Class: MDQT::CLI::Get
- Inherits:
-
Base
- Object
- Base
- MDQT::CLI::Get
show all
- Defined in:
- lib/mdqt/cli/get.rb
Instance Method Summary
collapse
Methods inherited from Base
#advise_on_xml_signing_support, #args, #btw, check_requirements, #colour_shell?, #explain, #extract_certificate_paths, #get_stdin, #halt!, #hey, #initialize, introduce, #options, #options=, #output, #pastel, #pipeable?, run, #say, #service_url, service_url, #yay
Instance Method Details
#action(results, options) ⇒ Object
73
74
75
76
77
78
79
80
|
# File 'lib/mdqt/cli/get.rb', line 73
def action(results, options)
case
when options.save_to
:save_files
else
:print_to_stdout
end
end
|
#get_responses ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/mdqt/cli/get.rb', line 23
def get_responses
client = MDQT::Client.new(
service_url(options),
verbose: options.verbose,
explain: options.explain ? true : false,
tls_risky: options.tls_risky ? true : false,
cache_type: MDQT::CLI::CacheControl.cache_type(options),
)
args.empty? ? [client.get_metadata("")] : args.collect { |entity_id| client.get_metadata(entity_id) }
end
|
#output_files(results, options) ⇒ Object
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/mdqt/cli/get.rb', line 86
def output_files(results, options)
pwd = Pathname.getwd
prepare_output_directory(options.save_to)
results.each do |result|
main_file = output_file_path(result.filename)
open(main_file, 'w') { |f|
f.puts result.data
}
if options.list
puts Pathname.new(main_file).relative_path_from(pwd)
end
yay "Created #{main_file}"
end
end
|
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/mdqt/cli/get.rb', line 62
def output_metadata(results, options)
case action(results, options)
when :save_files
output_files(results, options)
when :print_to_stdout
output_to_stdout(results, options)
else
halt! "Can't determine output type"
end
end
|
#output_to_stdout(results, options) ⇒ Object
82
83
84
|
# File 'lib/mdqt/cli/get.rb', line 82
def output_to_stdout(results, options)
results.each { |r| puts output(r) }
end
|
#run ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/mdqt/cli/get.rb', line 9
def run
aggregate_confirmation_check!
advise_on_xml_signing_support
results = verify_results(get_responses)
output_metadata(results, options)
end
|
#verify_results(results) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/mdqt/cli/get.rb', line 37
def verify_results(results)
if options.validate
results.each do |result|
next unless result.ok?
halt! "The data for #{result.identifier} is not valid when checked against schema:\n#{result.validation_error}" unless result.valid?
btw "Data for #{result.identifier.empty? ? 'aggregate' : result.identifier } has been validated against schema" end
end
return results unless options.verify_with
cert_paths = (options.verify_with)
results.each do |result|
next unless result.ok?
halt! "Data from #{options.service} is not signed, cannot verify!" unless result.signed?
halt! "The data for #{result.identifier} cannot be verified using #{cert_paths.to_sentence}" unless result.verified_signature?(cert_paths)
btw "Data for #{result.identifier.empty? ? 'aggregate' : result.identifier } has been verified using '#{cert_paths.to_sentence}'" end
results
end
|