Sha256: c2ade6211b298a49f925c4a1b641c504208c874f94951e5a25e261ef54ff93e8

Contents?: true

Size: 1.01 KB

Versions: 35

Compression:

Stored size: 1.01 KB

Contents

module Brightbox
  module Config
    module GpgEncryptedPasswords
      attr_accessor :gpg_password

      def gpg_encrypted_password_filename
        file_name = "#{client_name}.password.gpg"
        @gpg_encrypted_password_filename ||= File.join(config_directory, file_name)
      end

      # Return the password from gpg if it's possible
      def gpg_password
        if defined?(@gpg_password) && !@gpg_password.nil?
          return @gpg_password
        end
        if File.exist?(gpg_encrypted_password_filename)
          @gpg_password = gpg_decrypt_password
        else
          @gpg_password = nil
        end
      end

      private

      # Use gpg to decrypt the password
      def gpg_decrypt_password
        info "INFO: Decrypting #{gpg_encrypted_password_filename} to obtain password"
        begin
          IO::popen(["gpg", "--decrypt", gpg_encrypted_password_filename], "r") do |io|
            io.read.chomp
          end
        rescue Errno::ENOENT
          nil
        end
      end

    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
brightbox-cli-3.3.0 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-3.2.0 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-3.1.0 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-3.0.1 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-3.0.0 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-2.12.0 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-2.11.2 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-2.11.1 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-2.11.0 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-2.10.0 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-2.9.3 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-2.9.2 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-2.9.1 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-2.9.0 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-2.8.2 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-2.8.1 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-2.8.0 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-2.7.1 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-2.7.0 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-2.6.0 lib/brightbox-cli/config/gpg_encrypted_passwords.rb