-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathin
More file actions
executable file
·66 lines (44 loc) · 1.82 KB
/
Copy pathin
File metadata and controls
executable file
·66 lines (44 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/ruby
require 'json'
require 'aptly_cli'
require 'commander'
$stdout = STDERR
input = JSON.load($stdin.read, nil, { symbolize_names: true, create_additions: false })
config = { proto: 'http' }
options = Commander::Command::Options.new
%i{ server port username password debug name comment default_distribution default_component }.each do |option|
options.__send__("#{option}=", input[:source][option])
end
api_uri = URI(input[:source][:api_uri])
options.server = api_uri.host
options.port = api_uri.port
repo = AptlyCli::AptlyRepo.new(config, options)
response = repo.repo_package_query({
name: "#{input[:source][:component]}-#{input[:source][:distribution]}",
query: input[:source][:package],
with_deps: false,
format: 'details'
})
matches = response.parsed_response
.select{ |entry| entry['Package'].eql?(input[:source][:package]) }
.select{ |entry| entry['FilesHash'].eql?(input[:version][:ref]) }
unless matches.size.eql?(1)
warn('No match found')
exit(1)
end
p input
package_uri = URI("#{input[:source][:repo_uri].to_s.chomp('/')}/pool/#{input[:source][:component]}/#{input[:source][:package][0]}/#{input[:source][:package]}/#{matches.first['Filename']}")
response = Net::HTTP.new(package_uri.host, package_uri.port).get(package_uri.path)
unless Net::HTTPSuccess === response
warn(response.message)
exit(1)
end
archive = matches.first['Filename']
if input[:params] && input[:params][:archive]
archive = input[:params][:archive]
end
File.write("#{ARGV.first}/#{archive}", response.body)
File.write("#{ARGV.first}/filename", matches.first['Filename'])
File.write("#{ARGV.first}/path", archive)
$stdout = STDOUT
puts({ version: { ref: input[:version][:ref], filename: matches.first['Filename'] }, metadata: [ { name: :filename, value: matches.first['Filename'] }, { name: :path, value: archive }] }.to_json)