documenting the script, and cleaning up a little
This commit is contained in:
parent
9f5054d2a3
commit
2868f7d4c0
3 changed files with 48 additions and 43 deletions
10
README.md
10
README.md
|
@ -40,9 +40,17 @@ The script ./tools/handy.rb, has plenty of functionality, and feel free to add m
|
||||||
--test PATH validate PATH, instead of [/content/beta/rhel/server/5/5server/x86_64/sap/os/repomd.xml]
|
--test PATH validate PATH, instead of [/content/beta/rhel/server/5/5server/x86_64/sap/os/repomd.xml]
|
||||||
--print print the tree of contents
|
--print print the tree of contents
|
||||||
|
|
||||||
|
$> jruby ./tools/handy.rb
|
||||||
|
[/content/beta/rhel/server/5/5server/x86_64/sap/os/repomd.xml] true
|
||||||
|
|
||||||
|
$> jruby ./tools/handy.rb --test /foo/bar/baz
|
||||||
|
[/foo/bar/baz] false
|
||||||
|
|
||||||
|
$> jruby ./tools/handy.rb --contents ./myfile.txt --test /foo/bar/baz
|
||||||
|
[/foo/bar/baz] true
|
||||||
|
|
||||||
$> jruby ./tools/handy.rb --dot > contents.dot && dot -Tpng contents.dot -o contents.png && display contents.png
|
$> jruby ./tools/handy.rb --dot > contents.dot && dot -Tpng contents.dot -o contents.png && display contents.png
|
||||||
|
|
||||||
$> jruby ./tools/handy.rb --cert ./src/test/resources/test-certv3.pem
|
$> jruby ./tools/handy.rb --cert ./src/test/resources/test-certv3.pem
|
||||||
[/content/beta/rhel/server/5/5server/x86_64/sap/os/repomd.xml] true
|
|
||||||
[/foo/path, /foo/path/always/$releasever, /foo/path/never]
|
[/foo/path, /foo/path/always/$releasever, /foo/path/never]
|
||||||
|
|
||||||
|
|
|
@ -79,35 +79,6 @@ def printTree(node, tab)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_args(args)
|
|
||||||
options = {
|
|
||||||
:content_list => './src/test/resources/contents.list',
|
|
||||||
:dot => false,
|
|
||||||
:test_url => '/content/beta/rhel/server/5/5server/x86_64/sap/os/repomd.xml',
|
|
||||||
}
|
|
||||||
opts = OptionParser.new do |opts|
|
|
||||||
opts.on('--dot',"output the dot digraph of content listing (defaults to #{options[:content_list]}") do |o|
|
|
||||||
options[:dot] = o
|
|
||||||
end
|
|
||||||
opts.on('--contents FILE', "use FILE instead of #{options[:content_list]}") do |o|
|
|
||||||
options[:content_list] = o
|
|
||||||
end
|
|
||||||
opts.on('--cert FILE', "read contents from certificate FILE") do |o|
|
|
||||||
options[:certificate] = o
|
|
||||||
end
|
|
||||||
opts.on('--test PATH', "validate PATH, instead of [#{options[:test_url]}]") do |o|
|
|
||||||
options[:test_url] = o
|
|
||||||
end
|
|
||||||
opts.on('--print', "print the tree of contents") do |o|
|
|
||||||
options[:printTree] = o
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
opts.parse!(args)
|
|
||||||
|
|
||||||
return options
|
|
||||||
end
|
|
||||||
|
|
||||||
# ick, using java to do SSL
|
# ick, using java to do SSL
|
||||||
def object_from_oid(cert, oid)
|
def object_from_oid(cert, oid)
|
||||||
return unless cert
|
return unless cert
|
||||||
|
@ -138,22 +109,57 @@ def value_from_oid_bunk(filename, oid)
|
||||||
return OpenSSL::ASN1.decode(OpenSSL::ASN1.decode(ext.to_der).value[1].value).value
|
return OpenSSL::ASN1.decode(OpenSSL::ASN1.decode(ext.to_der).value[1].value).value
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def parse_args(args)
|
||||||
|
options = {
|
||||||
|
:content_list => './src/test/resources/contents.list',
|
||||||
|
:dot => false,
|
||||||
|
:test_url => '/content/beta/rhel/server/5/5server/x86_64/sap/os/repomd.xml',
|
||||||
|
}
|
||||||
|
opts = OptionParser.new do |opts|
|
||||||
|
opts.on('--dot',"output the dot digraph of content listing (defaults to #{options[:content_list]}") do |o|
|
||||||
|
options[:dot] = o
|
||||||
|
end
|
||||||
|
opts.on('--contents FILE', "use FILE instead of #{options[:content_list]}") do |o|
|
||||||
|
options[:content_list] = o
|
||||||
|
end
|
||||||
|
opts.on('--cert FILE', "read contents from certificate FILE") do |o|
|
||||||
|
options[:certificate] = o
|
||||||
|
end
|
||||||
|
opts.on('--test PATH', "validate PATH, instead of [#{options[:test_url]}]") do |o|
|
||||||
|
options[:test_url] = o
|
||||||
|
end
|
||||||
|
opts.on('--print', "print the tree of contents") do |o|
|
||||||
|
options[:printTree] = o
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
opts.parse!(args)
|
||||||
|
|
||||||
|
return options
|
||||||
|
end
|
||||||
|
|
||||||
def main(args)
|
def main(args)
|
||||||
options = parse_args(args)
|
options = parse_args(args)
|
||||||
|
|
||||||
STDERR.puts("[%s] %s" % [options[:test_url], pt.validate(options[:test_url])])
|
if options[:dot]
|
||||||
|
puts print_dot(pt(options[:content_list]).getRootPathNode()).read()
|
||||||
puts print_dot(pt(options[:content_list]).getRootPathNode()).read() if options[:dot]
|
return
|
||||||
|
end
|
||||||
if options[:printTree]
|
if options[:printTree]
|
||||||
pn = pt.getRootPathNode
|
pn = pt.getRootPathNode
|
||||||
printTree(pn, 0)
|
printTree(pn, 0)
|
||||||
|
return
|
||||||
end
|
end
|
||||||
if options[:certificate]
|
if options[:certificate]
|
||||||
data = value_from_oid(options[:certificate], '1.3.6.1.4.1.2312.9.7')
|
data = value_from_oid(options[:certificate], '1.3.6.1.4.1.2312.9.7')
|
||||||
pt = Trie::PathTree.new(data.getOctets)
|
pt = Trie::PathTree.new(data.getOctets)
|
||||||
puts pt.toList()
|
puts pt.toList()
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Default behaviour (no other flags provided)
|
||||||
|
puts "[%s] %s" % [options[:test_url], pt.validate(options[:test_url])]
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
main(ARGV) if $0 == __FILE__
|
main(ARGV) if $0 == __FILE__
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
#!/bin/sh
|
|
||||||
|
|
||||||
base_dir=$(readlink -f $(dirname $0)/..)
|
|
||||||
|
|
||||||
java \
|
|
||||||
-cp $(find ${base_dir}/lib/ -type f -printf "%h/%f:")$(ls -rt ${base_dir}/target/*jar | tail -1) \
|
|
||||||
com.hashbangbash.trie.App \
|
|
||||||
${base_dir}/src/test/resources/test-certv3.pem
|
|
||||||
|
|
Loading…
Reference in a new issue