Sha256: 5956b6e04871062459b2e8a401c38c55c793a4c8a83ec9643bec503c3b5e3d1c

Contents?: true

Size: 703 Bytes

Versions: 2

Compression:

Stored size: 703 Bytes

Contents

module Peekj
  class Credentials
    KEYS = %w[app_url username api_token]

    class << self
      KEYS.each do |credential_key|
        define_method :"#{credential_key}" do
          keychain_password(credential_key)
        end


        define_method :"#{credential_key}=" do |credential_value|
          add_or_update_keychain_password(credential_key, credential_value)
        end
      end

      private

      def add_or_update_keychain_password(key, password)
        system "security add-generic-password -U -a 'peekj' -s '#{key}' -w '#{password}'"
      end

      def keychain_password(key)
        `security find-generic-password -a 'peekj' -s #{key} -w`.chomp
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
peekj-0.1.1 lib/peekj/credentials.rb
peekj-0.1.0 lib/peekj/credentials.rb