aptly_cli 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ceb07d514a0630db6a211ef67c423e70bbfb7366891566fca5eb82633ca45cd2
4
- data.tar.gz: 64e5864e9bd063af826abf8aa1f8b4ba65f4288f0bd0bf3ba52a61352b7db34c
3
+ metadata.gz: c4fb76b5a05ffe081ad5adac38b250f0566dc13b3f6d4b59d69d5cb9b444c7ad
4
+ data.tar.gz: 7f70ac81c20310b8b5ac91ad50a2f52e84dc9d028713c15184d612d97ddcc8d6
5
5
  SHA512:
6
- metadata.gz: 348202e54b4fade990163e8cf1a2107f7f538d58ca894f07401c9cc57b3495f450cd032956010bcf5d84472c5b4c4a8895f8d0e69d25aa772258015875d409e2
7
- data.tar.gz: 0d11506ac7051aef167bbfa558a22d982a373194bdb1f02dce97e16f6bff15bee4fdd85100a408c65c5e45a9f7d9e0fd0d75662fb599f2dfd8296de8442b8e8b
6
+ metadata.gz: c251302d85569e13f307f085a3864ecc706f730ff33438c37c530d08b1373eb196bafe1b5ae7f7172d29765131336893fc17ffaa387ab8eb21e2e2f6958322c1
7
+ data.tar.gz: dba94fca72f1cb48f6ef051a2d9af5123912435352c3057ad06d9394cf3c2637b0c5d496947b6ff6c73e620088b1aaac9c79d50f637d102cc33e3dd116c07d85
@@ -0,0 +1,42 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+
6
+ name: Ruby Gem
7
+
8
+ on:
9
+ # Manually publish
10
+ workflow_dispatch:
11
+ # Alternatively, publish whenever changes are merged to the `main` branch.
12
+ push:
13
+ branches: [ master ]
14
+ pull_request:
15
+ branches: [ master ]
16
+
17
+ jobs:
18
+ build:
19
+ name: Build + Publish
20
+ runs-on: ubuntu-latest
21
+ permissions:
22
+ packages: write
23
+ contents: read
24
+
25
+ steps:
26
+ - uses: actions/checkout@v2
27
+ - name: Set up Ruby 2.6
28
+ uses: ruby/setup-ruby@477b21f02be01bcb8030d50f37cfec92bfa615b6
29
+ with:
30
+ ruby-version: 2.6
31
+ - run: bundle install
32
+
33
+ - name: Publish to RubyGems
34
+ run: |
35
+ mkdir -p $HOME/.gem
36
+ touch $HOME/.gem/credentials
37
+ chmod 0600 $HOME/.gem/credentials
38
+ printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
39
+ gem build *.gemspec
40
+ gem push *.gem
41
+ env:
42
+ GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_AUTH_TOKEN}}"
data/aptly_cli.gemspec CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.required_ruby_version = '>= 2.0.0'
27
27
 
28
28
  spec.add_development_dependency "bundler"
29
- spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rake", ">= 12.3.3"
30
30
  spec.add_development_dependency "minitest"
31
31
  spec.add_development_dependency "coveralls"
32
32
  spec.add_development_dependency "simplecov"
data/bin/aptly-cli CHANGED
@@ -115,7 +115,6 @@ command :repo_create do |c|
115
115
  c.option '--default_distribution DISTRIBUTION', String, 'Default distribution when publishing from this local repo'
116
116
  c.option '--default_component COMPONENT', String, 'Default component when publishing from this local repo'
117
117
  c.action do |args, options|
118
- puts options.name
119
118
  config = AptlyCli::AptlyLoad.new.configure_with($config_file)
120
119
  handle_global_options options
121
120
  aptly_command = AptlyCli::AptlyRepo.new(config, options)
@@ -166,7 +165,7 @@ command :repo_edit do |c|
166
165
  if options.comment
167
166
  repo_options = { :Comment => options.comment.to_s }
168
167
  end
169
- puts aptly_command.repo_edit(options.name.to_s, repo_options)
168
+ puts aptly_command.repo_edit(options.name.to_s, repo_options || {})
170
169
  end
171
170
  end
172
171
 
@@ -1,3 +1,3 @@
1
1
  module AptlyCli
2
- VERSION = '0.5.0'.freeze
2
+ VERSION = '0.6.0'.freeze
3
3
  end
data/lib/aptly_command.rb CHANGED
@@ -1,4 +1,8 @@
1
1
  module AptlyCli
2
+ class HttpError < StandardError; end
3
+ class HttpNotFoundError < HttpError; end
4
+ class HttpInternalServerError < HttpError; end
5
+
2
6
  class AptlyCommand
3
7
  include HTTParty
4
8
 
@@ -64,5 +68,41 @@ module AptlyCli
64
68
 
65
69
  self.class.debug_output @config[:debug] ? $stdout : nil
66
70
  end
71
+
72
+ def delete(path, options = {})
73
+ response = self.class.delete(path, options)
74
+ process_response(response)
75
+ end
76
+
77
+ def get(path, options = {})
78
+ response = self.class.get(path, options)
79
+ process_response(response)
80
+ end
81
+
82
+ def post(path, options = {})
83
+ response = self.class.post(path, options)
84
+ process_response(response)
85
+ end
86
+
87
+ def put(path, options = {})
88
+ response = self.class.put(path, options)
89
+ process_response(response)
90
+ end
91
+
92
+ def process_response(response)
93
+ json_response = JSON.parse response.body
94
+
95
+ raise "[Server] #{json_response['error']}" unless !json_response.is_a?(Hash) || json_response.dig('error').nil?
96
+
97
+ raise HttpNotFoundError, "#{json_response}" if response.code == 404
98
+ raise HttpInternalServerError, "#{json_response}" if response.code == 500
99
+
100
+ response
101
+ rescue JSON::ParserError
102
+ raise HttpNotFoundError, "#{json_response}" if response.code == 404
103
+ raise HttpInternalServerError, "#{json_response}" if response.code == 500
104
+
105
+ response
106
+ end
67
107
  end
68
108
  end
data/lib/aptly_file.rb CHANGED
@@ -10,7 +10,7 @@ module AptlyCli
10
10
 
11
11
  def file_dir
12
12
  uri = '/files'
13
- response = self.class.get uri
13
+ response = get uri
14
14
  response.parsed_response
15
15
  end
16
16
 
@@ -20,19 +20,19 @@ module AptlyCli
20
20
  else
21
21
  '/files/' + file_uri
22
22
  end
23
- response = self.class.get uri
23
+ response = get uri
24
24
  response.parsed_response
25
25
  end
26
26
 
27
27
  def file_delete(file_uri)
28
28
  uri = '/files' + file_uri
29
- response = self.class.delete uri
29
+ response = delete uri
30
30
  response.parsed_response
31
31
  end
32
32
 
33
33
  def file_post(post_options = {})
34
34
  api_file_uri = '/files' + post_options[:file_uri].to_s
35
- response = self.class.post(api_file_uri,
35
+ response = post(api_file_uri,
36
36
  body: {
37
37
  package: post_options[:package],
38
38
  file: File.new(post_options[:local_file])
data/lib/aptly_misc.rb CHANGED
@@ -11,12 +11,12 @@ module AptlyCli
11
11
 
12
12
  def get_graph(extension)
13
13
  uri = "/graph.#{extension}"
14
- self.class.get(uri)
14
+ get(uri)
15
15
  end
16
16
 
17
17
  def get_version
18
18
  uri = '/version'
19
- response = self.class.get(uri)
19
+ response = get(uri)
20
20
  response.parsed_response
21
21
  end
22
22
  end
data/lib/aptly_package.rb CHANGED
@@ -11,7 +11,7 @@ module AptlyCli
11
11
 
12
12
  def package_show(package_key)
13
13
  uri = "/packages/#{package_key}"
14
- self.class.get(uri)
14
+ get(uri)
15
15
  end
16
16
  end
17
17
  end
data/lib/aptly_publish.rb CHANGED
@@ -26,12 +26,12 @@ module AptlyCli
26
26
 
27
27
  uri += "/#{publish_options[:distribution]}"
28
28
  uri += '?force=1' if publish_options[:force] == true
29
- self.class.delete(uri)
29
+ delete(uri)
30
30
  end
31
31
 
32
32
  def publish_list
33
33
  uri = '/publish'
34
- self.class.get(uri)
34
+ get(uri)
35
35
  end
36
36
 
37
37
  def _parse_snapshots(names)
@@ -92,7 +92,7 @@ module AptlyCli
92
92
 
93
93
  @body_json = @body.to_json
94
94
 
95
- self.class.post(uri, :headers => { 'Content-Type' => 'application/json' },
95
+ post(uri, :headers => { 'Content-Type' => 'application/json' },
96
96
  :body => @body_json)
97
97
  end
98
98
 
@@ -112,13 +112,13 @@ module AptlyCli
112
112
  uri += if publish_options[:prefix]
113
113
  "/#{publish_options[:prefix]}"
114
114
  else
115
- '/'
115
+ '/:.'
116
116
  end
117
117
 
118
118
  uri += "/#{publish_options[:distribution]}"
119
119
 
120
120
  @body_json = @body.to_json
121
- self.class.put(uri, :headers => { 'Content-Type' => 'application/json' },
121
+ put(uri, :headers => { 'Content-Type' => 'application/json' },
122
122
  :body => @body_json)
123
123
  end
124
124
  end
data/lib/aptly_repo.rb CHANGED
@@ -14,12 +14,14 @@ module AptlyCli
14
14
  comment: nil,
15
15
  DefaultDistribution: nil,
16
16
  DefaultComponent: nil })
17
+ raise ArgumentError, 'Repository name is required' if repo_options[:name].nil? || repo_options[:name].empty?
18
+
17
19
  uri = '/repos'
18
20
  name = repo_options[:name]
19
21
  comment = repo_options[:comment]
20
22
  default_distribution = repo_options[:DefaultDistribution]
21
23
  default_component = repo_options[:DefaultComponent]
22
- self.class.post(uri,
24
+ post(uri,
23
25
  :body =>
24
26
  { 'Name' => name, 'Comment' => comment,
25
27
  'DefaultDistribution' => default_distribution,
@@ -28,36 +30,32 @@ module AptlyCli
28
30
  end
29
31
 
30
32
  def repo_delete(repo_options = { name: nil, force: nil })
33
+ raise ArgumentError, 'Repository name is required' if repo_options[:name].nil? || repo_options[:name].empty?
34
+
31
35
  uri = '/repos/' + repo_options[:name]
32
36
  uri += '?force=1' if repo_options[:force] == true
33
- self.class.delete(uri)
37
+ delete(uri)
34
38
  end
35
39
 
36
- def repo_edit(name, repo_options = { k => v })
37
- repo_option = ''
38
- repo_value = ''
39
- uri = '/repos/' + name unless name.nil?
40
- repo_options.each do |k, v|
41
- repo_option = k
42
- repo_value = v
43
- end
40
+ def repo_edit(name, repo_options)
41
+ raise ArgumentError, 'Repository name is required' if name.nil? || name.empty?
44
42
 
45
- self.class.put(uri, :body => { repo_option => repo_value }.to_json,
43
+ uri = "/repos/#{name}"
44
+
45
+ put(uri, :body => repo_options.to_json,
46
46
  :headers => { 'Content-Type' => 'application/json' })
47
47
  end
48
48
 
49
49
  def repo_list
50
50
  uri = '/repos'
51
- self.class.get(uri)
51
+ get(uri)
52
52
  end
53
53
 
54
54
  def repo_package_add(repo_options, packages)
55
- if !repo_options.is_a?(Hash) || repo_options[:name].nil?
56
- raise ArgumentError.new('Must pass a repository name')
57
- end
55
+ raise ArgumentError, 'Repository name is required' if repo_options[:name].nil? || repo_options[:name].empty?
58
56
 
59
57
  uri = '/repos/' + repo_options[:name] + '/packages'
60
- self.class.post(
58
+ post(
61
59
  uri,
62
60
  :body => { PackageRefs: packages }.to_json,
63
61
  :headers => { 'Content-Type' => 'application/json' }
@@ -65,12 +63,10 @@ module AptlyCli
65
63
  end
66
64
 
67
65
  def repo_package_delete(repo_options, packages)
68
- if !repo_options.is_a?(Hash) || repo_options[:name].nil?
69
- raise ArgumentError.new('Must pass a repository name')
70
- end
66
+ raise ArgumentError, 'Repository name is required' if repo_options[:name].nil? || repo_options[:name].empty?
71
67
 
72
68
  uri = '/repos/' + repo_options[:name] + '/packages'
73
- self.class.delete(
69
+ delete(
74
70
  uri,
75
71
  :body => { PackageRefs: packages }.to_json,
76
72
  :headers => { 'Content-Type' => 'application/json' }
@@ -80,18 +76,16 @@ module AptlyCli
80
76
  def repo_package_query(repo_options = { name: nil, query: nil,
81
77
  with_deps: false,
82
78
  format: nil })
83
- if repo_options[:name].nil?
84
- raise ArgumentError.new('Must pass a repository name')
85
- else
86
- uri = '/repos/' + repo_options[:name] + '/packages'
87
- end
79
+ raise ArgumentError, 'Repository name is required' if repo_options[:name].nil? || repo_options[:name].empty?
80
+
81
+ uri = '/repos/' + repo_options[:name] + '/packages'
88
82
 
89
83
  qs_hash = {}
90
84
  qs_hash['q'] = repo_options[:query] if repo_options[:query]
91
85
  qs_hash['format'] = repo_options[:format] if repo_options[:format]
92
86
  qs_hash['withDeps'] = 1 if repo_options[:with_deps]
93
87
  uri += '?' + URI.encode_www_form(qs_hash) if qs_hash
94
- self.class.get uri
88
+ get uri
95
89
  end
96
90
 
97
91
  def repo_show(name)
@@ -100,11 +94,13 @@ module AptlyCli
100
94
  else
101
95
  '/repos/' + name
102
96
  end
103
- self.class.get uri
97
+ get uri
104
98
  end
105
99
 
106
100
  def repo_upload(repo_options = { name: nil, dir: nil, file: nil,
107
101
  noremove: false, forcereplace: false })
102
+ raise ArgumentError, 'Repository name is required' if repo_options[:name].nil? || repo_options[:name].empty?
103
+
108
104
  name = repo_options[:name]
109
105
  dir = repo_options[:dir]
110
106
  file = repo_options[:file]
@@ -12,20 +12,20 @@ module AptlyCli
12
12
  def snapshot_delete(name, force=nil)
13
13
  uri = "/snapshots/#{name}"
14
14
  uri += '?force=1' if force == true
15
- self.class.delete(uri)
15
+ delete(uri)
16
16
  end
17
17
 
18
18
  def snapshot_list(sort=nil)
19
19
  uri = '/snapshots'
20
20
  uri += "?sort=#{sort}" if sort
21
- self.class.get(uri)
21
+ get(uri)
22
22
  end
23
23
 
24
24
  def snapshot_create(name, repo, description=nil)
25
25
  # Build uri to create snapshot, requires name of snap and name of repo
26
26
  uri = "/repos/#{repo}/" + 'snapshots'
27
27
 
28
- self.class.post(uri, :body =>
28
+ post(uri, :body =>
29
29
  { 'Name' => name,
30
30
  'Description' => description }.to_json,
31
31
  :headers => { 'Content-Type' => 'application/json' })
@@ -35,7 +35,7 @@ module AptlyCli
35
35
  sourcesnapshots=[], packagerefs=[])
36
36
  uri = '/snapshots'
37
37
  begin
38
- self.class.post(uri,
38
+ post(uri,
39
39
  :body => { 'Name' => name, 'Description' => description,
40
40
  'SourceSnapshots' => sourcesnapshots,
41
41
  'PackageRefs' => packagerefs }.to_json,
@@ -47,7 +47,7 @@ module AptlyCli
47
47
 
48
48
  def snapshot_diff(name, with_snapshot)
49
49
  uri = "/snapshots/#{name}/diff/#{with_snapshot}"
50
- self.class.get(uri)
50
+ get(uri)
51
51
  end
52
52
 
53
53
  def snapshot_search(name, search_options={})
@@ -63,12 +63,12 @@ module AptlyCli
63
63
  end
64
64
 
65
65
  @options[:query] = { withDeps: '1' } if search_options[:withDeps] == true
66
- self.class.get(uri, @options)
66
+ get(uri, @options)
67
67
  end
68
68
 
69
69
  def snapshot_show(name)
70
70
  uri = "/snapshots/#{name}"
71
- self.class.get(uri)
71
+ get(uri)
72
72
  end
73
73
 
74
74
  def snapshot_update(name, new_name, description=nil)
@@ -83,7 +83,7 @@ module AptlyCli
83
83
  @query[:Description] = description unless description.nil?
84
84
  @query_json = @query.to_json
85
85
  begin
86
- self.class.put(uri, :body => @query_json, :headers =>
86
+ put(uri, :body => @query_json, :headers =>
87
87
  { 'Content-Type' => 'application/json' })
88
88
  rescue HTTParty::Error => e
89
89
  puts e
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aptly_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-04 00:00:00.000000000 Z
11
+ date: 2022-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: 12.3.3
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: 12.3.3
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -130,6 +130,7 @@ executables:
130
130
  extensions: []
131
131
  extra_rdoc_files: []
132
132
  files:
133
+ - ".github/workflows/publish.yml"
133
134
  - ".gitignore"
134
135
  - ".hound.yml"
135
136
  - ".rubocop.yml"
@@ -177,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
177
178
  - !ruby/object:Gem::Version
178
179
  version: '0'
179
180
  requirements: []
180
- rubygems_version: 3.0.2
181
+ rubygems_version: 3.0.3.1
181
182
  signing_key:
182
183
  specification_version: 4
183
184
  summary: Command line client to interact with Aptly package management system