Class: GitAuto::Config::CredentialStore

Inherits:
Object
  • Object
show all
Defined in:
lib/git_auto/config/credential_store.rb

Constant Summary collapse

CREDENTIALS_FILE =
File.join(File.expand_path("~/.git_auto"), "credentials.yml")
ENCRYPTION_KEY =
ENV["GIT_AUTO_SECRET"] || "default_development_key"

Instance Method Summary collapse

Constructor Details

#initializeCredentialStore

Returns a new instance of CredentialStore.



14
15
16
# File 'lib/git_auto/config/credential_store.rb', line 14

def initialize
  ensure_credentials_file
end

Instance Method Details

#api_key_exists?(provider) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
# File 'lib/git_auto/config/credential_store.rb', line 32

def api_key_exists?(provider)
  credentials = load_credentials
  credentials.key?(provider.to_s)
end

#get_api_key(provider) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/git_auto/config/credential_store.rb', line 24

def get_api_key(provider)
  credentials = load_credentials
  encrypted_key = credentials[provider.to_s]
  return nil unless encrypted_key

  decrypt(encrypted_key)
end

#store_api_key(key, provider) ⇒ Object



18
19
20
21
22
# File 'lib/git_auto/config/credential_store.rb', line 18

def store_api_key(key, provider)
  credentials = load_credentials
  credentials[provider.to_s] = encrypt(key)
  save_credentials(credentials)
end