uffizzi-cli 0.12.0 → 0.14.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c27a1f65cd69d407dc2f086733a20baaf6e129b7433322ac61682f6b8a1fa54e
4
- data.tar.gz: 61c6860dbc035009ee6197f353c05d0af95eda6d6f77b67d25f672ba954e114f
3
+ metadata.gz: a7a27f279e964f07491f920557722194d65c8a9259487a5a717707f6075d164b
4
+ data.tar.gz: d9825fe3425b0dde3dbe1e4528686100c6ca22f30aed4aa7a332cf991bbb6480
5
5
  SHA512:
6
- metadata.gz: 709d000e6701f32d3dcaa3745c68d2eb63695dba2dd8ef939201569605bb121fdd3422d730d3bdc2687a33cc81810b97a3a4f4841187aac68547824293523173
7
- data.tar.gz: 1b0ae241adab3fb770f25cca8709ae779b5c8de16056fa71e6242d470123550b6cacc920f1e2b9474951323b72d1d18160a840ed64c4814469eb89e138d0c3d5
6
+ metadata.gz: 179a75d66bd89efc1ad9b3decf5ebc6c5526b2fe0fdd02e616940b4f12544505c956874a0649a99a2c5d1e14fce6e1dcda305a9028e08d8e9c2b8b5f63955fb5
7
+ data.tar.gz: a8d2637bef4250c33bb1cc8725556a2758384c9115938865e8acd70b92fce515ccd94b691913341c6b6f64a29f6d9ff34e99148fd62cacf8d6551d72a1222508
@@ -34,17 +34,17 @@ module Uffizzi
34
34
 
35
35
  def set_server
36
36
  config_server = ConfigFile.exists? ? read_option_from_config(:server) : nil
37
- server_address = @options[:server] || config_server || Uffizzi.ui.ask('Server: ')
37
+ server_address = (@options[:server] || config_server || Uffizzi.ui.ask('Server:')).sub(/\/+$/, '')
38
38
  server_address.start_with?('http:', 'https:') ? server_address : "https://#{server_address}"
39
39
  end
40
40
 
41
41
  def set_username
42
42
  config_username = ConfigFile.exists? ? read_option_from_config(:username) : nil
43
- @options[:username] || config_username || Uffizzi.ui.ask('Username: ')
43
+ @options[:username] || config_username || Uffizzi.ui.ask('Username:')
44
44
  end
45
45
 
46
46
  def set_password
47
- ENV['UFFIZZI_PASSWORD'] || Uffizzi.ui.ask('Password: ', echo: false)
47
+ ENV['UFFIZZI_PASSWORD'] || Uffizzi.ui.ask('Password:', echo: false)
48
48
  end
49
49
 
50
50
  def read_option_from_config(option)
@@ -12,19 +12,24 @@ module Uffizzi
12
12
  desc 'service', 'Show the preview services info'
13
13
  require_relative 'preview/service'
14
14
  subcommand 'service', Uffizzi::Cli::Preview::Service
15
+
15
16
  desc 'list', 'List all previews'
17
+ method_option :filter, required: false, type: :string, aliases: '-f'
18
+ method_option :output, required: false, type: :string, aliases: '-o', enum: ['json']
16
19
  def list
17
20
  run('list')
18
21
  end
19
22
 
20
23
  desc 'create [COMPOSE_FILE]', 'Create a preview'
21
24
  method_option :output, required: false, type: :string, aliases: '-o', enum: ['json', 'github-action']
25
+ method_option :"set-labels", required: false, type: :string, aliases: '-s'
22
26
  def create(file_path = nil)
23
27
  run('create', file_path: file_path)
24
28
  end
25
29
 
26
30
  desc 'uffizzi preview update [DEPLOYMENT_ID] [COMPOSE_FILE]', 'Update a preview'
27
31
  method_option :output, required: false, type: :string, aliases: '-o', enum: ['json', 'github-action']
32
+ method_option :"set-labels", required: false, type: :string, aliases: '-s'
28
33
  def update(deployment_name, file_path)
29
34
  run('update', deployment_name: deployment_name, file_path: file_path)
30
35
  end
@@ -47,10 +52,7 @@ module Uffizzi
47
52
  private
48
53
 
49
54
  def run(command, file_path: nil, deployment_name: nil)
50
- unless options[:output].nil?
51
- Uffizzi.ui.output_format = options[:output]
52
- Uffizzi.ui.disable_stdout
53
- end
55
+ Uffizzi.ui.output_format = options[:output]
54
56
  raise Uffizzi::Error.new('You are not logged in.') unless Uffizzi::AuthHelper.signed_in?
55
57
  raise Uffizzi::Error.new('This command needs project to be set in config file') unless CommandService.project_set?(options)
56
58
 
@@ -58,11 +60,11 @@ module Uffizzi
58
60
 
59
61
  case command
60
62
  when 'list'
61
- handle_list_command(project_slug)
63
+ handle_list_command(project_slug, options[:filter])
62
64
  when 'create'
63
- handle_create_command(file_path, project_slug)
65
+ handle_create_command(file_path, project_slug, options[:"set-labels"])
64
66
  when 'update'
65
- handle_update_command(deployment_name, file_path, project_slug)
67
+ handle_update_command(deployment_name, file_path, project_slug, options[:"set-labels"])
66
68
  when 'delete'
67
69
  handle_delete_command(deployment_name, project_slug)
68
70
  when 'describe'
@@ -72,8 +74,9 @@ module Uffizzi
72
74
  end
73
75
  end
74
76
 
75
- def handle_list_command(project_slug)
76
- response = fetch_deployments(ConfigFile.read_option(:server), project_slug)
77
+ def handle_list_command(project_slug, filter)
78
+ parsed_filter = filter.nil? ? {} : build_filter_params(filter)
79
+ response = fetch_deployments(ConfigFile.read_option(:server), project_slug, parsed_filter)
77
80
 
78
81
  if ResponseHelper.ok?(response)
79
82
  handle_succeed_list_response(response)
@@ -82,8 +85,10 @@ module Uffizzi
82
85
  end
83
86
  end
84
87
 
85
- def handle_create_command(file_path, project_slug)
86
- params = file_path.nil? ? {} : prepare_params(file_path)
88
+ def handle_create_command(file_path, project_slug, labels)
89
+ Uffizzi.ui.disable_stdout unless options[:output].nil?
90
+ params = prepare_params(file_path, labels)
91
+
87
92
  response = create_deployment(ConfigFile.read_option(:server), project_slug, params)
88
93
 
89
94
  if !ResponseHelper.created?(response)
@@ -101,12 +106,13 @@ module Uffizzi
101
106
  handle_preview_interruption(deployment_id, ConfigFile.read_option(:server), project_slug)
102
107
  end
103
108
 
104
- def handle_update_command(deployment_name, file_path, project_slug)
109
+ def handle_update_command(deployment_name, file_path, project_slug, labels)
110
+ Uffizzi.ui.disable_stdout unless options[:output].nil?
105
111
  deployment_id = PreviewService.read_deployment_id(deployment_name)
106
112
 
107
113
  raise Uffizzi::Error.new("Preview should be specified in 'deployment-PREVIEW_ID' format") if deployment_id.nil?
108
114
 
109
- params = prepare_params(file_path)
115
+ params = prepare_params(file_path, labels)
110
116
  response = update_deployment(ConfigFile.read_option(:server), project_slug, deployment_id, params)
111
117
 
112
118
  if !ResponseHelper.ok?(response)
@@ -175,7 +181,11 @@ module Uffizzi
175
181
  raise Uffizzi::Error.new('The project has no active deployments') if deployments.empty?
176
182
 
177
183
  deployments.each do |deployment|
178
- Uffizzi.ui.say("deployment-#{deployment[:id]}")
184
+ if Uffizzi.ui.output_format.nil?
185
+ Uffizzi.ui.say("deployment-#{deployment[:id]}")
186
+ else
187
+ Uffizzi.ui.pretty_say(deployment)
188
+ end
179
189
  end
180
190
  end
181
191
 
@@ -205,26 +215,10 @@ module Uffizzi
205
215
  end
206
216
  end
207
217
 
208
- def prepare_params(file_path)
209
- begin
210
- compose_file_data = EnvVariablesService.substitute_env_variables(File.read(file_path))
211
- rescue Errno::ENOENT => e
212
- raise Uffizzi::Error.new(e.message)
213
- end
214
-
215
- compose_file_dir = File.dirname(file_path)
216
- dependencies = ComposeFileService.parse(compose_file_data, compose_file_dir)
217
- absolute_path = File.absolute_path(file_path)
218
- compose_file_params = {
219
- path: absolute_path,
220
- content: Base64.encode64(compose_file_data),
221
- source: absolute_path,
222
- }
223
-
224
- {
225
- compose_file: compose_file_params,
226
- dependencies: dependencies,
227
- }
218
+ def prepare_params(file_path, labels)
219
+ compose_file_params = file_path.nil? ? {} : build_compose_file_params(file_path)
220
+ metadata_params = labels.nil? ? {} : build_metadata_params(labels)
221
+ compose_file_params.merge(metadata_params)
228
222
  end
229
223
 
230
224
  def handle_preview_interruption(deployment_id, server, project_slug)
@@ -251,10 +245,77 @@ module Uffizzi
251
245
  end
252
246
 
253
247
  def build_deployment_data(deployment)
248
+ url_server = ConfigFile.read_option(:server)
249
+
254
250
  {
255
251
  id: "deployment-#{deployment[:id]}",
256
252
  url: "https://#{deployment[:preview_url]}",
253
+ containers_uri: "#{url_server}/projects/#{deployment[:project_id]}/deployments/#{deployment[:id]}/containers",
257
254
  }
258
255
  end
256
+
257
+ def build_compose_file_params(file_path)
258
+ begin
259
+ compose_file_data = EnvVariablesService.substitute_env_variables(File.read(file_path))
260
+ rescue Errno::ENOENT => e
261
+ raise Uffizzi::Error.new(e.message)
262
+ end
263
+
264
+ compose_file_dir = File.dirname(file_path)
265
+ dependencies = ComposeFileService.parse(compose_file_data, compose_file_dir)
266
+ absolute_path = File.absolute_path(file_path)
267
+ compose_file_params = {
268
+ path: absolute_path,
269
+ content: Base64.encode64(compose_file_data),
270
+ source: absolute_path,
271
+ }
272
+
273
+ {
274
+ compose_file: compose_file_params,
275
+ dependencies: dependencies,
276
+ }
277
+ end
278
+
279
+ def build_metadata_params(labels)
280
+ {
281
+ metadata: {
282
+ 'labels' => parse_params(labels, 'Labels'),
283
+ },
284
+ }
285
+ end
286
+
287
+ def build_filter_params(filter_params)
288
+ {
289
+ 'labels' => parse_params(filter_params, 'Filtering parameters'),
290
+ }
291
+ end
292
+
293
+ def parse_params(params, params_type)
294
+ validate_params(params, params_type)
295
+ params.split(' ').reduce({}) do |acc, param|
296
+ stringified_keys, value = param.split('=', 2)
297
+ keys = stringified_keys.split('.', -1)
298
+ inner_pair = { keys.pop => value }
299
+ prepared_param = keys.reverse.reduce(inner_pair) { |res, key| { key => res } }
300
+ merge_params(acc, prepared_param)
301
+ end
302
+ end
303
+
304
+ def validate_params(params, params_type)
305
+ params.split(' ').each do |param|
306
+ stringified_keys, value = param.split('=', 2)
307
+ raise Uffizzi::Error.new("#{params_type} were set in incorrect format.") if value.nil? || stringified_keys.nil? || value.empty?
308
+
309
+ keys = stringified_keys.split('.', -1)
310
+ raise Uffizzi::Error.new("#{params_type} were set in incorrect format.") if keys.empty? || keys.any?(&:empty?)
311
+ end
312
+ end
313
+
314
+ def merge_params(result, param)
315
+ key = param.keys.first
316
+ return result.merge(param) unless result.has_key?(key)
317
+
318
+ { key => result[key].merge(merge_params(result[key], param[key])) }
319
+ end
259
320
  end
260
321
  end
@@ -147,8 +147,8 @@ module ApiClient
147
147
  build_response(response)
148
148
  end
149
149
 
150
- def fetch_deployments(server, project_slug)
151
- uri = deployments_uri(server, project_slug)
150
+ def fetch_deployments(server, project_slug, filter)
151
+ uri = deployments_uri(server, project_slug, filter)
152
152
  response = http_client.make_get_request(uri)
153
153
 
154
154
  build_response(response)
@@ -32,8 +32,10 @@ module ApiRoutes
32
32
  "#{compose_files_uri(server, project_slug)}/validate"
33
33
  end
34
34
 
35
- def deployments_uri(server, project_slug)
36
- "#{server}/api/cli/v1/projects/#{project_slug}/deployments"
35
+ def deployments_uri(server, project_slug, filter = nil)
36
+ return "#{server}/api/cli/v1/projects/#{project_slug}/deployments" if filter.nil?
37
+
38
+ "#{server}/api/cli/v1/projects/#{project_slug}/deployments?q=#{filter.to_json}"
37
39
  end
38
40
 
39
41
  def deployment_uri(server, project_slug, deployment_id)
@@ -50,13 +50,13 @@ module Uffizzi
50
50
  headers = { 'Content-Type' => 'application/json' }
51
51
  request = case method
52
52
  when :get
53
- Net::HTTP::Get.new(uri.path, headers)
53
+ Net::HTTP::Get.new(uri.request_uri, headers)
54
54
  when :post
55
- Net::HTTP::Post.new(uri.path, headers)
55
+ Net::HTTP::Post.new(uri.request_uri, headers)
56
56
  when :delete
57
- Net::HTTP::Delete.new(uri.path, headers)
57
+ Net::HTTP::Delete.new(uri.request_uri, headers)
58
58
  when :put
59
- Net::HTTP::Put.new(uri.path, headers)
59
+ Net::HTTP::Put.new(uri.request_uri, headers)
60
60
  end
61
61
  if request.instance_of?(Net::HTTP::Post) || request.instance_of?(Net::HTTP::Put)
62
62
  request.body = params.to_json
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uffizzi
4
- VERSION = '0.12.0'
4
+ VERSION = '0.14.0'
5
5
  end
@@ -1,6 +1,6 @@
1
1
  .\" generated with Ronn-NG/v0.9.1
2
2
  .\" http://github.com/apjanke/ronn-ng/tree/0.9.1
3
- .TH "UFFIZZI\-PREVIEW\-CREATE" "" "May 2022" ""
3
+ .TH "UFFIZZI\-PREVIEW\-CREATE" "" "August 2022" ""
4
4
  .SH "NAME"
5
5
  \fBuffizzi\-preview\-create\fR \- create a preview
6
6
  .SH "SYNOPSIS"
@@ -32,6 +32,12 @@ https://github\.com/UffizziCloud/uffizzi_cli
32
32
  the previews they create: when the preview is deleted, the
33
33
  alternate compose is deleted by the Uffizzi API\.
34
34
  .fi
35
+ .SH "FLAGS"
36
+ .nf
37
+ \-\-set\-labels=METADATA
38
+ Metadata of deployment that contains any information which can
39
+ be usefull for filtering deployments\.
40
+ .fi
35
41
  .SH "UFFIZZI WIDE FLAGS"
36
42
  .nf
37
43
  These flags are available to all commands: \-\-project\. Run $ uffizzi
@@ -46,5 +52,14 @@ To create a preview with the project\'s default compose file, run:
46
52
  To create a preview with an alternate compose file, run:
47
53
 
48
54
  $ uffizzi preview create docker\-compose\.uffizzi\.alt\.yml
55
+
56
+ To create a preview with single label, run:
57
+
58
+ $ uffizzi preview create \-\-set\-labels github\.repo=my_repo
59
+
60
+ To create a preview with multiple labels, run:
61
+
62
+ $ uffizzi preview create \e
63
+ \-\-set\-labels="github\.repo=my_repo github\.pull_request\.number=23"
49
64
  .fi
50
65
 
@@ -27,6 +27,11 @@ uffizzi-preview-create - create a preview
27
27
  the previews they create: when the preview is deleted, the
28
28
  alternate compose is deleted by the Uffizzi API.
29
29
 
30
+ ## FLAGS
31
+ --set-labels=METADATA
32
+ Metadata of deployment that contains any information which can
33
+ be usefull for filtering deployments.
34
+
30
35
  ## UFFIZZI WIDE FLAGS
31
36
  These flags are available to all commands: --project. Run $ uffizzi
32
37
  help for details.
@@ -39,3 +44,12 @@ uffizzi-preview-create - create a preview
39
44
  To create a preview with an alternate compose file, run:
40
45
 
41
46
  $ uffizzi preview create docker-compose.uffizzi.alt.yml
47
+
48
+ To create a preview with single label, run:
49
+
50
+ $ uffizzi preview create --set-labels github.repo=my_repo
51
+
52
+ To create a preview with multiple labels, run:
53
+
54
+ $ uffizzi preview create \
55
+ --set-labels="github.repo=my_repo github.pull_request.number=23"
@@ -1,6 +1,6 @@
1
1
  .\" generated with Ronn-NG/v0.9.1
2
2
  .\" http://github.com/apjanke/ronn-ng/tree/0.9.1
3
- .TH "UFFIZZI\-PREVIEW\-LIST" "" "May 2022" ""
3
+ .TH "UFFIZZI\-PREVIEW\-LIST" "" "August 2022" ""
4
4
  .SH "NAME"
5
5
  \fBuffizzi\-preview\-list\fR \- list previews in a project
6
6
  .SH "SYNOPSIS"
@@ -15,6 +15,15 @@ deploying and failed previews\.
15
15
  For more information on Uffizzi previews, see:
16
16
  https://github\.com/UffizziCloud/uffizzi_cli
17
17
  .fi
18
+ .SH "FLAGS"
19
+ .nf
20
+ \-\-filter=METADATA
21
+ Metadata to filtering list of deployments\.
22
+
23
+ \-\-output=json
24
+ Use this option for a more detailed description of listed
25
+ deployments\.
26
+ .fi
18
27
  .SH "UFFIZZI WIDE FLAGS"
19
28
  .nf
20
29
  These flags are available to all commands: \-\-project\. Run $ uffizzi
@@ -29,5 +38,20 @@ To list all previews in the default project, run:
29
38
  To list all previews in a project with name my_project, run:
30
39
 
31
40
  $ uffizzi preview list \-\-project="my_project"
41
+
42
+ To list all previews in json format, run:
43
+
44
+ $ uffizzi preview list \-\-output="json"
45
+
46
+ To list all previews filtered by metadata using single
47
+ label, run:
48
+
49
+ $ uffizzi preview list \-\-filter github\.repo=my_repo
50
+
51
+ To list all previews filtered by metadata using multiple
52
+ labels, run:
53
+
54
+ $ uffizzi preview list \e
55
+ \-\-filter="github\.repo=my_repo github\.pull_request\.number=23"
32
56
  .fi
33
57
 
@@ -11,6 +11,14 @@ uffizzi-preview-list - list previews in a project
11
11
  For more information on Uffizzi previews, see:
12
12
  https://github.com/UffizziCloud/uffizzi_cli
13
13
 
14
+ ## FLAGS
15
+ --filter=METADATA
16
+ Metadata to filtering list of deployments.
17
+
18
+ --output=json
19
+ Use this option for a more detailed description of listed
20
+ deployments.
21
+
14
22
  ## UFFIZZI WIDE FLAGS
15
23
  These flags are available to all commands: --project. Run $ uffizzi
16
24
  help for details.
@@ -23,3 +31,18 @@ uffizzi-preview-list - list previews in a project
23
31
  To list all previews in a project with name my_project, run:
24
32
 
25
33
  $ uffizzi preview list --project="my_project"
34
+
35
+ To list all previews in json format, run:
36
+
37
+ $ uffizzi preview list --output="json"
38
+
39
+ To list all previews filtered by metadata using single
40
+ label, run:
41
+
42
+ $ uffizzi preview list --filter github.repo=my_repo
43
+
44
+ To list all previews filtered by metadata using multiple
45
+ labels, run:
46
+
47
+ $ uffizzi preview list \
48
+ --filter="github.repo=my_repo github.pull_request.number=23"
@@ -1,8 +1,8 @@
1
1
  .\" generated with Ronn-NG/v0.9.1
2
2
  .\" http://github.com/apjanke/ronn-ng/tree/0.9.1
3
- .TH "UPDATE" "" "May 2022" ""
3
+ .TH "UPDATE" "" "August 2022" ""
4
4
  .SH "NAME"
5
- \fBuffizzi preview update\fR \- update a preview
5
+ \fBupdate\fR \- update a preview
6
6
  .SH "SYNOPSIS"
7
7
  .nf
8
8
  uffizzi preview update [PREVIEW_ID] [COMPOSE_FILE] [UFFIZZI_WIDE_FLAG \|\.\|\.\|\.]
@@ -27,6 +27,12 @@ https://github\.com/UffizziCloud/uffizzi_cli
27
27
  [COMPOSE_FILE]
28
28
  The new compose file you want to preview\.
29
29
  .fi
30
+ .SH "FLAGS"
31
+ .nf
32
+ \-\-set\-labels=METADATA
33
+ Metadata of deployment that contains any information which can
34
+ be usefull for filtering deployments\.
35
+ .fi
30
36
  .SH "UFFIZZI WIDE FLAGS"
31
37
  .nf
32
38
  These flags are available to all commands: \-\-project\. Run $ uffizzi
@@ -38,5 +44,17 @@ The following command updates a preview with ID deployment\-67 using
38
44
  compose file docker\-compose\.alt\.yml:
39
45
 
40
46
  $ uffizzi preview update deployment\-67 docker\-compose\.alt\.yml
47
+
48
+ To update a preview with single label, run:
49
+
50
+ $ uffizzi preview update \e
51
+ deployment\-67 docker\-compose\.alt\.yml \e
52
+ \-\-set\-labels github\.repo=my_repo
53
+
54
+ To update a preview with multiple labels, run:
55
+
56
+ $ uffizzi preview update \e
57
+ deployment\-67 docker\-compose\.alt\.yml \e
58
+ \-\-set\-labels="github\.repo=my_repo github\.pull_request\.number=23"
41
59
  .fi
42
60
 
@@ -22,6 +22,11 @@ uffizzi preview update - update a preview
22
22
  [COMPOSE_FILE]
23
23
  The new compose file you want to preview.
24
24
 
25
+ ## FLAGS
26
+ --set-labels=METADATA
27
+ Metadata of deployment that contains any information which can
28
+ be usefull for filtering deployments.
29
+
25
30
  ## UFFIZZI WIDE FLAGS
26
31
  These flags are available to all commands: --project. Run $ uffizzi
27
32
  help for details.
@@ -31,3 +36,15 @@ uffizzi preview update - update a preview
31
36
  compose file docker-compose.alt.yml:
32
37
 
33
38
  $ uffizzi preview update deployment-67 docker-compose.alt.yml
39
+
40
+ To update a preview with single label, run:
41
+
42
+ $ uffizzi preview update \
43
+ deployment-67 docker-compose.alt.yml \
44
+ --set-labels github.repo=my_repo
45
+
46
+ To update a preview with multiple labels, run:
47
+
48
+ $ uffizzi preview update \
49
+ deployment-67 docker-compose.alt.yml \
50
+ --set-labels="github.repo=my_repo github.pull_request.number=23"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uffizzi-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.14.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Thurman
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-08-08 00:00:00.000000000 Z
12
+ date: 2022-08-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: awesome_print