uffizzi-cli 0.11.4 → 0.11.5

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: e92bf221528510c670cb020826d6449a4c200dcdacb6b6c42cea9344f1aac12b
4
- data.tar.gz: d95b2e8069051b7450d099add663104da159756913ca977d303f673805d8d0cb
3
+ metadata.gz: a81fa2bb6f00491f6c59e4c10ea3ce067da1b75b26ff8543e1a08558893058c0
4
+ data.tar.gz: fec82e0d04c499515f0221740a1a40b51bd5593a35223c0a7723648f20b25a5e
5
5
  SHA512:
6
- metadata.gz: a3da65fe42dd24ddca4c3c5fb7b15349e1daeef00689c421b0556d1d58eb34169de7c8bb4474ff1594fc5e526a1a5d8bd89124b649fb2606f10172440236613d
7
- data.tar.gz: f68cba8bbbf8591dfb5310606f7322b312171d1110587fd80969453fccaa82d2f31aab560731d962122e82524f7a4ac20283e5f2d2b8965b0e027bae370e3746
6
+ metadata.gz: 82610a6fe745521646e7d7e7c5e0f65a39263ea53987f1e431d0a0d0b69033d015a67bcd48b07e30c5d044f2167c752f307525438ca232044e90c5b60eb0f602
7
+ data.tar.gz: 67d5b6c3947e01e72c3ec678b6b14a1ccc6b78583d34f46274cdfa1f7692c9632b98728f43bf1ab5e0b3e984313db98e536c5231ddb9d2a07cc8156b8334ca2e
@@ -20,24 +20,26 @@ module Uffizzi
20
20
  desc 'docker-hub', 'Connect to Docker Hub (hub.docker.com)'
21
21
  method_option :skip_raise_existence_error, type: :boolean, default: false,
22
22
  desc: 'Skip raising an error within check the credential'
23
+ method_option :update_credential_if_exists, type: :boolean, default: false
23
24
  def docker_hub
24
25
  type = Uffizzi.configuration.credential_types[:dockerhub]
25
- check_credential_existence(type, 'docker-hub')
26
+ credential_exists = credential_exists?(type)
27
+ handle_existing_credential_options('docker-hub') if credential_exists
26
28
 
27
- username = ENV['DOCKERHUB_USERNAME'] || Uffizzi.ui.ask('Username: ')
28
- password = ENV['DOCKERHUB_PASSWORD'] || Uffizzi.ui.ask('Password: ', echo: false)
29
+ username = ENV['DOCKERHUB_USERNAME'] || Uffizzi.ui.ask('Username:')
30
+ password = ENV['DOCKERHUB_PASSWORD'] || Uffizzi.ui.ask('Password:', echo: false)
29
31
 
30
32
  params = {
31
33
  username: username,
32
34
  password: password,
33
- type: Uffizzi.configuration.credential_types[:dockerhub],
35
+ type: type,
34
36
  }
35
37
 
36
38
  server = ConfigFile.read_option(:server)
37
- response = create_credential(server, params)
39
+ response = create_or_update_credential(server, params, create: !credential_exists)
38
40
 
39
- if ResponseHelper.created?(response)
40
- print_success_message('DockerHub')
41
+ if successful?(response)
42
+ print_success_message('Docker Hub')
41
43
  else
42
44
  ResponseHelper.handle_failed_response(response)
43
45
  end
@@ -46,13 +48,15 @@ module Uffizzi
46
48
  desc 'acr', 'Connect to Azure Container Registry (azurecr.io)'
47
49
  method_option :skip_raise_existence_error, type: :boolean, default: false,
48
50
  desc: 'Skip raising an error within check the credential'
51
+ method_option :update_credential_if_exists, type: :boolean, default: false
49
52
  def acr
50
53
  type = Uffizzi.configuration.credential_types[:azure]
51
- check_credential_existence(type, 'acr')
54
+ credential_exists = credential_exists?(type)
55
+ handle_existing_credential_options('acr') if credential_exists
52
56
 
53
- registry_url = ENV['ACR_REGISTRY_URL'] || Uffizzi.ui.ask('Registry Domain: ')
54
- username = ENV['ACR_USERNAME'] || Uffizzi.ui.ask('Docker ID: ')
55
- password = ENV['ACR_PASSWORD'] || Uffizzi.ui.ask('Password/Access Token: ', echo: false)
57
+ registry_url = ENV['ACR_REGISTRY_URL'] || Uffizzi.ui.ask('Registry Domain:')
58
+ username = ENV['ACR_USERNAME'] || Uffizzi.ui.ask('Docker ID:')
59
+ password = ENV['ACR_PASSWORD'] || Uffizzi.ui.ask('Password/Access Token:', echo: false)
56
60
 
57
61
  params = {
58
62
  username: username,
@@ -62,9 +66,9 @@ module Uffizzi
62
66
  }
63
67
 
64
68
  server = ConfigFile.read_option(:server)
65
- response = create_credential(server, params)
69
+ response = create_or_update_credential(server, params, create: !credential_exists)
66
70
 
67
- if ResponseHelper.created?(response)
71
+ if successful?(response)
68
72
  print_success_message('ACR')
69
73
  else
70
74
  ResponseHelper.handle_failed_response(response)
@@ -74,13 +78,15 @@ module Uffizzi
74
78
  desc 'ecr', 'Connect to Amazon Elastic Container Registry'
75
79
  method_option :skip_raise_existence_error, type: :boolean, default: false,
76
80
  desc: 'Skip raising an error within check the credential'
81
+ method_option :update_credential_if_exists, type: :boolean, default: false
77
82
  def ecr
78
83
  type = Uffizzi.configuration.credential_types[:amazon]
79
- check_credential_existence(type, 'ecr')
84
+ credential_exists = credential_exists?(type)
85
+ handle_existing_credential_options('ecr') if credential_exists
80
86
 
81
- registry_url = ENV['AWS_REGISTRY_URL'] || Uffizzi.ui.ask('Registry Domain: ')
82
- access_key = ENV['AWS_ACCESS_KEY_ID'] || Uffizzi.ui.ask('Access key ID: ')
83
- secret_access_key = ENV['AWS_SECRET_ACCESS_KEY'] || Uffizzi.ui.ask('Secret access key: ', echo: false)
87
+ registry_url = ENV['AWS_REGISTRY_URL'] || Uffizzi.ui.ask('Registry Domain:')
88
+ access_key = ENV['AWS_ACCESS_KEY_ID'] || Uffizzi.ui.ask('Access key ID:')
89
+ secret_access_key = ENV['AWS_SECRET_ACCESS_KEY'] || Uffizzi.ui.ask('Secret access key:', echo: false)
84
90
 
85
91
  params = {
86
92
  username: access_key,
@@ -90,9 +96,9 @@ module Uffizzi
90
96
  }
91
97
 
92
98
  server = ConfigFile.read_option(:server)
93
- response = create_credential(server, params)
99
+ response = create_or_update_credential(server, params, create: !credential_exists)
94
100
 
95
- if ResponseHelper.created?(response)
101
+ if successful?(response)
96
102
  print_success_message('ECR')
97
103
  else
98
104
  ResponseHelper.handle_failed_response(response)
@@ -102,9 +108,11 @@ module Uffizzi
102
108
  desc 'gcr', 'Connect to Google Container Registry (gcr.io)'
103
109
  method_option :skip_raise_existence_error, type: :boolean, default: false,
104
110
  desc: 'Skip raising an error within check the credential'
111
+ method_option :update_credential_if_exists, type: :boolean, default: false
105
112
  def gcr(credential_file_path = nil)
106
113
  type = Uffizzi.configuration.credential_types[:google]
107
- check_credential_existence(type, 'gcr')
114
+ credential_exists = credential_exists?(type)
115
+ handle_existing_credential_options('gcr') if credential_exists
108
116
 
109
117
  credential_content = google_service_account_content(credential_file_path)
110
118
 
@@ -114,9 +122,9 @@ module Uffizzi
114
122
  }
115
123
 
116
124
  server = ConfigFile.read_option(:server)
117
- response = create_credential(server, params)
125
+ response = create_or_update_credential(server, params, create: !credential_exists)
118
126
 
119
- if ResponseHelper.created?(response)
127
+ if successful?(response)
120
128
  print_success_message('GCR')
121
129
  else
122
130
  ResponseHelper.handle_failed_response(response)
@@ -126,11 +134,13 @@ module Uffizzi
126
134
  desc 'ghcr', 'Connect to GitHub Container Registry (ghcr.io)'
127
135
  method_option :skip_raise_existence_error, type: :boolean, default: false,
128
136
  desc: 'Skip raising an error within check the credential'
137
+ method_option :update_credential_if_exists, type: :boolean, default: false
129
138
  method_option :username, type: :string, aliases: :u
130
139
  method_option :token, type: :string, aliases: :t
131
140
  def ghcr
132
141
  type = Uffizzi.configuration.credential_types[:github_registry]
133
- check_credential_existence(type, 'ghcr')
142
+ credential_exists = credential_exists?(type)
143
+ handle_existing_credential_options('ghcr') if credential_exists
134
144
 
135
145
  username = options[:username] || ENV['GITHUB_USERNAME'] || Uffizzi.ui.ask('Github Username:')
136
146
  password = options[:token] || ENV['GITHUB_ACCESS_TOKEN'] || Uffizzi.ui.ask('Access Token:', echo: false)
@@ -142,9 +152,9 @@ module Uffizzi
142
152
  }
143
153
 
144
154
  server = ConfigFile.read_option(:server)
145
- response = create_credential(server, params)
155
+ response = create_or_update_credential(server, params, create: !credential_exists)
146
156
 
147
- if ResponseHelper.created?(response)
157
+ if successful?(response)
148
158
  print_success_message('GHCR')
149
159
  else
150
160
  ResponseHelper.handle_failed_response(response)
@@ -156,31 +166,46 @@ module Uffizzi
156
166
 
157
167
  private
158
168
 
169
+ def successful?(response)
170
+ ResponseHelper.created?(response) || ResponseHelper.ok?(response)
171
+ end
172
+
159
173
  def prepare_registry_url(registry_url)
160
174
  return registry_url if registry_url.match?(/^(?:http(s)?:\/\/)/)
161
175
 
162
176
  "https://#{registry_url}"
163
177
  end
164
178
 
165
- def print_success_message(connection_name)
166
- Uffizzi.ui.say("Successfully connected to #{connection_name}")
179
+ def print_success_message(credential_type_slug)
180
+ Uffizzi.ui.say("Successfully connected to #{credential_type_slug}.")
167
181
  end
168
182
 
169
- def check_credential_existence(type, connection_name)
183
+ def credential_exists?(type)
170
184
  server = ConfigFile.read_option(:server)
171
185
  response = check_credential(server, type)
172
- return if ResponseHelper.ok?(response)
186
+ !ResponseHelper.ok?(response)
187
+ end
188
+
189
+ def handle_existing_credential_options(credential_type_slug)
190
+ if options.update_credential_if_exists?
191
+ Uffizzi.ui.say('Updating existing credential.')
192
+ return
193
+ end
173
194
 
174
195
  if options.skip_raise_existence_error?
175
- Uffizzi.ui.say("Credentials of type #{connection_name} already exist for this account.")
196
+ Uffizzi.ui.say("Credential of type #{credential_type_slug} already exists for this account.")
176
197
  exit(true)
177
198
  else
178
- message = "Credentials of type #{connection_name} already exist for this account. " \
179
- "To remove them, run $ uffizzi disconnect #{connection_name}."
199
+ message = "Credential of type #{credential_type_slug} already exists for this account.\n" \
200
+ "To remove them, run uffizzi disconnect #{credential_type_slug}."
180
201
  raise Uffizzi::Error.new(message)
181
202
  end
182
203
  end
183
204
 
205
+ def create_or_update_credential(server, params, create: true)
206
+ create ? create_credential(server, params) : update_credential(server, params, params[:type])
207
+ end
208
+
184
209
  def handle_list_credentials_success(response)
185
210
  credentials = response[:body][:credentials]
186
211
  credentials.each do |credential|
@@ -204,7 +229,7 @@ module Uffizzi
204
229
  def google_service_account_content(credential_file_path = nil)
205
230
  return ENV['GCLOUD_SERVICE_KEY'] if ENV['GCLOUD_SERVICE_KEY']
206
231
 
207
- return Uffizzi.ui.say('Path to google service account key file wasn\'t specified.') if credential_file_path.nil?
232
+ raise Uffizzi::Error.new("Path to a google service account key file wasn't specified.") if credential_file_path.nil?
208
233
 
209
234
  begin
210
235
  credential_content = File.read(credential_file_path)
@@ -70,6 +70,13 @@ module ApiClient
70
70
  build_response(response)
71
71
  end
72
72
 
73
+ def update_credential(server, params, type)
74
+ uri = credential_uri(server, type)
75
+ response = http_client.make_put_request(uri, params)
76
+
77
+ build_response(response)
78
+ end
79
+
73
80
  def fetch_deployment_services(server, project_slug, deployment_id)
74
81
  uri = preview_services_uri(server, project_slug, deployment_id)
75
82
  response = http_client.make_get_request(uri)
@@ -78,7 +85,7 @@ module ApiClient
78
85
  end
79
86
 
80
87
  def delete_credential(server, credential_type)
81
- uri = delete_credential_uri(server, credential_type)
88
+ uri = credential_uri(server, credential_type)
82
89
  response = http_client.make_delete_request(uri)
83
90
 
84
91
  build_response(response)
@@ -64,7 +64,7 @@ module ApiRoutes
64
64
  "#{server}/api/cli/v1/projects/#{project_slug}/deployments/#{deployment_id}/containers"
65
65
  end
66
66
 
67
- def delete_credential_uri(server, credential_type)
67
+ def credential_uri(server, credential_type)
68
68
  "#{server}/api/cli/v1/account/credentials/#{credential_type}"
69
69
  end
70
70
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uffizzi
4
- VERSION = '0.11.4'
4
+ VERSION = '0.11.5'
5
5
  end
data/man/uffizzi-connect CHANGED
@@ -33,5 +33,11 @@ gcr
33
33
  ghcr
34
34
  Connect to GitHub Container Registry (ghcr\.io)\.
35
35
  .fi
36
+ .SH "FLAGS"
37
+ .nf
38
+ \-\-skip\-raise\-existence\-error If credential exist, do not raise an exception, just print a message
39
+
40
+ \-\-update\-credential\-if\-exists Update credential if it exists
41
+ .fi
36
42
  .P
37
43
  Run \'uffizzi connect COMMAND \-\-help\' for more information on a command\.
@@ -28,4 +28,10 @@ uffizzi-connect - grant a Uffizzi user account access to external services
28
28
  ghcr
29
29
  Connect to GitHub Container Registry (ghcr.io).
30
30
 
31
+
32
+ ## FLAGS
33
+ --skip-raise-existence-error If credential exist, do not raise an exception, just print a message
34
+
35
+ --update-credential-if-exists Update credential if it exists
36
+
31
37
  Run 'uffizzi connect COMMAND --help' for more information on a command.
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.11.4
4
+ version: 0.11.5
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-07-28 00:00:00.000000000 Z
12
+ date: 2022-08-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: awesome_print