Class: UffizziCore::Api::Cli::V1::Accounts::CredentialsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- UffizziCore::Api::Cli::V1::Accounts::CredentialsController
- Defined in:
- app/controllers/uffizzi_core/api/cli/v1/accounts/credentials_controller.rb
Instance Method Summary collapse
-
#check_credential ⇒ Object
Check if credential of the type already exists in the account.
-
#create ⇒ Object
Create account credential.
-
#destroy ⇒ Object
Delete account credential.
-
#index ⇒ Object
Get a list of accounts credential.
-
#update ⇒ Object
Update existing credential of the given type.
Instance Method Details
#check_credential ⇒ Object
Check if credential of the type already exists in the account
74 75 76 77 78 79 80 81 82 83 |
# File 'app/controllers/uffizzi_core/api/cli/v1/accounts/credentials_controller.rb', line 74 def check_credential credential_form = UffizziCore::Api::Cli::V1::Account::Credential::CheckCredentialForm.new credential_form.type = params[:type] credential_form.account = resource_account if credential_form.valid? respond_with credential_form else respond_with credential_form.errors, status: :unprocessable_entity end end |
#create ⇒ Object
Create account credential
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/uffizzi_core/api/cli/v1/accounts/credentials_controller.rb', line 30 def create credential_form = UffizziCore::Api::Cli::V1::Account::Credential::CreateForm.new credential_form.assign_attributes(credential_params) credential_form.account = resource_account credential_form.registry_url = registry_url(credential_form) credential_form.username = '_json_key' if credential_form.google? credential_form.activate UffizziCore::Account::CreateCredentialJob.perform_async(credential_form.id) if credential_form.save respond_with credential_form end |
#destroy ⇒ Object
Delete account credential
93 94 95 96 |
# File 'app/controllers/uffizzi_core/api/cli/v1/accounts/credentials_controller.rb', line 93 def destroy credential = resource_account.credentials.find_by!(type: params[:type]) credential.destroy end |
#index ⇒ Object
Get a list of accounts credential
12 13 14 15 16 |
# File 'app/controllers/uffizzi_core/api/cli/v1/accounts/credentials_controller.rb', line 12 def index credentials = resource_account.credentials.pluck(:type) render json: { credentials: credentials }, status: :ok end |
#update ⇒ Object
Update existing credential of the given type
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/controllers/uffizzi_core/api/cli/v1/accounts/credentials_controller.rb', line 51 def update credential = resource_account.credentials.find_by!(type: params[:type]) # Called every pipeline run from CLI with the --update-if-exists-option return respond_with credential unless credential_changed?(credential, credential_params) credential_form = credential.becomes(UffizziCore::Api::Cli::V1::Account::Credential::UpdateForm) credential_form.assign_attributes(credential_params) if credential_form.save UffizziCore::Account::UpdateCredentialJob.perform_async(credential_form.id) respond_with credential_form else respond_with credential_form, status: :unprocessable_entity end end |