Class: AWSTracker::AWSAccount

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/aws_tracker/models/aws_account.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#access_key_idObject

Credentials - these must be loaded from YAML or set programmatically



8
9
10
# File 'lib/aws_tracker/models/aws_account.rb', line 8

def access_key_id
  @access_key_id
end

#ec2Object

Returns a right_aws connection to EC2, creating it on demand



54
55
56
# File 'lib/aws_tracker/models/aws_account.rb', line 54

def ec2
  @ec2
end

#logObject

Configure logging



20
21
22
# File 'lib/aws_tracker/models/aws_account.rb', line 20

def log
  @log
end

#secret_access_keyObject

Credentials - these must be loaded from YAML or set programmatically



8
9
10
# File 'lib/aws_tracker/models/aws_account.rb', line 8

def secret_access_key
  @secret_access_key
end

Class Method Details

.from_memoryObject

Creates and returns an account based on the environment variables: AWS_ACCOUNT_NUMBER, AWS_ACCESS_KEY_ID, AWS_ACCESS_KEY_SECRET



63
64
65
66
67
68
69
70
# File 'lib/aws_tracker/models/aws_account.rb', line 63

def self.from_memory
   = ENV['AWS_ACCOUNT_NUMBER']
  AWSAccount.() do |acc|
    acc.name              = "M-R #{}"
    acc.access_key_id     = ENV['AWS_ACCESS_KEY_ID']
    acc.secret_access_key = ENV['AWS_ACCESS_KEY_SECRET']
  end
end

.from_yaml_file(yaml_file) ⇒ Object

Returns an Array of AWSAccount objects created from a YAML file



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/aws_tracker/models/aws_account.rb', line 73

def self.from_yaml_file(yaml_file)
   = YAML::load(File.open(yaml_file)).to_hash
  .map do |name, hash|
    AWSAccount.new({
      :name               => name,
      :account_id         => hash["account_id"],
      :access_key_id      => hash["access_key_id"],
      :secret_access_key  => hash["secret_access_key"],
    })
  end
end

Instance Method Details

#setup_default_loggerObject



22
23
24
# File 'lib/aws_tracker/models/aws_account.rb', line 22

def setup_default_logger
  @log ||= AWSTracker.default_logger
end

#update_ebs_volumesObject

Fetches EBS Volume data and saves to database



44
45
46
# File 'lib/aws_tracker/models/aws_account.rb', line 44

def update_ebs_volumes
  EBSVolume. self
end

#update_instancesObject

Fetches Instance data and saves to database



39
40
41
# File 'lib/aws_tracker/models/aws_account.rb', line 39

def update_instances
  Instance. self
end

#update_security_groupsObject

Fetches Security Group data and saves to database



34
35
36
# File 'lib/aws_tracker/models/aws_account.rb', line 34

def update_security_groups
  SecurityGroup. self
end

#update_statusObject



26
27
28
29
30
31
# File 'lib/aws_tracker/models/aws_account.rb', line 26

def update_status
  update_security_groups
  update_instances
  update_ebs_volumes
  update_tags
end

#update_tagsObject

Fetches Tags and saves to database



49
50
51
# File 'lib/aws_tracker/models/aws_account.rb', line 49

def update_tags
  Tag. self
end