Class: ClusterFsck::CredentialGrabber

Inherits:
Object
  • Object
show all
Defined in:
lib/clusterfsck/credential_grabber.rb

Constant Summary collapse

FOG_PATH =
"~/.fog"
CF_PATH =
"~/.clusterfsck"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.findObject



7
8
9
# File 'lib/clusterfsck/credential_grabber.rb', line 7

def self.find
  new.find
end

Instance Method Details

#findObject



11
12
13
# File 'lib/clusterfsck/credential_grabber.rb', line 11

def find
  from_env_vars || from_cluster_fsck_config || from_fog_file
end

#from_cluster_fsck_configObject



36
37
38
39
40
41
42
43
44
# File 'lib/clusterfsck/credential_grabber.rb', line 36

def from_cluster_fsck_config
  if ClusterFsck.config_hash['aws_access_key_id'] &&
     ClusterFsck.config_hash['aws_secret_access_key']
    {
        access_key_id: ClusterFsck.config_hash['aws_access_key_id'],
        secret_access_key: ClusterFsck.config_hash['aws_secret_access_key'],
    }
  end
end

#from_env_varsObject



27
28
29
30
31
32
33
34
# File 'lib/clusterfsck/credential_grabber.rb', line 27

def from_env_vars
  if ENV['AWS_ACCESS_KEY_ID'] && ENV['AWS_SECRET_ACCESS_KEY']
    {
        access_key_id: ENV['AWS_ACCESS_KEY_ID'],
        secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
    }
  end
end

#from_fog_fileObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/clusterfsck/credential_grabber.rb', line 15

def from_fog_file
  if exists?(File.expand_path(FOG_PATH))
    fog_credentials = YAML.load_file(File.expand_path(FOG_PATH))
    {
        access_key_id: fog_credentials[:default][:aws_access_key_id],
        secret_access_key: fog_credentials[:default][:aws_secret_access_key],
    }
  end
rescue ArgumentError #when there is no HOME, File.expand_path above raises ArgumentError
  nil
end