Sha256: 40a9b03dec31ad7f42333b6868590de6cad83da6fd4e0317f9e6456fbb67303f

Contents?: true

Size: 998 Bytes

Versions: 3

Compression:

Stored size: 998 Bytes

Contents

require 'fog'

module Vcloud
  module Core
    module Fog
      module Login
        class << self
          def token(pass)
            check_plaintext_pass
            token = get_token(pass)

            return token
          end

          def token_export(*args)
            return "export #{Vcloud::Core::Fog::TOKEN_ENV_VAR_NAME}=#{token(*args)}"
          end

          private

          def check_plaintext_pass
            pass = Vcloud::Core::Fog::fog_credentials_pass
            unless pass.nil? || pass.empty?
              raise "Found plaintext #{Vcloud::Core::Fog::FOG_CREDS_PASS_NAME} entry. Please set it to an empty string"
            end
          end

          def get_token(pass)
            ENV.delete(Vcloud::Core::Fog::TOKEN_ENV_VAR_NAME)
            vcloud = ::Fog::Compute::VcloudDirector.new({
              Vcloud::Core::Fog::FOG_CREDS_PASS_NAME => pass,
            })

            return vcloud.vcloud_token
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vcloud-core-0.10.0 lib/vcloud/core/fog/login.rb
vcloud-core-0.9.0 lib/vcloud/core/fog/login.rb
vcloud-core-0.8.0 lib/vcloud/core/fog/login.rb