Sha256: c67a0bcce4c3e4030c952b31e3c4b2d8fbc80a3d22271e2bb91572a31a6ad916

Contents?: true

Size: 1019 Bytes

Versions: 18

Compression:

Stored size: 1019 Bytes

Contents

module Brightbox
  module Config
    module GpgEncryptedPasswords
      attr_writer :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

        @gpg_password = if File.exist?(gpg_encrypted_password_filename)
                          gpg_decrypt_password
                        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

18 entries across 18 versions & 1 rubygems

Version Path
brightbox-cli-5.0.0 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-5.0.0.rc2 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-5.0.0.rc1 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-5.0.0.alpha lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-4.8.0 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-4.7.0 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-4.6.0 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-4.5.0 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-4.5.0.rc1 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-4.4.0 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-4.3.2 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-4.3.1 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-4.3.0 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-4.2.1 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-4.2.0 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-4.1.0 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-4.0.0 lib/brightbox-cli/config/gpg_encrypted_passwords.rb
brightbox-cli-4.0.0.rc2 lib/brightbox-cli/config/gpg_encrypted_passwords.rb