Class: UffizziCore::Api::Cli::V1::Accounts::CredentialsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/uffizzi_core/api/cli/v1/accounts/credentials_controller.rb

Instance Method Summary collapse

Instance Method Details

#check_credentialObject

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. = 
  if credential_form.valid?
    respond_with credential_form
  else
    respond_with credential_form.errors, status: :unprocessable_entity
  end
end

#createObject

Create account credential

Examples:

Possible types:
UffizziCore::Credential::Amazon, UffizziCore::Credential::Azure, UffizziCore::Credential::DockerHub,
UffizziCore::Credential::DockerRegistry, UffizziCore::Credential::Google, UffizziCore::Credential::GithubContainerRegistry


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. = 
  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

#destroyObject

Delete account credential



93
94
95
96
# File 'app/controllers/uffizzi_core/api/cli/v1/accounts/credentials_controller.rb', line 93

def destroy
  credential = .credentials.find_by!(type: params[:type])
  credential.destroy
end

#indexObject

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 = .credentials.pluck(:type)

  render json: { credentials: credentials }, status: :ok
end

#updateObject

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 = .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