mdqt 0.5.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +25 -0
- data/README.md +10 -0
- data/exe/mdqt +3 -5
- data/lib/mdqt/cli/base.rb +22 -28
- data/lib/mdqt/cli/get.rb +13 -7
- data/lib/mdqt/cli/ln.rb +7 -0
- data/lib/mdqt/cli/ls.rb +3 -1
- data/lib/mdqt/cli/rename.rb +15 -0
- data/lib/mdqt/client/metadata_file.rb +6 -0
- data/lib/mdqt/version.rb +1 -1
- metadata +2 -3
- data/lib/mdqt/cli/stream.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ecdc970f76e871f3a12cd67229ca3f5a07888f0f633a21e0aead8a0a235b5f75
|
4
|
+
data.tar.gz: 9576e8403a2d3c6f755a9007a341f73c9e44a18ca0d96d869c1867eff00c9855
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b01525dbee9c0aa0c6f7a1ec46d21bc101ac47e5a70e2e7a5b0442d5efb10477852dac8389569cfea8ddeb1ec642eea2ad011a2d9988be1dd215d5c47c75e2f
|
7
|
+
data.tar.gz: 935e467dc9dfe24c06646b30527ad035e4901943d7393677b72aa6df623ad161f109083e921e5d64ca63bcca2cb25e75dcdd0b5a618a7ef66837dafbf799f287
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,30 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.6.0
|
4
|
+
|
5
|
+
### New Features
|
6
|
+
|
7
|
+
- STDIN and pipes: Arguments (such as filenames and entity IDs) can now be piped into mdqt. This
|
8
|
+
enables pipelining, so you can chain commands together.
|
9
|
+
- The `rename` command now has a `--link` option that creates a symlink from the original
|
10
|
+
filename to the renamed file.
|
11
|
+
- The `get` command now has a `--list` option that works when `--save-to` is used, to list filenames being
|
12
|
+
written to disk.
|
13
|
+
|
14
|
+
### Improvements
|
15
|
+
|
16
|
+
- Emacs backup files (so called turd files) ending with ~ and files ending with .bak
|
17
|
+
are now ignored.
|
18
|
+
|
19
|
+
### Removed features
|
20
|
+
|
21
|
+
- `link` and `rename` now require files to be specified: you now *cannot* run `mdqt rename`
|
22
|
+
to rename everything in the current directory.
|
23
|
+
|
24
|
+
- The `--link_id` option for `get` saved a link to each downloaded file that is almost the same as the
|
25
|
+
filename - maybe this made sense in mdqt 0.1.0 but it's quite useless now. If anyone can remember what it was
|
26
|
+
actually for I'll put it back.
|
27
|
+
|
3
28
|
## 0.5.0
|
4
29
|
|
5
30
|
### New Features
|
data/README.md
CHANGED
@@ -246,6 +246,16 @@ To show the full MDQ URL of an entity
|
|
246
246
|
|
247
247
|
$ mdqt url http://entity.ac.uk/shibboleth
|
248
248
|
|
249
|
+
MDQT can accept input on stdin, allowing composition and pipelining
|
250
|
+
|
251
|
+
$ cat list_of_ids.txt | bundle exec mdqt url
|
252
|
+
|
253
|
+
$ mdqt list | grep cern.ch | mdqt get --save-to cern_metadata/ --list | mdqt ls
|
254
|
+
|
255
|
+
## Alternatives
|
256
|
+
|
257
|
+
* [SAML Library](https://github.com/trscavo/saml-library) is a set of scripts to help with metadata-related tasks, written
|
258
|
+
by Tom Scavo of Internet2. Some of the scripts provide similar functionality to MDQT, and are designed to be piped together.
|
249
259
|
|
250
260
|
## Library Usage
|
251
261
|
|
data/exe/mdqt
CHANGED
@@ -42,7 +42,8 @@ Commander.configure do
|
|
42
42
|
c.option '--explain', 'Show details of client request and server response'
|
43
43
|
c.option '--tls-risky', "Don't check certificate used for TLS (usually a bad idea)"
|
44
44
|
c.option '--save-to PATH', String, 'Write all data to files in the specified directory'
|
45
|
-
c.option '--link-id', 'If saving files, save files with aliases (requires `--save-to`)'
|
45
|
+
#c.option '--link-id', 'If saving files, save files with aliases (requires `--save-to`)'
|
46
|
+
c.option '--list', 'If saving files, print the names of files written to disk (requires `--save-to`)'
|
46
47
|
c.option '--verbose', 'Display extra information on stderr'
|
47
48
|
c.action do |args, options|
|
48
49
|
options.default MDQT::CLI::Defaults.cli_defaults
|
@@ -103,7 +104,6 @@ Commander.configure do
|
|
103
104
|
c.option '--force', 'Overwrite any existing links'
|
104
105
|
c.option '--verbose', 'Display extra information on stderr'
|
105
106
|
c.action do |args, options|
|
106
|
-
args = Dir.glob("*.xml") unless args && !args.empty?
|
107
107
|
options.default MDQT::CLI::Defaults.cli_defaults
|
108
108
|
options.default({ service: :not_required })
|
109
109
|
MDQT::CLI::Ln.run(args, options)
|
@@ -115,7 +115,6 @@ Commander.configure do
|
|
115
115
|
c.description = 'List valid metadata files in directory'
|
116
116
|
c.option '--verbose', 'Display extra information on stderr'
|
117
117
|
c.action do |args, options|
|
118
|
-
args = Dir.glob("*.xml") unless args && !args.empty?
|
119
118
|
options.default MDQT::CLI::Defaults.cli_defaults
|
120
119
|
options.default({ service: :not_required })
|
121
120
|
MDQT::CLI::Ls.run(args, options)
|
@@ -128,7 +127,6 @@ Commander.configure do
|
|
128
127
|
c.option '--service URL', String, 'MDQ service to search for entities. Defaults to MDQT_SERVICE or MDQ_BASE_URL env variables'
|
129
128
|
c.option '--cache', "Cache downloads and try to fetch from cache where appropriate (deprecated)"
|
130
129
|
c.option '--refresh', "Never cache (will prevent --cache)"
|
131
|
-
#c.option '--stdin', 'accept one or more entity ids from STDIN'
|
132
130
|
c.option '--verbose', 'Display extra information on stderr'
|
133
131
|
c.action do |args, options|
|
134
132
|
options.default MDQT::CLI::Defaults.cli_defaults
|
@@ -152,8 +150,8 @@ Commander.configure do
|
|
152
150
|
c.description = 'Rename a file using the sha1 hash of its entityID'
|
153
151
|
c.option '--force', 'Overwrite any existing files with that name'
|
154
152
|
c.option '--verbose', 'Display extra information on stderr'
|
153
|
+
c.option '--link', 'Add a symlink with the original filename'
|
155
154
|
c.action do |args, options|
|
156
|
-
args = Dir.glob("*.xml") unless args && !args.empty?
|
157
155
|
options.default MDQT::CLI::Defaults.cli_defaults
|
158
156
|
options.default({ service: :not_required })
|
159
157
|
MDQT::CLI::Rename.run(args, options)
|
data/lib/mdqt/cli/base.rb
CHANGED
@@ -6,19 +6,18 @@ module MDQT
|
|
6
6
|
|
7
7
|
require 'mdqt/cli'
|
8
8
|
require 'pastel'
|
9
|
+
require 'pathname'
|
9
10
|
|
10
11
|
def self.run(args, options)
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
check_requirements(args, options)
|
15
|
-
introduce(args, options)
|
13
|
+
check_requirements(options)
|
14
|
+
introduce(options)
|
16
15
|
|
17
16
|
self.new(args, options).run
|
18
17
|
end
|
19
18
|
|
20
|
-
def self.check_requirements(
|
21
|
-
|
19
|
+
def self.check_requirements(options)
|
20
|
+
|
22
21
|
unless options.service == :not_required
|
23
22
|
abort "No MDQ service URL has been specified. Please use --service, MDQT_SERVICE or MDQ_BASE_URL" unless service_url(options).to_s.start_with?("http")
|
24
23
|
end
|
@@ -30,47 +29,41 @@ module MDQT
|
|
30
29
|
rescue
|
31
30
|
abort "Error: Directory #{dir} did not exist, and we can't create it"
|
32
31
|
end
|
33
|
-
abort "Error: '#{dir}' is not a writable directory!" if (File.directory?(dir) && !
|
32
|
+
abort "Error: '#{dir}' is not a writable directory!" if (File.directory?(dir) && !File.writable?(dir))
|
34
33
|
abort "Error: '#{dir}' is not a directory!" unless File.directory?(dir)
|
35
34
|
end
|
36
35
|
|
37
36
|
end
|
38
37
|
|
39
|
-
def self.introduce(
|
38
|
+
def self.introduce(options)
|
40
39
|
if options.verbose
|
41
40
|
STDERR.puts "MDQT version #{MDQT::VERSION}"
|
42
41
|
STDERR.puts "Using #{service_url(options)}" unless options.service == :not_required
|
43
42
|
STDERR.puts "Caching is #{MDQT::CLI::CacheControl.caching_on?(options) ? 'on' : 'off'}"
|
44
43
|
STDERR.print "XML validation is #{MDQT::Client.verification_available? ? 'available' : 'not available'}"
|
45
|
-
STDERR.puts
|
44
|
+
STDERR.puts " #{options.validate ? "and active" : "but inactive"} for this request" if MDQT::Client.verification_available?
|
46
45
|
STDERR.print "Signature verification is #{MDQT::Client.verification_available? ? 'available' : 'not available'}"
|
47
|
-
STDERR.puts
|
46
|
+
STDERR.puts " #{options.verify_with ? "and active" : "but inactive"} for this request" if MDQT::Client.verification_available?
|
48
47
|
STDERR.puts "Output directory for saved files is: #{File.absolute_path(options.save_to)}" if options.save_to
|
49
48
|
STDERR.puts("Warning! TLS certificate verification has been disabled!") if options.tls_risky
|
50
49
|
STDERR.puts
|
51
50
|
end
|
52
51
|
end
|
53
52
|
|
54
|
-
def
|
55
|
-
|
56
|
-
args
|
57
|
-
|
58
|
-
|
59
|
-
def self.piped?
|
60
|
-
!STDIN.tty? && !STDIN.closed?
|
61
|
-
end
|
62
|
-
|
63
|
-
def self.parse_stdin
|
64
|
-
STDIN.gsub("\s", "\n").each_line.collect {|l| l.strip}
|
53
|
+
def initialize(cli_args, options)
|
54
|
+
piped_input = get_stdin
|
55
|
+
@args = cli_args.concat(piped_input)
|
56
|
+
@options = options
|
65
57
|
end
|
66
58
|
|
67
|
-
def
|
68
|
-
|
69
|
-
|
59
|
+
def get_stdin
|
60
|
+
return $stdin.readlines.map(&:split).flatten.map(&:strip) if pipeable?
|
61
|
+
[]
|
70
62
|
end
|
71
63
|
|
72
|
-
def
|
73
|
-
|
64
|
+
def pipeable?
|
65
|
+
return false if ENV["MDQT_STDIN"].to_s.strip.downcase == "off" # Workaround Aruba testing weirdness?
|
66
|
+
!STDIN.tty? && !$stdin.closed? && $stdin.stat.pipe?
|
74
67
|
end
|
75
68
|
|
76
69
|
def args
|
@@ -119,7 +112,7 @@ module MDQT
|
|
119
112
|
unless response.explanation.empty?
|
120
113
|
require 'terminal-table'
|
121
114
|
misc_rows = [['URL', response.explanation[:url]], ["Method", response.explanation[:method]], ['Status', response.explanation[:status]]]
|
122
|
-
req_header_rows
|
115
|
+
req_header_rows = response.explanation[:request_headers].map { |k, v| ['C', k, v] }
|
123
116
|
resp_header_rows = response.explanation[:response_headers].map { |k, v| ['S', k, v] }
|
124
117
|
|
125
118
|
btw Terminal::Table.new :title => "HTTP Misc", :rows => misc_rows
|
@@ -182,6 +175,7 @@ module MDQT
|
|
182
175
|
end
|
183
176
|
|
184
177
|
end
|
185
|
-
|
178
|
+
|
179
|
+
#
|
186
180
|
end
|
187
181
|
|
data/lib/mdqt/cli/get.rb
CHANGED
@@ -84,22 +84,28 @@ module MDQT
|
|
84
84
|
end
|
85
85
|
|
86
86
|
def output_files(results, options)
|
87
|
+
pwd = Pathname.getwd
|
87
88
|
prepare_output_directory(options.save_to)
|
88
89
|
results.each do |result|
|
89
90
|
main_file = output_file_path(result.filename)
|
90
91
|
open(main_file, 'w') { |f|
|
91
92
|
f.puts result.data
|
92
93
|
}
|
93
|
-
yay "Created #{main_file}"
|
94
94
|
|
95
|
-
if options.
|
96
|
-
|
97
|
-
full_alias = output_file_path(altname)
|
98
|
-
FileUtils.ln_sf(main_file, full_alias)
|
99
|
-
yay "Linked alias #{altname} -> #{main_file}"
|
100
|
-
end
|
95
|
+
if options.list
|
96
|
+
puts Pathname.new(main_file).relative_path_from(pwd)
|
101
97
|
end
|
102
98
|
|
99
|
+
yay "Created #{main_file}"
|
100
|
+
|
101
|
+
# if options.link_id
|
102
|
+
# ["{sha1}#{result.filename.gsub(".xml", "")}"].each do |altname|
|
103
|
+
# full_alias = output_file_path(altname)
|
104
|
+
# FileUtils.ln_sf(main_file, full_alias)
|
105
|
+
# yay "Linked alias #{altname} -> #{main_file}"
|
106
|
+
# end
|
107
|
+
# end
|
108
|
+
|
103
109
|
end
|
104
110
|
end
|
105
111
|
|
data/lib/mdqt/cli/ln.rb
CHANGED
@@ -19,6 +19,8 @@ module MDQT
|
|
19
19
|
explain: options.explain ? true : false,
|
20
20
|
)
|
21
21
|
|
22
|
+
halt!("Please specify a file to link to!") if args.empty?
|
23
|
+
|
22
24
|
args.each do |filename|
|
23
25
|
|
24
26
|
next if File.symlink?(filename)
|
@@ -44,6 +46,11 @@ module MDQT
|
|
44
46
|
btw("Cannot link file to itself! #{filename}")
|
45
47
|
end
|
46
48
|
|
49
|
+
if file.turd?
|
50
|
+
hey "Warning: will not process backup/turd files"
|
51
|
+
next
|
52
|
+
end
|
53
|
+
|
47
54
|
message = ""
|
48
55
|
|
49
56
|
if File.exists?(linkname)
|
data/lib/mdqt/cli/ls.rb
CHANGED
data/lib/mdqt/cli/rename.rb
CHANGED
@@ -19,8 +19,12 @@ module MDQT
|
|
19
19
|
explain: options.explain ? true : false,
|
20
20
|
)
|
21
21
|
|
22
|
+
halt!("Please specify a file to rename!") if args.empty?
|
23
|
+
|
22
24
|
args.each do |filename|
|
23
25
|
|
26
|
+
next if File.symlink?(filename)
|
27
|
+
|
24
28
|
file = client.open_metadata(filename)
|
25
29
|
|
26
30
|
halt!("Cannot access file #{filename}") unless file.readable?
|
@@ -32,6 +36,11 @@ module MDQT
|
|
32
36
|
newname = file.linkname # Using the same name as the link, not super-obvious
|
33
37
|
next if filename == newname
|
34
38
|
|
39
|
+
if file.turd?
|
40
|
+
hey "Warning: will not process backup/turd files"
|
41
|
+
next
|
42
|
+
end
|
43
|
+
|
35
44
|
message = ""
|
36
45
|
|
37
46
|
if File.exists?(newname)
|
@@ -44,6 +53,12 @@ module MDQT
|
|
44
53
|
end
|
45
54
|
|
46
55
|
File.rename(filename, newname)
|
56
|
+
|
57
|
+
if options.link
|
58
|
+
File.delete(filename) if options.force && File.exists?(filename)
|
59
|
+
File.symlink(newname, filename) unless newname == filename
|
60
|
+
end
|
61
|
+
|
47
62
|
hey("#{filename} renamed to #{newname} [#{file.entity_id}] #{message}") if options.verbose
|
48
63
|
end
|
49
64
|
|
data/lib/mdqt/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mdqt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pete Birkinshaw
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: commander
|
@@ -292,7 +292,6 @@ files:
|
|
292
292
|
- lib/mdqt/cli/rename.rb
|
293
293
|
- lib/mdqt/cli/reset.rb
|
294
294
|
- lib/mdqt/cli/services.rb
|
295
|
-
- lib/mdqt/cli/stream.rb
|
296
295
|
- lib/mdqt/cli/transform.rb
|
297
296
|
- lib/mdqt/cli/url.rb
|
298
297
|
- lib/mdqt/cli/version.rb
|
data/lib/mdqt/cli/stream.rb
DELETED
File without changes
|