awx 0.2.0 → 0.3.0
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/lib/aws/aws.rb +9 -0
- data/lib/aws/aws_cli.rb +36 -30
- data/lib/aws/aws_cloudformation.rb +59 -36
- data/lib/aws/aws_outputter.rb +33 -2
- data/lib/aws/aws_profile.rb +116 -0
- data/lib/aws/aws_reports.rb +47 -26
- data/lib/awx.rb +98 -45
- data/lib/core/opt.rb +1 -1
- data/lib/routes/aws_cloudformation_create.rb +447 -192
- data/lib/routes/aws_cloudformation_detect_drift.rb +33 -7
- data/lib/routes/aws_deploy.rb +486 -0
- data/lib/routes/aws_dynamo_db.rb +43 -0
- data/lib/routes/aws_list.rb +17 -11
- data/lib/routes/aws_switch.rb +76 -0
- data/lib/version.rb +1 -1
- data/opt/{yml/aws-reports.yml → awx/reports.yml} +15 -12
- data/opt/config/schema.yml +63 -0
- data/opt/config/template.yml +21 -0
- metadata +25 -23
- data/lib/aws/aws_config.rb +0 -39
- data/lib/core/config.rb +0 -127
- data/lib/core/config_unique.rb +0 -64
- data/lib/routes/aws_lambda.rb +0 -122
- data/lib/routes/setup.rb +0 -31
data/lib/aws/aws_config.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
module App
|
2
|
-
|
3
|
-
class AWSConfig
|
4
|
-
|
5
|
-
BLANK = '[BLANK]'
|
6
|
-
|
7
|
-
AWS_PROFILE_ALBERT_CLI = 'albert-cli'
|
8
|
-
|
9
|
-
FILE_AWS_CONFIG = File.expand_path('~/.aws/config')
|
10
|
-
FILE_AWS_CREDENTIALS = File.expand_path('~/.aws/credentials')
|
11
|
-
|
12
|
-
@@aws_credentials = BLANK
|
13
|
-
|
14
|
-
# Gets AWS credentials from ~/.aws directory for given profile.
|
15
|
-
# If credentials don't exist (or are missing information) -- nil is returned.
|
16
|
-
def self.get_credentials(profile = 'default')
|
17
|
-
if @@aws_credentials == BLANK
|
18
|
-
return nil unless Blufin::Files::file_exists(FILE_AWS_CONFIG)
|
19
|
-
return nil unless Blufin::Files::file_exists(FILE_AWS_CREDENTIALS)
|
20
|
-
config = ParseConfig.new(FILE_AWS_CONFIG)
|
21
|
-
credentials = ParseConfig.new(FILE_AWS_CREDENTIALS)
|
22
|
-
@@aws_credentials = nil
|
23
|
-
if !config.params[profile].nil? && !credentials.params[profile].nil?
|
24
|
-
if !config.params[profile]['region'].nil? && !config.params[profile]['output'].nil? && !credentials.params[profile]['aws_access_key_id'].nil? && !credentials.params[profile]['aws_secret_access_key'].nil?
|
25
|
-
aws_credentials = App::AWSCredentials.new
|
26
|
-
aws_credentials.region = config.params[profile]['region']
|
27
|
-
aws_credentials.output = config.params[profile]['output']
|
28
|
-
aws_credentials.aws_key = config.params[profile]['aws_access_key_id']
|
29
|
-
aws_credentials.aws_secret = config.params[profile]['aws_secret_access_key']
|
30
|
-
@@aws_credentials = aws_credentials
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
@@aws_credentials
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
data/lib/core/config.rb
DELETED
@@ -1,127 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
require 'parseconfig'
|
3
|
-
|
4
|
-
module App
|
5
|
-
|
6
|
-
class Config
|
7
|
-
|
8
|
-
@params = {}
|
9
|
-
|
10
|
-
extend ConfigUnique
|
11
|
-
include ConfigUnique
|
12
|
-
|
13
|
-
def self.initialize
|
14
|
-
if config_file_exists?
|
15
|
-
run_load_config
|
16
|
-
else
|
17
|
-
run_first_journey
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.config_file_exists?
|
22
|
-
unless File.exists? ("#{File.expand_path(CONFIG_FILE)}")
|
23
|
-
return false
|
24
|
-
end
|
25
|
-
true
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.run_load_config
|
29
|
-
config_params_get
|
30
|
-
config_params_validate
|
31
|
-
end
|
32
|
-
|
33
|
-
def self.run_first_journey
|
34
|
-
first_journey_message
|
35
|
-
config_file_create
|
36
|
-
config_file_edit
|
37
|
-
config_params_get
|
38
|
-
config_params_validate(true)
|
39
|
-
end
|
40
|
-
|
41
|
-
def self.first_journey_message
|
42
|
-
puts
|
43
|
-
puts "Thank you for installing the #{Blufin::Terminal::format_highlight("#{GEM_NAME}-cli")} ruby gem."
|
44
|
-
puts "CLI stands for 'Command Line Interface'."
|
45
|
-
puts
|
46
|
-
puts "The first thing you'll need to do is setup your configuration file."
|
47
|
-
puts "The file is located at: #{Blufin::Terminal::format_directory(ConfigUnique::CONFIG_FILE)}"
|
48
|
-
puts
|
49
|
-
puts "You probably won't have this file so the program will create it for you."
|
50
|
-
puts "\n"
|
51
|
-
unless Blufin::Terminal::prompt_yes_no('Create configuration file?')
|
52
|
-
Blufin::Terminal::abort
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def self.config_file_edit
|
57
|
-
system("nano #{File.expand_path(CONFIG_FILE)}")
|
58
|
-
end
|
59
|
-
|
60
|
-
def self.config_params_get
|
61
|
-
config = ParseConfig.new("#{File.expand_path(CONFIG_FILE)}")
|
62
|
-
config.get_params.each do |param|
|
63
|
-
@params[param] = config[param]
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def self.config_params_validate(show_success_message = false)
|
68
|
-
error_text = ''
|
69
|
-
missing_keys = get_missing_config_keys
|
70
|
-
if missing_keys.any?
|
71
|
-
missing_keys.each do |key|
|
72
|
-
error_text = "#{error_text}\x1B[38;5;196mKey/value must exist and cannot be null:\x1B[0m \x1B[38;5;240m#{key}\x1B[0m\n"
|
73
|
-
end
|
74
|
-
error_text = error_text[0..-2]
|
75
|
-
end
|
76
|
-
unless error_text == ''
|
77
|
-
show_error_message(error_text)
|
78
|
-
end
|
79
|
-
if show_success_message
|
80
|
-
Blufin::Terminal::success('Configuration parameters are correct.', "You are now ready to start using this utility.\nStart by typing #{Blufin::Terminal::format_command("#{GEM_NAME} --help")} (or #{Blufin::Terminal::format_command("#{GEM_NAME} -h")}).")
|
81
|
-
exit
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
def self.show_error_message(error_text)
|
86
|
-
Blufin::Terminal::error('Your configuration parameters are invalid.', "#{error_text}\n\nYou can fix this by running #{Blufin::Terminal::format_command("#{GEM_NAME} setup")} (or #{Blufin::Terminal::format_command("#{GEM_NAME} x")}).")
|
87
|
-
exit
|
88
|
-
end
|
89
|
-
|
90
|
-
def self.get_missing_config_keys
|
91
|
-
missing_keys = required_config_keys.dup
|
92
|
-
@params.each do |key, value|
|
93
|
-
unless value == ''
|
94
|
-
missing_keys.delete(key)
|
95
|
-
end
|
96
|
-
end
|
97
|
-
missing_keys
|
98
|
-
end
|
99
|
-
|
100
|
-
# Checks if a config parameter exists.
|
101
|
-
# @return boolean
|
102
|
-
def self.param_exists(param_name)
|
103
|
-
@params.has_key?(param_name)
|
104
|
-
end
|
105
|
-
|
106
|
-
# Get ALL config parameters.
|
107
|
-
# @return Hash
|
108
|
-
def self.params
|
109
|
-
@params
|
110
|
-
end
|
111
|
-
|
112
|
-
# Get custom keys from the config file (IE: ssh_ec2=user|host|pem)
|
113
|
-
# @return String
|
114
|
-
def self.get_custom_key(prefix, config_key)
|
115
|
-
if config_key.nil?
|
116
|
-
Blufin::Terminal::error("The script requires a config parameter from your #{Blufin::Terminal::format_directory(ConfigUnique::CONFIG_FILE)} file", "The key should have a prefix of: #{Blufin::Terminal::format_highlight(prefix)}", true)
|
117
|
-
end
|
118
|
-
config_param = (config_key =~ /\A#{prefix}\S+\z/i) ? config_key : "#{prefix}#{config_key}"
|
119
|
-
unless App::Config::param_exists(config_param)
|
120
|
-
Blufin::Terminal::error('Invalid config parameter', "Cannot find #{Blufin::Terminal::format_highlight('key')} #{Blufin::Terminal::format_invalid("\"#{config_param}\"")} in: #{Blufin::Terminal::format_directory(ConfigUnique::CONFIG_FILE)}", true)
|
121
|
-
end
|
122
|
-
App::Config.param(config_param)
|
123
|
-
end
|
124
|
-
|
125
|
-
end
|
126
|
-
|
127
|
-
end
|
data/lib/core/config_unique.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
module ConfigUnique
|
2
|
-
|
3
|
-
@params = {}
|
4
|
-
|
5
|
-
# USED BY CONFIG CLASS
|
6
|
-
CONFIG_FILE = '~/.awxrc'
|
7
|
-
GEM_NAME = 'awx'
|
8
|
-
|
9
|
-
# STORED PARAMETERS
|
10
|
-
PATH_TO_REPO_AWX = 'path_to_repo_awx'
|
11
|
-
PATH_TO_REPO_SECRETS = 'path_to_repo_secrets'
|
12
|
-
PATH_TO_LAMBDA_EWORLD = 'path_to_lambda_eworld'
|
13
|
-
|
14
|
-
def param(param_name)
|
15
|
-
|
16
|
-
raise RuntimeError, "Expected String, instead got:#{param_name.class}" unless param_name.is_a?(String)
|
17
|
-
|
18
|
-
unless [
|
19
|
-
PATH_TO_REPO_AWX,
|
20
|
-
PATH_TO_REPO_SECRETS,
|
21
|
-
PATH_TO_LAMBDA_EWORLD
|
22
|
-
].include?(param_name)
|
23
|
-
unless param_name =~ /^ssh_[a-z_]+$/
|
24
|
-
raise RuntimeError, "#{Blufin::Terminal::format_highlight(param_name)} is not a valid config parameter"
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
param_value = @params[param_name]
|
29
|
-
return nil if param_value.nil?
|
30
|
-
|
31
|
-
if [
|
32
|
-
PATH_TO_REPO_AWX,
|
33
|
-
PATH_TO_REPO_SECRETS,
|
34
|
-
PATH_TO_LAMBDA_EWORLD
|
35
|
-
].include?(param_name)
|
36
|
-
begin
|
37
|
-
return "/#{Blufin::Strings.remove_surrounding_slashes(File.expand_path(param_value))}"
|
38
|
-
rescue Exception => e
|
39
|
-
Blufin::Terminal::error("Something went wrong trying to get parameter: #{param_name}", e.message)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
param_value
|
44
|
-
end
|
45
|
-
|
46
|
-
def config_file_create
|
47
|
-
File.open("#{File.expand_path(CONFIG_FILE)}", 'w') { |file|
|
48
|
-
file.write("# CONFIGURATION FILE -- Make sure that ALL parameters are correct before saving.\n")
|
49
|
-
file.write("\n")
|
50
|
-
file.write("#{PATH_TO_REPO_AWX}=\n")
|
51
|
-
file.write("#{PATH_TO_REPO_SECRETS}=\n")
|
52
|
-
file.write("#{PATH_TO_LAMBDA_EWORLD}=\n")
|
53
|
-
}
|
54
|
-
end
|
55
|
-
|
56
|
-
def required_config_keys
|
57
|
-
[
|
58
|
-
PATH_TO_REPO_AWX,
|
59
|
-
PATH_TO_REPO_SECRETS,
|
60
|
-
PATH_TO_LAMBDA_EWORLD
|
61
|
-
]
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
data/lib/routes/aws_lambda.rb
DELETED
@@ -1,122 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
require 'uri'
|
3
|
-
|
4
|
-
module AppCommand
|
5
|
-
|
6
|
-
class AWSLambda < ::Convoy::ActionCommand::Base
|
7
|
-
|
8
|
-
VALID_METHODS = %w(GET POST PUT DELETE)
|
9
|
-
|
10
|
-
def execute
|
11
|
-
|
12
|
-
begin
|
13
|
-
|
14
|
-
@opts = command_options
|
15
|
-
@args = arguments
|
16
|
-
|
17
|
-
@project = @args[0]
|
18
|
-
@project_path = nil
|
19
|
-
@uri = @args[1]
|
20
|
-
@method = @args[2].nil? ? nil : @args[2].upcase
|
21
|
-
@file_payload = @opts[:payload_file]
|
22
|
-
@file_headers = @opts[:headers_file].nil? ? 'default' : @opts[:headers_file]
|
23
|
-
@headers = nil
|
24
|
-
@payload = nil
|
25
|
-
|
26
|
-
@valid_projects = {
|
27
|
-
'bb' => App::Config.param(ConfigUnique::PATH_TO_LAMBDA_BERT),
|
28
|
-
'ew' => App::Config.param(ConfigUnique::PATH_TO_LAMBDA_EWORLD)
|
29
|
-
}
|
30
|
-
|
31
|
-
opts_validate
|
32
|
-
opts_routing
|
33
|
-
|
34
|
-
rescue => e
|
35
|
-
|
36
|
-
Blufin::Terminal::print_exception(e)
|
37
|
-
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
def opts_validate
|
43
|
-
|
44
|
-
nil_errors = []
|
45
|
-
nil_errors << "#{Blufin::Terminal::format_highlight('1st')} parameter must be #{Blufin::Terminal::format_action('project')}. Valid projects are: #{@valid_projects.keys.join(', ')}" if @project.nil?
|
46
|
-
nil_errors << "#{Blufin::Terminal::format_highlight('2nd')} parameter must be #{Blufin::Terminal::format_action('uri')} aka: route to Lambda handler" if @uri.nil? || @uri.strip == ''
|
47
|
-
nil_errors << "#{Blufin::Terminal::format_highlight('3rd')} parameter must be #{Blufin::Terminal::format_action('method')}. Valid methods are: #{VALID_METHODS.join(', ')}" if @uri.nil? || @uri.strip == ''
|
48
|
-
|
49
|
-
# Catch NULL errors first.
|
50
|
-
Blufin::Terminal::error('Please fix the following errors:', nil_errors) if nil_errors.any?
|
51
|
-
|
52
|
-
# Validate project alias.
|
53
|
-
Blufin::Terminal::error("#{Blufin::Terminal::format_action('project')} #{Blufin::Terminal::format_highlight(@project.nil? || @project.strip == '' ? 'nil' : @project)} is invalid. Valid project(s) are:", @valid_projects.keys, true) unless @valid_projects.keys.include?(@project)
|
54
|
-
|
55
|
-
# Validate project path.
|
56
|
-
@project_path = @valid_projects[@project]
|
57
|
-
Blufin::Terminal::error("#{Blufin::Terminal::format_action('project path')} doesn't exist: #{Blufin::Terminal::format_directory(@project_path)}") unless Blufin::Files::path_exists(@project_path)
|
58
|
-
|
59
|
-
# Validate HTTP Method.
|
60
|
-
Blufin::Terminal::error("#{Blufin::Terminal::format_action('http')} method #{Blufin::Terminal::format_highlight(@method.nil? || @method.strip == '' ? 'nil' : @method)} is invalid. Valid methods are:", VALID_METHODS, true) unless VALID_METHODS.include?(@method)
|
61
|
-
|
62
|
-
# Validate headers file.
|
63
|
-
unless Blufin::Files::file_exists(@file_headers)
|
64
|
-
file_headers_alt = "#{@project_path}/json/headers/#{@file_headers.strip.gsub(/(\.json)$/i, '')}.json"
|
65
|
-
if Blufin::Files::file_exists(file_headers_alt)
|
66
|
-
@file_headers = file_headers_alt
|
67
|
-
h_buffer = ''
|
68
|
-
Blufin::Files::read_file(@file_headers).each { |line| h_buffer = "#{h_buffer}#{line.gsub("\n", '').strip}" }
|
69
|
-
begin
|
70
|
-
JSON.parse(h_buffer)
|
71
|
-
@headers = h_buffer
|
72
|
-
rescue => e
|
73
|
-
Blufin::Terminal::error("Failed to parse JSON from #{Blufin::Terminal::format_action('header file')}: #{Blufin::Terminal::format_directory(@file_headers)}", e.message)
|
74
|
-
end
|
75
|
-
else
|
76
|
-
Blufin::Terminal::error("Neither of the following #{Blufin::Terminal::format_action('headers files')} exist:", [@file_headers, file_headers_alt], true)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
# Validate payload file.
|
81
|
-
unless @file_payload.nil?
|
82
|
-
unless Blufin::Files::file_exists(@file_payload)
|
83
|
-
file_payload_alt = "#{@project_path}/json/payload/#{@file_payload.strip.gsub(/(\.json)$/i, '')}.json"
|
84
|
-
if Blufin::Files::file_exists(file_payload_alt)
|
85
|
-
@file_payload = file_payload_alt
|
86
|
-
p_buffer = ''
|
87
|
-
Blufin::Files::read_file(@file_payload).each { |line| p_buffer = "#{p_buffer}#{line.gsub("\n", '').strip}" }
|
88
|
-
begin
|
89
|
-
JSON.parse(p_buffer)
|
90
|
-
@payload = p_buffer
|
91
|
-
rescue => e
|
92
|
-
Blufin::Terminal::error("Failed to parse JSON from #{Blufin::Terminal::format_action('payload file')}: #{Blufin::Terminal::format_directory(@file_payload)}", e.message)
|
93
|
-
end
|
94
|
-
else
|
95
|
-
Blufin::Terminal::error("Neither of the following #{Blufin::Terminal::format_action('headers files')} exist:", [@file_payload, file_payload_alt], true)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
101
|
-
|
102
|
-
def opts_routing
|
103
|
-
|
104
|
-
headers = @headers.nil? ? nil : ",\"headers\":#{@headers}"
|
105
|
-
payload = @payload.nil? ? nil : ",\"body\":\"#{URI::encode(@payload)}\""
|
106
|
-
|
107
|
-
cmd = "sls invoke local -f main -d '{\"resource\":\"/#{@uri}\",\"path\":\"/#{@uri}\",\"httpMethod\":\"#{@method}\"#{headers}#{payload},\"pathParameters\":{\"hash\":\"cae695cfa2c33ad92ea17e1a03fba99cb9e734dbd4cc4eb8f143bf45e06e81a7rHhP4G070Rzke2O5Vg12A==\"}}'"
|
108
|
-
res = Blufin::Terminal::command_capture(cmd, @project_path, true, false)
|
109
|
-
|
110
|
-
begin
|
111
|
-
jsn = JSON.parse(res[0].strip.gsub(/\n$/, '').gsub('\"', '"').gsub('"{', '{').gsub('}"', '}'))
|
112
|
-
sts = jsn['statusCode'].to_i
|
113
|
-
Blufin::Terminal::custom('Lambda Response', 54, "Status: \x1B[38;5;#{sts == 200 ? 46 : 196}m#{sts}\x1B[0m", JSON.pretty_generate(jsn['body']).split("\n"), true)
|
114
|
-
rescue
|
115
|
-
Blufin::Terminal::custom('Lambda Response', 54, "Detected #{Blufin::Terminal::format_highlight('console.log()')} or unparseable output:", res[0].split("\n"), true)
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|
119
|
-
|
120
|
-
end
|
121
|
-
|
122
|
-
end
|
data/lib/routes/setup.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
module AppCommand
|
2
|
-
|
3
|
-
class Setup < ::Convoy::ActionCommand::Base
|
4
|
-
|
5
|
-
def execute
|
6
|
-
|
7
|
-
begin
|
8
|
-
|
9
|
-
if File.exists?(File.expand_path(App::Config::CONFIG_FILE))
|
10
|
-
|
11
|
-
App::Config::config_file_edit
|
12
|
-
App::Config::config_params_get
|
13
|
-
App::Config::config_params_validate(true)
|
14
|
-
|
15
|
-
else
|
16
|
-
|
17
|
-
App::Config.initialize
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
rescue => e
|
22
|
-
|
23
|
-
Blufin::Terminal::print_exception(e)
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|