hibernate 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb37df3a1d0e0b64ae191626bfe015bca529ff81582816dea8a9198acc388f0b
4
- data.tar.gz: 60eb78bd95762490b910a6dc949c666126c4e72fbd0822c5103b197642de8fbb
3
+ metadata.gz: 13ffe5bd9a5a78875bccaa274cc525629110332a84ce88c97928549b5857698c
4
+ data.tar.gz: 2543e29eb63533e946de460b89749c7853bcb419bafde2bbcd0b4b61cdc1cf6c
5
5
  SHA512:
6
- metadata.gz: 3111686232c5dc02bb56a7c9f3b59ed0d9fc90a3ac1f986b32038cbbc41abeb62840228712e10ada6d7920082f1201aaa52b8cc88fbb4a33f53ec6ee843ed42a
7
- data.tar.gz: 7d0389381b47eaa7be1d3938219c770b10ed5cca756cb861f4aceca5567e5abb4c460cbc56d9cddab42d548dfb768976573301b359083d045c38c453831aca72
6
+ metadata.gz: 4c0db9fdb1c8ebbd341cdca34dd56db61a89b975ab8a815b34991a09bb9858c325ada48c8fa5708cf99244e6fb7b8aae9b0566fadb15fff1d9ea7be8d8143d03
7
+ data.tar.gz: 0307afb2b28ec2d44d7901d6e60cc3c63c0ed228015a8829690d3676922aeb6c28f90d197df680c8ca77b268941b890a0c0dbbd8989862b7fdb28a635d3b6559
data/bin/hibernate CHANGED
@@ -20,8 +20,8 @@ class HibernateCLI
20
20
  parser = OptionParser.new do |parser|
21
21
  parser.banner = "Usage: hibernate [command] [options]"
22
22
 
23
- parser.on('--account-id=<ACCOUNT_ID>', 'Specify the AWS account ID') do |account_id|
24
- ENV['AWS_ACCOUNT_ID'] = account_id
23
+ parser.on('--profile=<PROFILE_NAME>', 'Specify the profile name') do |profile|
24
+ ENV['AWS_PROFILE'] = profile
25
25
  end
26
26
 
27
27
  parser.on('--instance-name=<INSTANCE_NAME>', 'Specify the EC2 instance name') do |instance_name|
@@ -1,49 +1,31 @@
1
1
  require 'yaml'
2
- require 'fileutils'
3
2
 
4
3
  module Hibernate
5
4
  class ConfigLoader
6
- CACHE_FILE_PATH = File.expand_path('~/.aws_account_cache')
7
-
8
5
  def initialize(config_path = 'config.yaml')
9
6
  @config_path = config_path
10
- @account_id = fetch_account_id
11
7
  @config = load_config
8
+ @profile = ENV['AWS_PROFILE'] || default_profile
12
9
  validate_config
13
10
  end
14
11
 
15
12
  def aws_credentials
16
- account_config = @config.dig('aws_accounts', @account_id)
13
+ account_config = @config.dig('aws_accounts', @profile)
14
+
17
15
  if account_config.nil?
18
- raise "Account ID #{@account_id} not found in the configuration file."
16
+ raise "Profile #{@profile} not found in the configuration file."
19
17
  end
20
18
 
21
19
  {
22
- account_id: @account_id,
20
+ account_id: account_config['account_id'],
23
21
  region: account_config['region'],
24
22
  access_key_id: account_config.dig('credentials', 'access_key_id'),
25
23
  secret_access_key: account_config.dig('credentials', 'secret_access_key')
26
24
  }
27
25
  end
28
26
 
29
- def self.cache_account_id(account_id)
30
- FileUtils.mkdir_p(File.dirname(CACHE_FILE_PATH)) # Ensure directory exists
31
- File.write(CACHE_FILE_PATH, account_id)
32
- end
33
-
34
27
  private
35
28
 
36
- def fetch_account_id
37
- if ENV['AWS_ACCOUNT_ID']
38
- self.class.cache_account_id(ENV['AWS_ACCOUNT_ID'])
39
- ENV['AWS_ACCOUNT_ID']
40
- elsif File.exist?(CACHE_FILE_PATH)
41
- File.read(CACHE_FILE_PATH).strip
42
- else
43
- raise "AWS account ID is not set. Please pass an account ID using the --account-id option or set it in the configuration."
44
- end
45
- end
46
-
47
29
  def load_config
48
30
  if File.exist?(@config_path)
49
31
  YAML.load_file(@config_path)
@@ -53,14 +35,22 @@ module Hibernate
53
35
  end
54
36
 
55
37
  def validate_config
56
- unless @config.dig('aws_accounts', @account_id)
57
- raise "Please set the 'account_id' in the configuration file."
38
+ unless @config.dig('aws_accounts', @profile)
39
+ raise "Profile #{@profile} is not defined in the configuration file."
58
40
  end
59
41
 
60
- credentials = @config.dig('aws_accounts', @account_id, 'credentials')
42
+ credentials = @config.dig('aws_accounts', @profile, 'credentials')
61
43
  unless credentials && credentials['access_key_id'] && credentials['secret_access_key']
62
- raise "AWS credentials for account ID #{@account_id} are missing or incomplete."
44
+ raise "AWS credentials for profile #{@profile} are missing or incomplete."
45
+ end
46
+ end
47
+
48
+ def default_profile
49
+ default_accounts = @config['aws_accounts'].select { |_, account| account['default'] }
50
+ if default_accounts.empty?
51
+ raise "No default profile found in the configuration."
63
52
  end
53
+ default_accounts.keys.first
64
54
  end
65
55
  end
66
56
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hibernate
4
- VERSION = '0.1.4'
4
+ VERSION = '0.1.5'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hibernate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manish Sharma