uffizzi_core 0.3.5 → 0.3.6

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: b888a8d1591e641bb45316b744f8c7b71352104761401b3388590edb75a1cfee
4
- data.tar.gz: efec514c14a589b68da1bb42fe28e7bbdf7569ab6bfc1b4ea22ba8b2b4f14b88
3
+ metadata.gz: 7022668d1f77cf69c6d793ec22992f029947adad2ec8e735e6c319e632a7f745
4
+ data.tar.gz: 56bcce7234c9a6e8d194195624b621322d5aa18630dbd1c29ecb16987b6e9cc6
5
5
  SHA512:
6
- metadata.gz: 30dc824b604d9c770645a86853f96dd251826d1ddb0e4429b14697fc16a56e891854eac9ac20eeaea12f6aae76f9921ebb2e203517281585a6326eba93483b30
7
- data.tar.gz: c732982588d01d53a65cbb090acfd244b5b8c6c5dcf272ad80a3bc37e02797dcf2d5d06df252ffbc2b5e982ff1a165d1b44ba527d95fc38c411103eee41d265e
6
+ metadata.gz: e6ae611e6ec7dc0dd3f20fbc465ff03f7d2504a18e950145b8ef9925ccffff4f8477e1ecaf3f6ccfdc7150d848669e5a884b26bd2ddbfb904c5deeb377a8b96e
7
+ data.tar.gz: f4d09c156e135e44e56c79ae94d906e876767a330f7d09576b511637e8d8d264db104846b3cc3ca0a101ec2ca45dcaab68335a13e3c7e442bf5be21390b31f71
@@ -40,6 +40,27 @@ class UffizziCore::Api::Cli::V1::Account::CredentialsController < UffizziCore::A
40
40
  respond_with credential_form
41
41
  end
42
42
 
43
+ # Update existing credential of the given type
44
+ #
45
+ # @path [PUT] /api/cli/v1/account/credentials/{type}
46
+ #
47
+ # @parameter type(required,path) [string] Credential type
48
+ # @parameter credential(required,body) [object<type:string>]
49
+ # @response [object<id:integer, registry_url:string, username:string, password:string>] 200 OK
50
+ # @response [object<errors>] 422 Unprocessable entity
51
+ def update
52
+ credential = resource_account.credentials.find_by!(type: params[:type])
53
+ credential_form = credential.becomes(UffizziCore::Api::Cli::V1::Account::Credential::UpdateForm)
54
+ credential_form.assign_attributes(credential_params)
55
+
56
+ if credential_form.save
57
+ UffizziCore::Account::UpdateCredentialJob.perform_async(credential_form.id)
58
+ respond_with credential_form
59
+ else
60
+ respond_with credential_form, status: :unprocessable_entity
61
+ end
62
+ end
63
+
43
64
  # Check if credential of the type already exists in the account
44
65
  #
45
66
  # @path [GET] /api/cli/v1/account/credentials/{type}/check_credential
@@ -11,6 +11,6 @@ class UffizziCore::Api::Cli::V1::Account::Credential::CheckCredentialForm
11
11
  private
12
12
 
13
13
  def credential_exists?
14
- errors.add(:type, 'Credential of that type already exist.') if account.credentials.by_type(type).exists?
14
+ errors.add(:type, :exist) if account.credentials.by_type(type).exists?
15
15
  end
16
16
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::Api::Cli::V1::Account::Credential::UpdateForm < UffizziCore::Credential
4
+ include UffizziCore::ApplicationForm
5
+
6
+ permit :registry_url, :username, :password
7
+
8
+ validates :password, presence: { message: :password_blank }
9
+ validate :check_registry_url, if: -> { errors[:password].empty? }
10
+ validate :check_credential_correctness, if: -> { errors[:password].empty? }
11
+
12
+ private
13
+
14
+ def check_registry_url
15
+ errors.add(:registry_url, :invalid_scheme) if URI.parse(registry_url).scheme.nil?
16
+ end
17
+
18
+ def check_credential_correctness
19
+ errors.add(:username, :incorrect) unless UffizziCore::CredentialService.correct_credentials?(self)
20
+ end
21
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::Account::UpdateCredentialJob < UffizziCore::ApplicationJob
4
+ sidekiq_options queue: :accounts, retry: 5
5
+
6
+ def perform(id)
7
+ credential = UffizziCore::Credential.find(id)
8
+ UffizziCore::AccountService.update_credential(credential)
9
+ end
10
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ class UffizziCore::Deployment::UpdateCredentialJob < UffizziCore::ApplicationJob
4
+ sidekiq_options queue: :deployments, retry: Settings.controller.resource_update_retry_count
5
+
6
+ sidekiq_retry_in do |count, exception|
7
+ case exception
8
+ when UffizziCore::DeploymentNotFoundError
9
+ Rails.logger.info("DEPLOYMENT_PROCESS UpdateCredentialJob retry deployment_id=#{exception.deployment_id} count=#{count}")
10
+ Settings.controller.resource_update_retry_time
11
+ end
12
+ end
13
+
14
+ def perform(deployment_id, credential_id)
15
+ Rails.logger.info("DEPLOYMENT_PROCESS deployment_id=#{deployment_id} UpdateCredentialJob(cred_id:#{credential_id})")
16
+
17
+ deployment = UffizziCore::Deployment.find(deployment_id)
18
+ credential = UffizziCore::Credential.find(credential_id)
19
+
20
+ if deployment.disabled?
21
+ Rails.logger.info("DEPLOYMENT_PROCESS deployment_id=#{deployment.id} deployment was disabled. Stop updating credential")
22
+ return
23
+ end
24
+
25
+ unless UffizziCore::ControllerService.deployment_exists?(deployment)
26
+ raise UffizziCore::DeploymentNotFoundError,
27
+ deployment_id
28
+ end
29
+
30
+ UffizziCore::ControllerService.apply_credential(deployment, credential)
31
+ end
32
+ end
@@ -9,6 +9,10 @@ class UffizziCore::Api::Cli::V1::Account::CredentialsPolicy < UffizziCore::Appli
9
9
  context.user_access_module.admin_access_to_account?(context.user, context.account)
10
10
  end
11
11
 
12
+ def update?
13
+ context.user_access_module.admin_access_to_account?(context.user, context.account)
14
+ end
15
+
12
16
  def check_credential?
13
17
  context.user_access_module.admin_access_to_account?(context.user, context.account)
14
18
  end
@@ -9,5 +9,8 @@ module UffizziCore::DeploymentRepo
9
9
  }
10
10
  scope :with_amazon_repos, -> { includes(containers: [:repo]).where(containers: { repos: { type: UffizziCore::Repo::Amazon.name } }) }
11
11
  scope :existed, -> { where(state: [:active, :failed]) }
12
+ scope :active_for_credential_id, ->(credential_id) {
13
+ active.joins(project: :credentials).merge(UffizziCore::Project.active).where(credentials: { id: credential_id })
14
+ }
12
15
  end
13
16
  end
@@ -3,18 +3,20 @@
3
3
  class UffizziCore::AccountService
4
4
  class << self
5
5
  def create_credential(credential)
6
- credential.account.projects.active.each do |project|
7
- project.deployments.active.each do |deployment|
8
- UffizziCore::Deployment::CreateCredentialJob.perform_async(deployment.id, credential.id)
9
- end
6
+ UffizziCore::Deployment.active_for_credential_id(credential.id).pluck(:id).each do |deployment_id|
7
+ UffizziCore::Deployment::CreateCredentialJob.perform_async(deployment_id, credential.id)
8
+ end
9
+ end
10
+
11
+ def update_credential(credential)
12
+ UffizziCore::Deployment.active_for_credential_id(credential.id).pluck(:id).each do |deployment_id|
13
+ UffizziCore::Deployment::UpdateCredentialJob.perform_async(deployment_id, credential.id)
10
14
  end
11
15
  end
12
16
 
13
17
  def delete_credential(credential)
14
- credential.account.projects.active.each do |project|
15
- project.deployments.active.each do |deployment|
16
- UffizziCore::Deployment::DeleteCredentialJob.perform_async(deployment.id, credential.id)
17
- end
18
+ UffizziCore::Deployment.active_for_credential_id(credential.id).pluck(:id).each do |deployment_id|
19
+ UffizziCore::Deployment::DeleteCredentialJob.perform_async(deployment_id, credential.id)
18
20
  end
19
21
  end
20
22
  end
@@ -19,8 +19,7 @@ class UffizziCore::CredentialService
19
19
  end
20
20
 
21
21
  if credential.persisted? && credential.active? && !status
22
- Rails.logger.warn("broken credentials, credential_correct? credential_id=#{credential.id}")
23
- credential.unauthorize!
22
+ Rails.logger.warn("Wrong credential: credential_correct? credential_id=#{credential.id}")
24
23
  end
25
24
 
26
25
  status
data/config/routes.rb CHANGED
@@ -46,7 +46,7 @@ UffizziCore::Engine.routes.draw do
46
46
 
47
47
  resource :account, only: [] do
48
48
  scope module: :account do
49
- resources :credentials, only: ['index', 'create', 'destroy'], param: :type do
49
+ resources :credentials, only: ['index', 'create', 'update', 'destroy'], param: :type do
50
50
  member do
51
51
  get :check_credential
52
52
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UffizziCore
4
- VERSION = '0.3.5'
4
+ VERSION = '0.3.6'
5
5
  end
@@ -122,12 +122,12 @@
122
122
  "x-action": "create"
123
123
  }
124
124
  },
125
- "/api/cli/v1/account/credentials/{type}/check_credential": {
126
- "get": {
125
+ "/api/cli/v1/account/credentials/{type}": {
126
+ "put": {
127
127
  "tags": [
128
128
  "Account/Credential"
129
129
  ],
130
- "operationId": "Account/Credential-check_credential",
130
+ "operationId": "Account/Credential-update",
131
131
  "parameters": [
132
132
  {
133
133
  "name": "credential",
@@ -145,27 +145,48 @@
145
145
  },
146
146
  {
147
147
  "name": "type",
148
- "description": "Scope response to type",
148
+ "description": "Credential type",
149
149
  "required": true,
150
150
  "in": "path",
151
151
  "type": "string"
152
152
  }
153
153
  ],
154
154
  "responses": {
155
- "422": {
156
- "description": "Unprocessable entity"
157
- },
158
155
  "200": {
159
- "description": "OK"
156
+ "description": "OK",
157
+ "schema": {
158
+ "type": "object",
159
+ "properties": {
160
+ "id": {
161
+ "type": "integer"
162
+ },
163
+ "registry_url": {
164
+ "type": "string"
165
+ },
166
+ "username": {
167
+ "type": "string"
168
+ },
169
+ "password": {
170
+ "type": "string"
171
+ }
172
+ }
173
+ }
174
+ },
175
+ "422": {
176
+ "description": "Unprocessable entity",
177
+ "schema": {
178
+ "type": "object",
179
+ "additionalProperties": {
180
+ "type": "errors"
181
+ }
182
+ }
160
183
  }
161
184
  },
162
- "description": "Check if credential of the type already exists in the account",
163
- "summary": "Check if credential of the type already exists in the account",
185
+ "description": "Update existing credential of the given type",
186
+ "summary": "Update existing credential of the given type",
164
187
  "x-controller": "uffizzi_core/api/cli/v1/account/credentials",
165
- "x-action": "check_credential"
166
- }
167
- },
168
- "/api/cli/v1/account/credentials/{type}": {
188
+ "x-action": "update"
189
+ },
169
190
  "delete": {
170
191
  "tags": [
171
192
  "Account/Credential"
@@ -210,6 +231,49 @@
210
231
  "x-action": "destroy"
211
232
  }
212
233
  },
234
+ "/api/cli/v1/account/credentials/{type}/check_credential": {
235
+ "get": {
236
+ "tags": [
237
+ "Account/Credential"
238
+ ],
239
+ "operationId": "Account/Credential-check_credential",
240
+ "parameters": [
241
+ {
242
+ "name": "credential",
243
+ "description": "credential",
244
+ "required": true,
245
+ "in": "body",
246
+ "schema": {
247
+ "type": "object",
248
+ "properties": {
249
+ "type": {
250
+ "type": "string"
251
+ }
252
+ }
253
+ }
254
+ },
255
+ {
256
+ "name": "type",
257
+ "description": "Scope response to type",
258
+ "required": true,
259
+ "in": "path",
260
+ "type": "string"
261
+ }
262
+ ],
263
+ "responses": {
264
+ "422": {
265
+ "description": "Unprocessable entity"
266
+ },
267
+ "200": {
268
+ "description": "OK"
269
+ }
270
+ },
271
+ "description": "Check if credential of the type already exists in the account",
272
+ "summary": "Check if credential of the type already exists in the account",
273
+ "x-controller": "uffizzi_core/api/cli/v1/account/credentials",
274
+ "x-action": "check_credential"
275
+ }
276
+ },
213
277
  "/api/cli/v1/projects/{project_slug}/compose_file": {
214
278
  "get": {
215
279
  "tags": [
@@ -1237,8 +1301,16 @@
1237
1301
  }
1238
1302
  ],
1239
1303
  "responses": {
1240
- "204": {
1241
- "description": "No content"
1304
+ "200": {
1305
+ "description": "OK",
1306
+ "schema": {
1307
+ "type": "object",
1308
+ "properties": {
1309
+ "project": {
1310
+ "$ref": "#/definitions/Project"
1311
+ }
1312
+ }
1313
+ }
1242
1314
  },
1243
1315
  "404": {
1244
1316
  "description": "Not Found"
@@ -1267,16 +1339,8 @@
1267
1339
  }
1268
1340
  ],
1269
1341
  "responses": {
1270
- "200": {
1271
- "description": "OK",
1272
- "schema": {
1273
- "type": "object",
1274
- "properties": {
1275
- "project": {
1276
- "$ref": "#/definitions/Project"
1277
- }
1278
- }
1279
- }
1342
+ "204": {
1343
+ "description": "No content"
1280
1344
  },
1281
1345
  "404": {
1282
1346
  "description": "Not Found"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uffizzi_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Thurman
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-07-25 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: aasm
@@ -729,6 +729,7 @@ files:
729
729
  - app/errors/uffizzi_core/deployment_not_found_error.rb
730
730
  - app/forms/uffizzi_core/api/cli/v1/account/credential/check_credential_form.rb
731
731
  - app/forms/uffizzi_core/api/cli/v1/account/credential/create_form.rb
732
+ - app/forms/uffizzi_core/api/cli/v1/account/credential/update_form.rb
732
733
  - app/forms/uffizzi_core/api/cli/v1/compose_file/check_credentials_form.rb
733
734
  - app/forms/uffizzi_core/api/cli/v1/compose_file/cli_form.rb
734
735
  - app/forms/uffizzi_core/api/cli/v1/compose_file/create_form.rb
@@ -747,6 +748,7 @@ files:
747
748
  - app/forms/uffizzi_core/mass_assignment_control_concern.rb
748
749
  - app/helpers/uffizzi_core/application_helper.rb
749
750
  - app/jobs/uffizzi_core/account/create_credential_job.rb
751
+ - app/jobs/uffizzi_core/account/update_credential_job.rb
750
752
  - app/jobs/uffizzi_core/activity_item/docker/update_digest_job.rb
751
753
  - app/jobs/uffizzi_core/application_job.rb
752
754
  - app/jobs/uffizzi_core/config_file/apply_job.rb
@@ -759,6 +761,7 @@ files:
759
761
  - app/jobs/uffizzi_core/deployment/delete_job.rb
760
762
  - app/jobs/uffizzi_core/deployment/deploy_containers_job.rb
761
763
  - app/jobs/uffizzi_core/deployment/manage_deploy_activity_item_job.rb
764
+ - app/jobs/uffizzi_core/deployment/update_credential_job.rb
762
765
  - app/lib/uffizzi_core/concerns/models/account.rb
763
766
  - app/lib/uffizzi_core/concerns/models/activity_item.rb
764
767
  - app/lib/uffizzi_core/concerns/models/build.rb