Sha256: 14d9352d2c2b7e65004eaeecd594e5e1fa099deaa6697221fbbdf5130fe9f514

Contents?: true

Size: 1.6 KB

Versions: 6

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true

require 'uffizzi'

module Uffizzi
  class Cli::Disconnect
    include ApiClient

    def run(credential_type)
      connection_type = case credential_type
                        when 'docker-hub'
                          Uffizzi.configuration.credential_types[:dockerhub]
                        when 'docker-registry'
                          Uffizzi.configuration.credential_types[:docker_registry]
                        when 'acr'
                          Uffizzi.configuration.credential_types[:azure]
                        when 'ecr'
                          Uffizzi.configuration.credential_types[:amazon]
                        when 'gcr'
                          Uffizzi.configuration.credential_types[:google]
                        when 'ghcr'
                          Uffizzi.configuration.credential_types[:github_registry]
                        else
                          raise Uffizzi::Error.new('Unsupported credential type.')
      end

      response = delete_credential(ConfigFile.read_option(:server), ConfigFile.read_option(:account_id), connection_type)

      if ResponseHelper.no_content?(response)
        Uffizzi.ui.say("Successfully disconnected from #{connection_name(credential_type)}.")
      else
        ResponseHelper.handle_failed_response(response)
      end
    end

    private

    def connection_name(credential_type)
      {
        'docker-hub' => 'DockerHub',
        'docker-registry' => 'Docker Registry',
        'acr' => 'ACR',
        'ecr' => 'ECR',
        'gcr' => 'GCR',
        'ghcr' => 'GHCR',
      }[credential_type]
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
uffizzi-cli-1.0.5 lib/uffizzi/cli/disconnect.rb
uffizzi-cli-1.0.4 lib/uffizzi/cli/disconnect.rb
uffizzi-cli-1.0.3 lib/uffizzi/cli/disconnect.rb
uffizzi-cli-1.0.2 lib/uffizzi/cli/disconnect.rb
uffizzi-cli-1.0.1 lib/uffizzi/cli/disconnect.rb
uffizzi-cli-1.0.0 lib/uffizzi/cli/disconnect.rb