Class: AWSTracker::AWSAccount
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- AWSTracker::AWSAccount
- Defined in:
- lib/aws_tracker/models/aws_account.rb
Instance Attribute Summary collapse
-
#access_key_id ⇒ Object
Credentials - these must be loaded from YAML or set programmatically.
-
#ec2 ⇒ Object
Returns a right_aws connection to EC2, creating it on demand.
-
#log ⇒ Object
Configure logging.
-
#secret_access_key ⇒ Object
Credentials - these must be loaded from YAML or set programmatically.
Class Method Summary collapse
-
.from_memory ⇒ Object
Creates and returns an account based on the environment variables: AWS_ACCOUNT_NUMBER, AWS_ACCESS_KEY_ID, AWS_ACCESS_KEY_SECRET.
-
.from_yaml_file(yaml_file) ⇒ Object
Returns an Array of AWSAccount objects created from a YAML file.
Instance Method Summary collapse
- #setup_default_logger ⇒ Object
-
#update_ebs_volumes ⇒ Object
Fetches EBS Volume data and saves to database.
-
#update_instances ⇒ Object
Fetches Instance data and saves to database.
-
#update_security_groups ⇒ Object
Fetches Security Group data and saves to database.
- #update_status ⇒ Object
-
#update_tags ⇒ Object
Fetches Tags and saves to database.
Instance Attribute Details
#access_key_id ⇒ Object
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 |
#ec2 ⇒ Object
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 |
#log ⇒ Object
Configure logging
20 21 22 |
# File 'lib/aws_tracker/models/aws_account.rb', line 20 def log @log end |
#secret_access_key ⇒ Object
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_memory ⇒ Object
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 account_id = ENV['AWS_ACCOUNT_NUMBER'] AWSAccount.find_or_initialize_by_account_id(account_id) do |acc| acc.name = "M-R #{account_id}" 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) account_hash = YAML::load(File.open(yaml_file)).to_hash account_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_logger ⇒ Object
22 23 24 |
# File 'lib/aws_tracker/models/aws_account.rb', line 22 def setup_default_logger @log ||= AWSTracker.default_logger end |
#update_ebs_volumes ⇒ Object
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.refresh_from_account self end |
#update_instances ⇒ Object
Fetches Instance data and saves to database
39 40 41 |
# File 'lib/aws_tracker/models/aws_account.rb', line 39 def update_instances Instance.refresh_from_account self end |
#update_security_groups ⇒ Object
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.refresh_from_account self end |
#update_status ⇒ Object
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 end |
#update_tags ⇒ Object
Fetches Tags and saves to database
49 50 51 |
# File 'lib/aws_tracker/models/aws_account.rb', line 49 def Tag.refresh_from_account self end |