aptly_cli 0.2.9 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MGQ1MWI0M2I3NGRmZDU1NDZlOTIwZWI4N2JlN2VlZThlMjhiZDdlZQ==
4
+ OTlmNzM3YjU0YzFkYjVmYTNjOWZmNWZiMmIzNjgxNDZiYzNmOGM1MQ==
5
5
  data.tar.gz: !binary |-
6
- NTdjODhiYTBjOGRjNjYyZmJhZjgyN2U4ZWEzYzJkYmUzMjVkOTA2Ng==
6
+ MjZhOTk4NmYwYzQ0NTYwODcyYTNlMzIxZmI0NTViMDRhMTRlOTJkOA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MmRiMjMzYTc1NTg2NjE3MjdmMjRkMjI2ZmMzOWE3YjU2ZTljZjAwZDI0MWM1
10
- OWRiYjM4ZGY5YTQ4YzRjODRhNzdiNzQzYjJlOTg0ZWMwOWE2YTI0MDhhNjNk
11
- ZDUxYWU4NDQ4ZTI2NDhjYmQ2MDA1MGEyNzI0ZmUwNjUwNzAyYzE=
9
+ NzIwNmZiNjI1NmYzMTc3NmU3ODIyYTQxNDY2MTY4YmQ4MjY3MGRmYmQzNjcz
10
+ YjRlNDM4NDEwNTdkYTY3ZWUwNzQ4ZmQ3ZDg2ZjQ4OTdhYjU3NzQyMzhiOGMy
11
+ NDhiYTlmZWE4NmYzMDFiZjRjODVmZjYyMDIwYWQ0MjJlZDBjOGI=
12
12
  data.tar.gz: !binary |-
13
- ZTE1MTQwOTNhMjU3NmUwY2I5M2FkYzgzMDgyMzQ4MWU4YTNiOWRiZDA4NWVm
14
- MWRlOGNjMTcxNmNkMTgzNjkyN2MxMTAwYzgwZWE2NjhkNDcxMzU4MGVlYzhm
15
- ZTZmODE5MzlhYmVlMzQwNTRkM2M5ZjQ2OGIwZTY5ZDdhYjYxY2E=
13
+ MmZiZTBiYjFjZTg0NTMzZTM3NWQyZWYyMWFhNDZlOGZkZDdkZmU5OWJiODY3
14
+ MTI0ZDI5OTY4NGQwZDcxYjU4ZTQ4ODVmMzlkZDMwYWJiNjhlYTM1MzAwNjYy
15
+ NjdmZjcxOGMzNmI0OGY1OGY4Y2IxZjA3NjMzYzcyNzUzYjUzMDQ=
data/Dockerfile CHANGED
@@ -1,19 +1,29 @@
1
- FROM debian:jessie
1
+ FROM ruby:2.3
2
+ MAINTAINER Zane Williamson <zane.williamson@gmail.com>
2
3
 
3
- EXPOSE 8080
4
+ # Install apt packages
5
+ ARG DEBIAN_FRONTEND=noninteractive
6
+ RUN apt-get update -qq && \
7
+ apt-get install -y -qq \
8
+ less \
9
+ locales && \
10
+ apt-get clean && \
11
+ rm -rf /var/lib/apt/lists/*
4
12
 
5
- RUN echo "deb http://repo.aptly.info/ squeeze main" > /etc/apt/sources.list.d/aptly.list; \
6
- apt-key adv --keyserver keys.gnupg.net --recv-keys 2A194991; \
7
- apt-get update; \
8
- apt-get install aptly curl xz-utils bzip2 gnupg wget graphviz -y --force-yes; \
9
- wget --quiet http://mirror.as24220.net/pub/ubuntu-archive/pool/main/z/zeitgeist/zeitgeist_0.9.0-1_all.deb -O /tmp/zeitgeist_0.9.0-1_all.deb; \
10
- wget --quiet http://mirror.as24220.net/pub/ubuntu-archive/pool/main/z/zsh/zsh_5.1.1-1ubuntu1_i386.deb -O /tmp/zsh_5.1.1-1ubuntu1_i386.deb
13
+ # Configure locale
14
+ ARG LOCALE="C.UTF-8"
15
+ RUN locale-gen "$LOCALE" && \
16
+ dpkg-reconfigure locales
17
+ ENV LANG="$LOCALE" LC_ALL="$LOCALE"
11
18
 
12
- ADD ./test/fixtures/aptly.conf /etc/aptly.conf
19
+ ADD . /app/
20
+ ADD lib /app/lib
13
21
 
14
- RUN aptly repo create testrepo
15
- RUN aptly repo create testrepo20
16
- RUN aptly repo add testrepo /tmp/zeitgeist_0.9.0-1_all.deb
17
- RUN aptly repo add testrepo20 /tmp/zsh_5.1.1-1ubuntu1_i386.deb
22
+ VOLUME /app
23
+ WORKDIR /app
18
24
 
19
- CMD /usr/bin/aptly api serve
25
+ RUN gem install bundler && \
26
+ bundle install && \
27
+ rake install
28
+
29
+ ENTRYPOINT ["aptly-cli"]
data/README.md CHANGED
@@ -4,36 +4,48 @@
4
4
  [![Gem Version](https://badge.fury.io/rb/aptly_cli.svg)](http://badge.fury.io/rb/aptly_cli)
5
5
  [![Coverage Status](https://coveralls.io/repos/github/sepulworld/aptly_cli/badge.svg?branch=master)](https://coveralls.io/github/sepulworld/aptly_cli?branch=master)
6
6
 
7
- A command line interace to execute [Aptly](http://aptly.info) commands againts remote Aptly API servers. Aptly-cli will allow you to interact with the file, repo, snapshot, publish, packages, graph and version API endpoints of your Aptly server.
7
+ A command line interface to execute [Aptly](http://aptly.info) commands againts remote Aptly API servers. Aptly-cli will allow you to interact with the file, repo, snapshot, publish, packages, graph and version API endpoints of your Aptly server.
8
8
 
9
9
 
10
10
  ## Installation
11
11
 
12
- Add this line to your application's Gemfile:
12
+ ### Install Gem:
13
13
 
14
- $ ruby gem 'aptly_cli'
14
+ $ gem install aptly_cli
15
+
16
+ or...
17
+
18
+ ### Install and run aptly-cli from Docker:
15
19
 
16
- And then execute:
20
+ # Optional: If you don't pull explicitly, `docker run` will do it for you
21
+ $ docker pull sepulworld/aptly-cli
17
22
 
18
- $ bundle
23
+ $ alias aptly-cli='\
24
+ docker run \
25
+ -v /etc/aptly-cli.conf:/etc/aptly-cli.conf \
26
+ -it --rm --name=aptly-cli \
27
+ sepulworld/aptly-cli'
19
28
 
20
- Or install it yourself as:
29
+ (Depending on how your system is set up, you might have to add `sudo` in front of the above `docker` commands or add your user to the `docker` group).
21
30
 
22
- $ gem install aptly_cli
23
-
31
+ If you don't do the `docker pull`, the first time you run `aptly-cli`, the `docker run` command will automatically pull [the `sepulworld/aptly-cli` image on the Docker Hub](https://hub.docker.com/r/sepulworld/aptly-cli/). Subsequent runs will use a locally cached copy of the image and will not have to download anything.
24
32
 
25
- Create a configuration file with aptly server and port, /etc/aptly-cli.conf (YAML syntax):
33
+ Create a configuration file with aptly server and port, `/etc/aptly-cli.conf` (YAML syntax):
26
34
 
27
- ---
28
- :proto: http
29
- :server: 127.0.0.1
30
- :port: 8082
31
- :debug: false
35
+ ```yaml
36
+ ---
37
+ :proto: http
38
+ :server: 127.0.0.1
39
+ :port: 8082
40
+ :debug: false
41
+ ```
32
42
 
33
43
  If you use Basic Authentication to protect your API, add username and password:
34
44
 
35
- :username: api-user
36
- :password: api-password
45
+ ```yaml
46
+ :username: api-user
47
+ :password: api-password
48
+ ```
37
49
 
38
50
  Also make sure that your config file isn't world readable (```chmod o-rw /etc/aptly-cli.conf```)
39
51
 
@@ -79,7 +91,7 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
79
91
 
80
92
  To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
81
93
 
82
- Ruby Minitest are impleneted using Docker container for functional tests
94
+ Ruby Minitest are implemented using a Docker container for functional tests.
83
95
 
84
96
  Rake tasks available:
85
97
 
data/Rakefile CHANGED
@@ -13,37 +13,37 @@ task default: :test
13
13
 
14
14
  desc "Docker build image"
15
15
  task :docker_build do
16
- sh %{docker build -t sepulworld/aptly_api .}
16
+ sh %{docker build -t sepulworld/aptly_api_test ./test/}
17
17
  end
18
18
 
19
19
  desc "Push Docker image to Docker Hub"
20
20
  task :docker_push do
21
- sh %{docker push sepulworld/aptly_api}
21
+ sh %{docker push sepulworld/aptly_api_test}
22
22
  end
23
23
 
24
24
  desc "Pull Docker image to Docker Hub"
25
25
  task :docker_pull do
26
- sh %{docker pull sepulworld/aptly_api}
26
+ sh %{docker pull sepulworld/aptly_api_test}
27
27
  end
28
28
 
29
29
  desc "List Docker Aptly running containers"
30
30
  task :docker_list_aptly do
31
- sh %{docker ps --filter ancestor='sepulworld/aptly_api' --format="{{.ID}}"}
31
+ sh %{docker ps --filter ancestor='sepulworld/aptly_api_test' --format="{{.ID}}"}
32
32
  end
33
33
 
34
34
  desc "Stop running Aptly Docker containers"
35
35
  task :docker_stop do
36
- sh %{docker stop $(docker ps --filter ancestor='sepulworld/aptly_api' --format="{{.ID}}")}
36
+ sh %{docker stop $(docker ps --filter ancestor='sepulworld/aptly_api_test' --format="{{.ID}}")}
37
37
  end
38
38
 
39
39
  desc "Start Aptly Docker container on port 8082"
40
40
  task :docker_run do
41
- sh %{docker run -d -p 8082:8080 sepulworld/aptly_api /bin/sh -c "aptly api serve"}
41
+ sh %{docker run -d -p 8082:8080 sepulworld/aptly_api_test /bin/sh -c "aptly api serve"}
42
42
  end
43
43
 
44
44
  desc "Show running Aptly process Docker stdout logs"
45
45
  task :docker_show_logs do
46
- sh %{docker logs $(docker ps --filter ancestor='sepulworld/aptly_api' --format="{{.ID}}")}
46
+ sh %{docker logs $(docker ps --filter ancestor='sepulworld/aptly_api_test' --format="{{.ID}}")}
47
47
  end
48
48
 
49
49
  desc "Restart Aptly docker container"
data/bin/aptly-cli CHANGED
@@ -8,14 +8,54 @@ require 'aptly_cli'
8
8
  program :version, AptlyCli::VERSION
9
9
  program :description, 'Aptly repository API client'
10
10
 
11
+ $config_file = '/etc/aptly-cli.conf'
12
+ $server = nil
13
+ $username = nil
14
+ $password = nil
15
+ $debug = false
16
+
17
+ global_option('-c', '--config FILE', 'Path to YAML config file') do |config_file|
18
+ $config_file = config_file
19
+ end
20
+
21
+ global_option('-s', '--server SERVER', 'Host name or IP address') do |server|
22
+ $server = server
23
+ end
24
+ global_option('--username USERNAME', 'User name') do |username|
25
+ $username = username
26
+ end
27
+ global_option('--password PASSWORD', 'Password') do |password|
28
+ $password = password
29
+ end
30
+ global_option('--debug', 'Enable debug output') do
31
+ $debug = true
32
+ end
33
+
34
+ def handle_global_options(options)
35
+ if $server
36
+ options.server = $server
37
+ end
38
+ if $username
39
+ options.username = $username
40
+ end
41
+ if $password
42
+ options.password = $password
43
+ end
44
+ if $debug
45
+ options.debug = $debug
46
+ end
47
+ end
48
+
11
49
  command :file_list do |c|
12
50
  c.syntax = 'aptly-cli file_list [options]'
13
- c.summary = 'List all directories that contain uploaded files'
14
- c.description = 'List all directories'
51
+ c.summary = 'List all directories'
52
+ c.description = 'List all directories that contain uploaded files'
15
53
  c.example 'List all directories for file uploads', 'aptly-cli file_list'
16
54
  c.option '--directory DIRECTORY', String, 'Directory to list packages on server'
17
55
  c.action do |args, options|
18
- aptly_command = AptlyCli::AptlyFile.new
56
+ config = AptlyCli::AptlyLoad.new.configure_with($config_file)
57
+ handle_global_options options
58
+ aptly_command = AptlyCli::AptlyFile.new(config, options)
19
59
  if options.directory
20
60
  puts aptly_command.file_get(options.directory)
21
61
  else
@@ -26,25 +66,31 @@ end
26
66
 
27
67
  command :file_upload do |c|
28
68
  c.syntax = 'aptly-cli file_upload [options]'
29
- c.summary = 'Parameter --directory is upload directory name. Directory would be created if it doesn’t exist.'
30
- c.description = 'File upload'
69
+ c.summary = 'File upload'
70
+ c.description = 'Parameter --directory is upload directory name. Directory would be created if it doesn’t exist.'
31
71
  c.example 'description', 'aptly-cli file_upload --upload /local/copy/of/package.deb --directory /aptlyserver_directory/'
32
72
  c.option '--directory DIRECTORY', String, 'Directory to load packages into'
33
73
  c.option '--upload UPLOAD', String, 'Package(s) to upload'
34
74
  c.action do |args, options|
35
- aptly_command = AptlyCli::AptlyFile.new
75
+ config = AptlyCli::AptlyLoad.new.configure_with($config_file)
76
+ handle_global_options options
77
+ aptly_command = AptlyCli::AptlyFile.new(config, options)
36
78
  puts aptly_command.file_post(:file_uri => options.directory, :package => options.upload, :local_file => options.upload)
37
79
  end
38
80
  end
39
81
 
40
82
  command :file_delete do |c|
41
83
  c.syntax = 'aptly-cli file_delete [options]'
42
- c.summary = 'Deletes all files in upload directory and directory itself. Or delete just a file'
43
- c.description = 'File delete'
44
- c.example 'Delete package redis-server found in redis upload directory', 'aptly-cli file_delete --target /redis/redis-server_2.8.3_i386-cc1.deb'
84
+ c.summary = 'File delete'
85
+ c.description = 'Deletes all files in upload directory and directory itself. Or delete just a file'
86
+ c.example(
87
+ 'Delete package redis-server found in redis upload directory',
88
+ 'aptly-cli file_delete --target /redis/redis-server_2.8.3_i386-cc1.deb')
45
89
  c.option '--target TARGET', String, 'Path to directory or specific package to delete'
46
90
  c.action do |args, options|
47
- aptly_command = AptlyCli::AptlyFile.new
91
+ config = AptlyCli::AptlyLoad.new.configure_with($config_file)
92
+ handle_global_options options
93
+ aptly_command = AptlyCli::AptlyFile.new(config, options)
48
94
  puts aptly_command.file_delete(options.target)
49
95
  end
50
96
  end
@@ -61,7 +107,9 @@ command :repo_create do |c|
61
107
  c.option '--default_component COMPONENT', String, 'Default component when publishing from this local repo'
62
108
  c.action do |args, options|
63
109
  puts options.name
64
- aptly_command = AptlyCli::AptlyRepo.new
110
+ config = AptlyCli::AptlyLoad.new.configure_with($config_file)
111
+ handle_global_options options
112
+ aptly_command = AptlyCli::AptlyRepo.new(config, options)
65
113
  repo_options = { :name => options.name.to_s,
66
114
  :comment => options.comment.to_s,
67
115
  :DefaultDistribution => options.default_distribution.to_s,
@@ -78,7 +126,9 @@ command :repo_delete do |c|
78
126
  c.option '--name NAME', String, 'Local repository name, required'
79
127
  c.option '--force'
80
128
  c.action do |args, options|
81
- aptly_command = AptlyCli::AptlyRepo.new
129
+ config = AptlyCli::AptlyLoad.new.configure_with($config_file)
130
+ handle_global_options options
131
+ aptly_command = AptlyCli::AptlyRepo.new(config, options)
82
132
  repo_options = { :name => options.name.to_s,
83
133
  :force => options.force.to_s }
84
134
  puts aptly_command.repo_delete(repo_options)
@@ -95,7 +145,9 @@ command :repo_edit do |c|
95
145
  c.option '--default_distribution DISTRIBUTION', String, 'Edit DefaultDistribution for repo'
96
146
  c.option '--default_component COMPONENT', String, 'Edit DefaultComponent for repo'
97
147
  c.action do |args, options|
98
- aptly_command = AptlyCli::AptlyRepo.new
148
+ config = AptlyCli::AptlyLoad.new.configure_with($config_file)
149
+ handle_global_options options
150
+ aptly_command = AptlyCli::AptlyRepo.new(config, options)
99
151
  if options.default_distribution
100
152
  repo_options = { :DefaultDistribution => options.default_distribution.to_s }
101
153
  end
@@ -115,22 +167,26 @@ command :repo_list do |c|
115
167
  c.description = 'Show list of currently available local repositories'
116
168
  c.example 'description', 'aptly-cli repo_list'
117
169
  c.action do |args, options|
118
- aptly_command = AptlyCli::AptlyRepo.new
170
+ config = AptlyCli::AptlyLoad.new.configure_with($config_file)
171
+ handle_global_options options
172
+ aptly_command = AptlyCli::AptlyRepo.new(config, options)
119
173
  puts aptly_command.repo_list()
120
174
  end
121
175
  end
122
176
 
123
177
  command :repo_package_query do |c|
124
178
  c.syntax = 'aptly-cli repo_package_query [options]'
125
- c.summary = 'List all packages in local repository or perform search on repository contents and return result., requires --name'
126
- c.description = 'List all packages or search on repo contents, requires --name'
179
+ c.summary = 'List all packages or search on repo contents, requires --name'
180
+ c.description = 'List all packages in local repository or perform search on repository contents and return result., requires --name'
127
181
  c.example 'description', 'aptly-cli repo_package_query --name megatronsoftware -query geoipupdate'
128
182
  c.option '--name NAME', String, 'Local repository name, required'
129
183
  c.option '--query QUERY', String, 'Package to query'
130
184
  c.option '--with_deps', 'Return results with dependencies'
131
185
  c.option '--format FORMAT', String, 'Format type to return, compact by default. "details" is an option'
132
186
  c.action do |args, options|
133
- aptly_command = AptlyCli::AptlyRepo.new
187
+ config = AptlyCli::AptlyLoad.new.configure_with($config_file)
188
+ handle_global_options options
189
+ aptly_command = AptlyCli::AptlyRepo.new(config, options)
134
190
  if options.query
135
191
  repo_options = { :name => options.name.to_s, :query => options.query.to_s }
136
192
  elsif options.with_deps and options.query.nil?
@@ -146,12 +202,14 @@ end
146
202
 
147
203
  command :repo_upload do |c|
148
204
  c.syntax = 'aptly-cli repo_upload [options]'
149
- c.summary = 'Import packages from files (uploaded using File Upload API) to the local repository. If directory specified, aptly would discover package files automatically.
150
-
151
- Adding same package to local repository is not an error.
152
-
153
- By default aptly would try to remove every successfully processed file and directory :dir (if it becomes empty after import).'
154
- c.description = 'Import packages from files'
205
+ c.summary = 'Import packages from files'
206
+ c.description = [
207
+ 'Import packages from files (uploaded using File Upload API) to the',
208
+ 'local repository. If directory specified, aptly would discover package',
209
+ 'files automatically. Adding same package to local repository is not an',
210
+ 'error. By default aptly would try to remove every successfully',
211
+ 'processed file and directory :dir (if it becomes empty after import).'
212
+ ].join(' ')
155
213
  c.example 'description', 'aptly-cli repo_upload --name rocksoftware --dir rockpackages --noremove'
156
214
  c.option '--name NAME', String, 'Local repository name, required'
157
215
  c.option '--dir DIR', String, 'Directory where packages are stored via File API'
@@ -159,7 +217,9 @@ command :repo_upload do |c|
159
217
  c.option '--noremove', 'Flag to not remove any files that were uploaded via File API after repo upload'
160
218
  c.option '--forcereplace', 'flag to replace file(s) already in the repo'
161
219
  c.action do |args, options|
162
- aptly_command = AptlyCli::AptlyRepo.new
220
+ config = AptlyCli::AptlyLoad.new.configure_with($config_file)
221
+ handle_global_options options
222
+ aptly_command = AptlyCli::AptlyRepo.new(config, options)
163
223
  puts aptly_command.repo_upload({ :name => options.name, :dir => options.dir,
164
224
  :file => options.file, :noremove => options.noremove,
165
225
  :forcereplace => options.forcereplace })
@@ -173,40 +233,46 @@ command :repo_show do |c|
173
233
  c.example 'description', 'aptly-cli repo_show --name megatronsoftware'
174
234
  c.option '--name NAME', String, 'Local repository name, required'
175
235
  c.action do |args, options|
176
- aptly_command = AptlyCli::AptlyRepo.new
236
+ config = AptlyCli::AptlyLoad.new.configure_with($config_file)
237
+ handle_global_options options
238
+ aptly_command = AptlyCli::AptlyRepo.new(config, options)
177
239
  puts aptly_command.repo_show(options.name)
178
240
  end
179
241
  end
180
242
 
181
243
  command :publish_drop do |c|
182
244
  c.syntax = 'aptly-cli publish_drop [options]'
183
- c.summary = 'Delete published repository, clean up files in published directory.'
184
- c.description = 'Delete published repository'
245
+ c.summary = 'Delete published repository'
246
+ c.description = 'Delete published repository, clean up files in published directory.'
185
247
  c.example 'Delete publish repository prefix precisetest', 'aptly-cli publish_drop --distribution precisetest'
186
248
  c.option '--prefix PREFIX', String, 'prefix, optional'
187
249
  c.option '--distribution DISTRIBUTION', String, 'distribution'
188
250
  c.option '--force', 'force published repository removal even if component cleanup fails'
189
251
  c.action do |args, options|
190
- aptly_command = AptlyCli::AptlyPublish.new
252
+ config = AptlyCli::AptlyLoad.new.configure_with($config_file)
253
+ handle_global_options options
254
+ aptly_command = AptlyCli::AptlyPublish.new(config, options)
191
255
  puts aptly_command.publish_drop({ :prefix => options.prefix, :distribution => options.distribution, :force => options.force })
192
256
  end
193
257
  end
194
258
 
195
259
  command :publish_list do |c|
196
260
  c.syntax = 'aptly-cli publish_list [options]'
197
- c.summary = 'List published repositories.'
261
+ c.summary = 'List published repositories'
198
262
  c.description = 'List published repositories.'
199
263
  c.example 'List published repositories', 'aptly-cli publish_list'
200
264
  c.action do |args, options|
201
- aptly_command = AptlyCli::AptlyPublish.new
265
+ config = AptlyCli::AptlyLoad.new.configure_with($config_file)
266
+ handle_global_options options
267
+ aptly_command = AptlyCli::AptlyPublish.new(config, options)
202
268
  puts aptly_command.publish_list()
203
269
  end
204
270
  end
205
271
 
206
272
  command :publish_repo do |c|
207
273
  c.syntax = 'aptly-cli publish_repo [options]'
208
- c.summary = 'Publish local repository or snapshot under specified prefix. Storage might be passed in prefix as well, e.g. s3:packages/. To supply empty prefix, just remove last part (POST /api/publish/:prefix/<:repos>or<:snapshots>'
209
- c.description = 'Publish local repository or snapshot under specified prefix'
274
+ c.summary = 'Publish local repository or snapshot under specified prefix'
275
+ c.description = 'Publish local repository or snapshot under specified prefix. Storage might be passed in prefix as well, e.g. s3:packages/. To supply empty prefix, just remove last part (POST /api/publish/:prefix/<:repos>or<:snapshots>'
210
276
  c.example 'publish multiple repos as source', 'aptly-cli publish_repo --sourcekind local --name precise/megatronsoftware,trusty/rocksoftware22 --architectures i386 amd64'
211
277
  c.example 'publish one repo, two archs, forceoverwrite', 'aptly-cli publish_repo --sourcekind local --name megatronsoftware --architectures i386 amd64 --forceoverwrite true'
212
278
  c.example 'publish 2 snapshots into one publish point', 'aptly-cli publish_repo --sourcekind snapshot --name precise/rocksoftware300,main/rocksoftware200 --label test_snap'
@@ -228,7 +294,9 @@ command :publish_repo do |c|
228
294
  c.option '--gpg_passphrase GPGPASS', String, 'gpg key passphrase (if using over http, would be transmitted in clear text!)'
229
295
  c.option '--gpg_passphrase_file GPGPASSFILE', String, 'gpg passphrase file (local to aptly server/user)'
230
296
  c.action do |args, options|
231
- aptly_command = AptlyCli::AptlyPublish.new
297
+ config = AptlyCli::AptlyLoad.new.configure_with($config_file)
298
+ handle_global_options options
299
+ aptly_command = AptlyCli::AptlyPublish.new(config, options)
232
300
  puts aptly_command.publish_repo(options.name, { :sourcekind => options.sourcekind, :prefix => options.prefix,
233
301
  :label => options.label, :distribution => options.distribution,
234
302
  :origin => options.origin, :forceoverwrite => options.forceoverwrite,
@@ -240,8 +308,8 @@ end
240
308
 
241
309
  command :publish_update do |c|
242
310
  c.syntax = 'aptly-cli publish_update [options]'
243
- c.summary = 'Update published repository. If local repository has been published, published repository would be updated to match local repository contents. If snapshots have been been published, it is possible to switch each component to new snapshot'
244
- c.description = 'Update published repository'
311
+ c.summary = 'Update published repository'
312
+ c.description = 'Update published repository. If local repository has been published, published repository would be updated to match local repository contents. If snapshots have been been published, it is possible to switch each component to new snapshot'
245
313
  c.example 'description', 'aptly-cli publish_update --forceoverwrite --distribution precise'
246
314
  c.option '--prefix PREFIX', String, 'Publishing prefix, default root'
247
315
  c.option '--distribution DISTRIBUTION', String, 'Distribution name'
@@ -255,7 +323,9 @@ command :publish_update do |c|
255
323
  c.option '--gpg_passphrase GPGPASS', String, 'gpg key passphrase (if using over http, would be transmitted in clear text!)'
256
324
  c.option '--gpg_passphrase_file GPGPASSFILE', String, 'gpg passphrase file (local to aptly server/user)'
257
325
  c.action do |args, options|
258
- aptly_command = AptlyCli::AptlyPublish.new
326
+ config = AptlyCli::AptlyLoad.new.configure_with($config_file)
327
+ handle_global_options options
328
+ aptly_command = AptlyCli::AptlyPublish.new(config, options)
259
329
  puts aptly_command.publish_update({ :prefix => options.prefix, :distribution => options.distribution, :forceoverwrite => options.forceoverwrite,
260
330
  :skip => options.gpg_skip, :batch => options.gpg_batch, :gpgKey => options.gpg_key,
261
331
  :keyring => options.gpg_keyring, :secretKeyring => options.gpg_secret_keyring,
@@ -266,41 +336,47 @@ end
266
336
 
267
337
  command :snapshot_create do |c|
268
338
  c.syntax = 'aptly-cli snapshot_create [options]'
269
- c.summary = 'Create snapshot of current local repository :name contents as new snapshot with name :snapname'
270
- c.description = 'Create snapshot, require --name'
339
+ c.summary = 'Create snapshot, require --name'
340
+ c.description = 'Create snapshot of current local repository :name contents as new snapshot with name :snapname'
271
341
  c.example 'Creating new snapshot megasoftware22-snap from megasoftware22 repo', 'aptly-cli snapshot_create --name megasoftware22-snap --repo meagsoftware22'
272
342
  c.option '--name NAME', String, 'Name of new snapshot, required'
273
343
  c.option '--repo REPO', String, 'Name of repo to snapshot'
274
344
  c.option '--description DESCRIPTION', String, 'Set description for snapshot'
275
345
  c.action do |args, options|
276
- aptly_command = AptlyCli::AptlySnapshot.new
346
+ config = AptlyCli::AptlyLoad.new.configure_with($config_file)
347
+ handle_global_options options
348
+ aptly_command = AptlyCli::AptlySnapshot.new(config, options)
277
349
  puts aptly_command.snapshot_create(options.name, options.repo, options.description)
278
350
  end
279
351
  end
280
352
 
281
353
  command :snapshot_delete do |c|
282
354
  c.syntax = 'aptly-cli snapshot_delete [options]'
283
- c.summary = 'Delete snapshot. Snapshot can’t be deleted if it is published. aptly would refuse to delete snapshot if it has been used as source to create other snapshots, but that could be overridden with force parameter'
284
- c.description = 'Delete snapshot, require --name'
355
+ c.summary = 'Delete snapshot, require --name'
356
+ c.description = 'Delete snapshot. Snapshot can’t be deleted if it is published. aptly would refuse to delete snapshot if it has been used as source to create other snapshots, but that could be overridden with force parameter'
285
357
  c.example 'Deleting the snapshot megasoftware22', 'aptly-cli snapshot_delete --name megatronsoftware22'
286
358
  c.example 'Deleting the snapshot megasoftware22 with force option', 'aptly-cli snapshot_delete --name megatronsoftware22 --force'
287
359
  c.option '--name NAME', String, 'Local snapshot name, required'
288
360
  c.option '--force', 'Force'
289
361
  c.action do |args, options|
290
- aptly_command = AptlyCli::AptlySnapshot.new
362
+ config = AptlyCli::AptlyLoad.new.configure_with($config_file)
363
+ handle_global_options options
364
+ aptly_command = AptlyCli::AptlySnapshot.new(config, options)
291
365
  puts aptly_command.snapshot_delete(options.name, options.force)
292
366
  end
293
367
  end
294
368
 
295
369
  command :snapshot_diff do |c|
296
370
  c.syntax = 'aptly-cli snapshot_diff [options]'
297
- c.summary = 'Calculate difference between two snapshots --name (left) and --withsnapshot (right).'
371
+ c.summary = 'Calculate difference between two snapshots'
298
372
  c.description = 'Calculate difference between two snapshots, require --name, require --withsnapshot'
299
373
  c.example 'Show difference between megatronsoftware and rocksoftware snapshots', 'aptly-cli snapshot_diff --name megatronsoftware --withsnapshot rocksoftware'
300
374
  c.option '--name NAME', String, 'Local snapshot name (left)'
301
375
  c.option '--withsnapshot WITHSNAPSHOT', String, 'Snapshot to diff against (right)'
302
376
  c.action do |args, options|
303
- aptly_command = AptlyCli::AptlySnapshot.new
377
+ config = AptlyCli::AptlyLoad.new.configure_with($config_file)
378
+ handle_global_options options
379
+ aptly_command = AptlyCli::AptlySnapshot.new(config, options)
304
380
  puts aptly_command.snapshot_diff(options.name, options.withsnapshot)
305
381
  end
306
382
  end
@@ -313,15 +389,17 @@ command :snapshot_list do |c|
313
389
  c.example 'Return list sorted by time', 'aptly-cli snapshot_list --sort time'
314
390
  c.option '--sort', String, 'Set sort by'
315
391
  c.action do |args, options|
316
- aptly_command = AptlyCli::AptlySnapshot.new
392
+ config = AptlyCli::AptlyLoad.new.configure_with($config_file)
393
+ handle_global_options options
394
+ aptly_command = AptlyCli::AptlySnapshot.new(config, options)
317
395
  puts aptly_command.snapshot_list(options.sort)
318
396
  end
319
397
  end
320
398
 
321
399
  command :snapshot_search do |c|
322
400
  c.syntax = 'aptly-cli snapshot_search [options]'
323
- c.summary = 'List all packages in snapshot or perform search on snapshot contents and return result'
324
- c.description = 'List all packages in snapshot or perform search'
401
+ c.summary = 'List all packages in snapshot or perform search'
402
+ c.description = 'List all packages in snapshot or perform search on snapshot contents and return result'
325
403
  c.example 'List all packages in snapshot megasoftware22-snap', 'aptly-cli snapshot_search --name megasoftware22-snap'
326
404
  c.example 'List all packages in snapshot megasoftware22-snap with format set to details', 'aptly-cli snapshot_search --name megasoftware22-snap --format details'
327
405
  c.example 'Search for package called nginx in snapshot megasoftware22-snap', 'aptly-cli snapshot_search --name megasoftware22-snap --query nginx'
@@ -330,7 +408,9 @@ command :snapshot_search do |c|
330
408
  c.option '--withdeps', 'Include package dependencies'
331
409
  c.option '--format FORMAT', String, 'Format the respone of the snapshot search results, compact by default.'
332
410
  c.action do |args, options|
333
- aptly_command = AptlyCli::AptlySnapshot.new
411
+ config = AptlyCli::AptlyLoad.new.configure_with($config_file)
412
+ handle_global_options options
413
+ aptly_command = AptlyCli::AptlySnapshot.new(config, options)
334
414
  puts aptly_command.snapshot_search(options.name, { :query => options.query, :format => options.format, :withdeps => options.withdeps })
335
415
  end
336
416
  end
@@ -342,7 +422,9 @@ command :snapshot_show do |c|
342
422
  c.example 'Show snapshot information for repo named megatronsoftware', 'aptly-cli snapshot_show --name megatronsoftware'
343
423
  c.option '--name NAME', String, 'Local snapshot name, required'
344
424
  c.action do |args, options|
345
- aptly_command = AptlyCli::AptlySnapshot.new
425
+ config = AptlyCli::AptlyLoad.new.configure_with($config_file)
426
+ handle_global_options options
427
+ aptly_command = AptlyCli::AptlySnapshot.new(config, options)
346
428
  puts aptly_command.snapshot_show(options.name)
347
429
  end
348
430
  end
@@ -356,19 +438,23 @@ command :snapshot_update do |c|
356
438
  c.option '--new_name NEWNAME', String, 'New name for the snapshot'
357
439
  c.option '--description DESCRIPTION', String, 'Update description for snapshot'
358
440
  c.action do |args, options|
359
- aptly_command = AptlyCli::AptlySnapshot.new
441
+ config = AptlyCli::AptlyLoad.new.configure_with($config_file)
442
+ handle_global_options options
443
+ aptly_command = AptlyCli::AptlySnapshot.new(config, options)
360
444
  puts aptly_command.snapshot_update(options.name, options.new_name, options.description)
361
445
  end
362
446
  end
363
447
 
364
448
  command :graph do |c|
365
449
  c.syntax = 'aptly-cli graph [options]'
366
- c.summary = 'Download a graph of repository layout. Current options are "svg" and "png"'
367
- c.description = 'Download an svg or png graph of repository layout'
450
+ c.summary = 'Download an svg or png graph of repository layout'
451
+ c.description = 'Download a graph of repository layout. Current options are "svg" and "png"'
368
452
  c.example 'description', 'aptly-cli graph png > ~/repo_graph.png'
369
453
  c.option '--type GRAPH_TYPE', String, 'Type of graph to download, present options are png or svg'
370
454
  c.action do |args, options|
371
- aptly_command = AptlyCli::AptlyMisc.new
455
+ config = AptlyCli::AptlyLoad.new.configure_with($config_file)
456
+ handle_global_options options
457
+ aptly_command = AptlyCli::AptlyMisc.new(config, options)
372
458
  puts aptly_command.get_graph(options.type)
373
459
  end
374
460
  end
@@ -378,8 +464,10 @@ command :version do |c|
378
464
  c.description = 'Display aptly server version'
379
465
  c.example 'description', 'aptly-cli version'
380
466
  c.action do |args, options|
381
- aptly_command = AptlyCli::AptlyMisc.new
382
- puts aptly_command.get_version()
467
+ config = AptlyCli::AptlyLoad.new.configure_with($config_file)
468
+ handle_global_options options
469
+ aptly_command = AptlyCli::AptlyMisc.new(config, options)
470
+ puts aptly_command.get_version()
383
471
  end
384
472
  end
385
473
 
@@ -1,3 +1,3 @@
1
1
  module AptlyCli
2
- VERSION = '0.2.9'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
@@ -0,0 +1,55 @@
1
+ class AptlyCommand
2
+ def initialize(config, options = nil)
3
+ @config = config
4
+ options ||= Options.new
5
+
6
+ if options.server
7
+ @config[:server] = options.server
8
+ end
9
+
10
+ if options.username
11
+ @config[:username] = options.username
12
+ end
13
+
14
+ if options.password
15
+ @config[:password] = options.password
16
+ end
17
+
18
+ if options.debug
19
+ @config[:debug] = options.debug
20
+ end
21
+
22
+ @config.each do |k, v|
23
+ if v == '${PROMPT}'
24
+ @config[k.to_sym] = ask("Enter a value for #{k}:")
25
+ elsif v == '${PROMPT_PASSWORD}'
26
+ @config[k.to_sym] = password("Enter a value for #{k}:")
27
+ elsif v == '${KEYRING}'
28
+ require 'keyring'
29
+
30
+ keyring = Keyring.new
31
+ value = keyring.get_password(@config[:server], @config[:username])
32
+
33
+ unless value
34
+ # Prompt for password...
35
+ value = password("Enter a value for #{k}:")
36
+
37
+ # ... and store in keyring
38
+ keyring.set_password(@config[:server], @config[:username], value)
39
+ end
40
+
41
+ @config[k.to_sym] = value
42
+ end
43
+ end
44
+
45
+ base_uri = "#{@config[:proto]}://#{@config[:server]}:#{@config[:port]}/api"
46
+ self.class.base_uri base_uri
47
+
48
+ if @config[:username]
49
+ if @config[:password]
50
+ self.class.basic_auth @config[:username].to_s, @config[:password].to_s
51
+ end
52
+ end
53
+ debug_output $stdout if @config[:debug] == true
54
+ end
55
+ end
data/lib/aptly_file.rb CHANGED
@@ -1,28 +1,14 @@
1
1
  require 'aptly_cli/version'
2
+ require 'aptly_command'
2
3
  require 'aptly_load'
3
4
  require 'httmultiparty'
4
5
 
5
6
  module AptlyCli
6
7
  # Uploading file into Aptly
7
- class AptlyFile
8
+ class AptlyFile < AptlyCommand
8
9
  include HTTMultiParty
9
10
  attr_accessor :file_uri, :package, :local_file_path
10
11
 
11
- # Load aptly-cli.conf and establish base_uri
12
- @config = AptlyCli::AptlyLoad.new.configure_with('/etc/aptly-cli.conf')
13
- base_uri "#{@config[:proto]}://#{@config[:server]}:#{@config[:port]}/api"
14
-
15
- if @config[:username]
16
- if @config[:password]
17
- basic_auth @config[:username].to_s, @config[:password].to_s
18
- end
19
- end
20
-
21
- debug_output $stdout if @config[:debug] == true
22
-
23
- def initialize(file_uri=nil, package=nil, local_file_path=nil)
24
- end
25
-
26
12
  def file_dir
27
13
  uri = '/files'
28
14
  self.class.get uri
data/lib/aptly_load.rb CHANGED
@@ -20,7 +20,7 @@ module AptlyCli
20
20
  port: 8082
21
21
  }
22
22
 
23
- @valid_config_keys = @config.keys
23
+ @valid_config_keys = @config.keys + [:username, :password, :debug]
24
24
  end
25
25
 
26
26
  # Configure through hash
@@ -28,6 +28,8 @@ module AptlyCli
28
28
  opts.each do |k, v|
29
29
  config[k.to_sym] = v if @valid_config_keys.include? k.to_sym
30
30
  end
31
+
32
+ @config
31
33
  end
32
34
 
33
35
  # Configure through yaml file
@@ -36,7 +38,8 @@ module AptlyCli
36
38
  config = YAML.load(IO.read(path_to_yaml_file))
37
39
  rescue Errno::ENOENT
38
40
  @log.warn(
39
- 'YAML configuration file couldn\'t be found at /etc/aptly-cli.conf. Using defaults.')
41
+ "YAML configuration file couldn\'t be found at " \
42
+ "#{path_to_yaml_file}. Using defaults.")
40
43
  return @config
41
44
  rescue Psych::SyntaxError
42
45
  @log.warn(
data/lib/aptly_misc.rb CHANGED
@@ -1,25 +1,14 @@
1
1
  require 'aptly_cli/version'
2
+ require 'aptly_command'
2
3
  require 'aptly_load'
3
4
  require 'httmultiparty'
4
5
  require 'json'
5
6
 
6
7
  module AptlyCli
7
8
  # Misc Aptly Class
8
- class AptlyMisc
9
+ class AptlyMisc < AptlyCommand
9
10
  include HTTMultiParty
10
11
 
11
- # Load aptly-cli.conf and establish base_uri
12
- @config = AptlyCli::AptlyLoad.new.configure_with('/etc/aptly-cli.conf')
13
- base_uri "#{@config[:proto]}://#{@config[:server]}:#{@config[:port]}/api"
14
-
15
- if @config[:username]
16
- if @config[:password]
17
- basic_auth @config[:username].to_s, @config[:password].to_s
18
- end
19
- end
20
-
21
- debug_output $stdout if @config[:debug] == true
22
-
23
12
  def get_graph(extension)
24
13
  uri = "/graph.#{extension}"
25
14
  self.class.get(uri)
data/lib/aptly_package.rb CHANGED
@@ -1,25 +1,14 @@
1
1
  require 'aptly_cli/version'
2
+ require 'aptly_command'
2
3
  require 'aptly_load'
3
4
  require 'httmultiparty'
4
5
  require 'json'
5
6
 
6
7
  module AptlyCli
7
8
  # Aptly Package API
8
- class AptlyPackage
9
+ class AptlyPackage < AptlyCommand
9
10
  include HTTMultiParty
10
11
 
11
- # Load aptly-cli.conf and establish base_uri
12
- @config = AptlyCli::AptlyLoad.new.configure_with('/etc/aptly-cli.conf')
13
- base_uri "#{@config[:proto]}://#{@config[:server]}:#{@config[:port]}/api"
14
-
15
- if @config[:username]
16
- if @config[:password]
17
- basic_auth @config[:username].to_s, @config[:password].to_s
18
- end
19
- end
20
-
21
- debug_output $stdout if @config[:debug] == true
22
-
23
12
  def package_show(package_key)
24
13
  uri = "/packages/#{package_key}"
25
14
  self.class.get(uri)
data/lib/aptly_publish.rb CHANGED
@@ -1,25 +1,14 @@
1
1
  require 'aptly_cli/version'
2
+ require 'aptly_command'
2
3
  require 'aptly_load'
3
4
  require 'httmultiparty'
4
5
  require 'json'
5
6
 
6
7
  module AptlyCli
7
8
  # :nodoc:
8
- class AptlyPublish
9
+ class AptlyPublish < AptlyCommand
9
10
  include HTTMultiParty
10
11
 
11
- # Load aptly-cli.conf and establish base_uri
12
- @config = AptlyCli::AptlyLoad.new.configure_with('/etc/aptly-cli.conf')
13
- base_uri "#{@config[:proto]}://#{@config[:server]}:#{@config[:port]}/api"
14
-
15
- if @config[:username]
16
- if @config[:password]
17
- basic_auth @config[:username].to_s, @config[:password].to_s
18
- end
19
- end
20
-
21
- debug_output $stdout if @config[:debug] == true
22
-
23
12
  @@available_gpg_options = [:skip, :batch, :gpgKey, :keyring, :secretKeyring,
24
13
  :passphrase, :passphraseFile]
25
14
  @@available_options_for_repo = [:distribution, :label, :origin,
data/lib/aptly_repo.rb CHANGED
@@ -1,22 +1,13 @@
1
1
  require 'aptly_cli/version'
2
+ require 'aptly_command'
2
3
  require 'aptly_load'
3
4
  require 'httmultiparty'
4
5
  require 'json'
5
6
 
6
7
  module AptlyCli
7
- # Aplty class to work with Repo API
8
- class AptlyRepo
8
+ # Aptly class to work with Repo API
9
+ class AptlyRepo < AptlyCommand
9
10
  include HTTMultiParty
10
- # Load aptly-cli.conf and establish base_uri
11
- @config = AptlyCli::AptlyLoad.new.configure_with('/etc/aptly-cli.conf')
12
- base_uri "#{@config[:proto]}://#{@config[:server]}:#{@config[:port]}/api"
13
-
14
- if @config[:username]
15
- if @config[:password]
16
- basic_auth @config[:username].to_s, @config[:password].to_s
17
- end
18
- end
19
- debug_output $stdout if @config[:debug] == true
20
11
 
21
12
  def repo_create(repo_options = { name: nil,
22
13
  comment: nil,
@@ -1,25 +1,14 @@
1
1
  require 'aptly_cli/version'
2
+ require 'aptly_command'
2
3
  require 'aptly_load'
3
4
  require 'httmultiparty'
4
5
  require 'json'
5
6
 
6
7
  module AptlyCli
7
- # Aplty class to work with Snapshot API
8
- class AptlySnapshot
8
+ # Aptly class to work with Snapshot API
9
+ class AptlySnapshot < AptlyCommand
9
10
  include HTTMultiParty
10
11
 
11
- # Load aptly-cli.conf and establish base_uri
12
- @config = AptlyCli::AptlyLoad.new.configure_with('/etc/aptly-cli.conf')
13
- base_uri "#{@config[:proto]}://#{@config[:server]}:#{@config[:port]}/api"
14
-
15
- if @config[:username]
16
- if @config[:password]
17
- basic_auth @config[:username].to_s, @config[:password].to_s
18
- end
19
- end
20
-
21
- debug_output $stdout if @config[:debug] == true
22
-
23
12
  def snapshot_delete(name, force=nil)
24
13
  uri = "/snapshots/#{name}"
25
14
  uri += '?force=1' if force == true
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.2.9
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-10 00:00:00.000000000 Z
11
+ date: 2016-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,6 +122,7 @@ files:
122
122
  - bin/setup
123
123
  - lib/aptly_cli.rb
124
124
  - lib/aptly_cli/version.rb
125
+ - lib/aptly_command.rb
125
126
  - lib/aptly_file.rb
126
127
  - lib/aptly_load.rb
127
128
  - lib/aptly_misc.rb