Sha256: 5e7e51559f3f67876d6a3a1030e647e453bd8e87d55e920e79e4f0a97dbc290a

Contents?: true

Size: 1.41 KB

Versions: 3

Compression:

Stored size: 1.41 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 '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_container_registry]
                        else
                          raise Uffizzi::Error.new('Unsupported credential type.')
      end

      response = delete_credential(ConfigFile.read_option(:hostname), connection_type)

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

    private

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
uffizzi-cli-0.5.2 lib/uffizzi/cli/disconnect.rb
uffizzi-cli-0.5.1 lib/uffizzi/cli/disconnect.rb
uffizzi-cli-0.5.0 lib/uffizzi/cli/disconnect.rb