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 +4 -4
- data/bin/hibernate +2 -2
- data/lib/hibernate/config_loader.rb +17 -27
- data/lib/hibernate/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13ffe5bd9a5a78875bccaa274cc525629110332a84ce88c97928549b5857698c
|
4
|
+
data.tar.gz: 2543e29eb63533e946de460b89749c7853bcb419bafde2bbcd0b4b61cdc1cf6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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('--
|
24
|
-
ENV['
|
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', @
|
13
|
+
account_config = @config.dig('aws_accounts', @profile)
|
14
|
+
|
17
15
|
if account_config.nil?
|
18
|
-
raise "
|
16
|
+
raise "Profile #{@profile} not found in the configuration file."
|
19
17
|
end
|
20
18
|
|
21
19
|
{
|
22
|
-
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', @
|
57
|
-
raise "
|
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', @
|
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
|
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
|
data/lib/hibernate/version.rb
CHANGED