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.
@@ -0,0 +1,43 @@
1
+ module AppCommand
2
+
3
+ class AWSDynamoDB < ::Convoy::ActionCommand::Base
4
+
5
+ JAR_FILE = 'DynamoDBLocal.jar'
6
+
7
+ def execute
8
+
9
+ begin
10
+
11
+ @opts = command_options
12
+ @args = arguments
13
+
14
+ @dynamo_db_path = Blufin::Config::get['DynamoDBPath']
15
+ @dynamo_db_file = "#{@dynamo_db_path}/#{JAR_FILE}"
16
+
17
+ opts_validate
18
+ opts_routing
19
+
20
+ rescue => e
21
+
22
+ Blufin::Terminal::print_exception(e)
23
+
24
+ end
25
+
26
+ end
27
+
28
+ def opts_validate
29
+
30
+ # Make sure DynamoDB .jar file exists.
31
+ Blufin::Terminal::error("File not found: #{Blufin::Terminal::format_directory(@dynamo_db_file)}", ['To download DynamoDB package, visit:', 'https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.DownloadingAndRunning.html'], true) unless Blufin::Files::file_exists(@dynamo_db_file)
32
+
33
+ end
34
+
35
+ def opts_routing
36
+
37
+ Blufin::Terminal::command("java -Djava.library.path=./DynamoDBLocal_lib -jar #{JAR_FILE} -sharedDb", @dynamo_db_path)
38
+
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -10,7 +10,8 @@ module AppCommand
10
10
  @args = arguments
11
11
 
12
12
  @resource = nil
13
- @silent = @opts[:json] || @opts[:json_prompt] || @opts[:yaml]
13
+ @export_id = nil
14
+ @silent = @opts[:json] || @opts[:json_prompt] || @opts[:yaml] || @opts[:yaml_colored]
14
15
  @regions = App::AWSCli::get_regions
15
16
  @terminal_width = Blufin::Terminal::get_terminal_width
16
17
  @data = nil
@@ -33,7 +34,7 @@ module AppCommand
33
34
 
34
35
  def opts_validate
35
36
 
36
- Blufin::Routes::only_one_of(@opts, [:json, :json_prompt, :yaml])
37
+ Blufin::Routes::only_one_of(@opts, [:json, :json_prompt, :yaml, :yaml_colored])
37
38
 
38
39
  # TODO - Implement!
39
40
  if @opts[:region] || @opts[:environment] || @opts[:project]
@@ -43,9 +44,10 @@ module AppCommand
43
44
  # Throw error if -m is set with any other flas.
44
45
  Blufin::Terminal::error("When #{Blufin::Terminal::format_flag('m')} is set, no other flags can be set.", "Found: #{Blufin::Routes::flags_set(@opts).to_i - 1} other flag(s).", true) if @opts[:metadata] && Blufin::Routes::flags_set(@opts).to_i > 1
45
46
 
46
- # For resources with exports, this enables you to pass the -r flag as both AcmCertificates or AcmCertificateARN (and it will resolve to the same API call).
47
- if @opts[:json_prompt]
48
- @opts[:resource] = @export_map[@opts[:resource]] if @export_map.has_key?(@opts[:resource])
47
+ # For resources with exports, this enables you to pass the -r flag as both AcmCertificates or AcmCertificateArn (and it will resolve to the same API call).
48
+ if @export_map.has_key?(@opts[:resource])
49
+ @export_id = @opts[:resource]
50
+ @opts[:resource] = @export_map[@opts[:resource]]
49
51
  end
50
52
 
51
53
  # Validate that resource exists (if passed from command-line).
@@ -55,6 +57,7 @@ module AppCommand
55
57
  Blufin::Terminal::error("The #{Blufin::Terminal::format_flag('j')} cannot be set when listing all resources.") if @opts[:json]
56
58
  Blufin::Terminal::error("The #{Blufin::Terminal::format_flag('j')} cannot be set when listing all resources.") if @opts[:json_prompt]
57
59
  Blufin::Terminal::error("The #{Blufin::Terminal::format_flag('y')} cannot be set when listing all resources.") if @opts[:yaml]
60
+ Blufin::Terminal::error("The #{Blufin::Terminal::format_flag('Y')} cannot be set when listing all resources.") if @opts[:yaml_colored]
58
61
  @resource = App::AWSReports::CONST_ALL
59
62
  else
60
63
  Blufin::Terminal::error("Invalid: #{Blufin::Terminal::format_invalid(@opts[:resource])} . Available resources are:", @data.keys, true) unless @data.has_key?(@opts[:resource])
@@ -63,10 +66,11 @@ module AppCommand
63
66
  end
64
67
 
65
68
  # If response is JSON/YAML, Resource must be explicitly specified.
66
- if @opts[:json] || @opts[:json_prompt] || @opts[:yaml]
69
+ if @opts[:json] || @opts[:json_prompt] || @opts[:yaml] || @opts[:yaml_colored]
67
70
  flag = 'j' if @opts[:json]
68
71
  flag = 'J' if @opts[:json_prompt]
69
72
  flag = 'y' if @opts[:yaml]
73
+ flag = 'Y' if @opts[:yaml_colored]
70
74
  Blufin::Terminal::error("Must specify #{Blufin::Terminal::format_highlight('resource')} explicitly (using #{Blufin::Terminal::format_flag('r')}) if #{Blufin::Terminal::format_flag(flag)} is set.") if @opts[:resource].nil?
71
75
  if @opts[:json_prompt]
72
76
  Blufin::Terminal::error("Resource must have #{Blufin::Terminal::format_highlight('export')} defined if #{Blufin::Terminal::format_flag(flag)} is set.") unless @resource.has_key?(App::AWSReports::KEY_EXPORT)
@@ -129,8 +133,8 @@ module AppCommand
129
133
  sleep(0.01)
130
134
  cmd_regions = @regions.join(',')
131
135
  cmd_regions = resource[App::AWSReports::KEY_REGIONS].join(',') if resource.has_key?(App::AWSReports::KEY_REGIONS)
132
- cmd_regions = "\x1B[38;5;#{cmd_color}m[\x1B[38;5;246m#{cmd_regions}\x1B[38;5;#{cmd_color}m]\x1B[0m"
133
- puts " \x1B[38;5;70m$ \x1B[38;5;#{cmd_color}maws #{resource[App::AWSReports::KEY_CLI][App::AWSReports::KEY_COMMAND]} --region #{cmd_regions}\x1B[0m"
136
+ cmd_regions = "\x1B[38;5;#{cmd_color}m[\x1B[38;5;246m#{cmd_regions}\x1B[38;5;#{cmd_color}m]"
137
+ App::AWSOutputter::output_cli_command("aws #{resource[App::AWSReports::KEY_CLI][App::AWSReports::KEY_COMMAND]} --region #{cmd_regions}\x1B[38;5;240m --profile \x1B[38;5;246m#{App::AWSProfile::get_profile_name}\x1B[0m")
134
138
  threads << Thread.new {
135
139
  uber_results[resource_title] = App::AWSReports::get_aws_data(@regions, resource, resource_title, silent: true)
136
140
  }
@@ -161,7 +165,7 @@ module AppCommand
161
165
  else
162
166
 
163
167
  # Bomb-out if the output does not fit in Terminal.
164
- if !@opts[:json] && !@opts[:json_prompt] && !@opts[:yaml] && !fits_in_terminal(resource_title)[0]
168
+ if !@opts[:json] && !@opts[:json_prompt] && !@opts[:yaml] && !@opts[:yaml_colored] && !fits_in_terminal(resource_title)[0]
165
169
  Blufin::Terminal::error("Output for #{Blufin::Terminal::format_highlight(resource_title)} \x1B[38;5;240m(#{Blufin::Terminal::format_action(@table_widths[resource_title])}\x1B[38;5;240m-width)\x1B[0m does not fit in Terminal \x1B[38;5;240m(#{Blufin::Terminal::format_action(@terminal_width)}\x1B[38;5;240m-width)\x1B[0m", 'Please make your terminal wider and try again.', true)
166
170
  end
167
171
 
@@ -196,9 +200,11 @@ module AppCommand
196
200
  if @opts[:json]
197
201
  puts JSON.pretty_generate(results)
198
202
  elsif @opts[:json_prompt]
199
- puts JSON.pretty_generate(App::AWSReports::parse_results_for_prompt(resource, results))
203
+ puts JSON.pretty_generate(App::AWSReports::parse_results_for_prompt(resource, @export_id, results))
200
204
  elsif @opts[:yaml]
201
- Blufin::Terminal::code_highlight(results.to_yaml, 'yml', 4)
205
+ puts results.to_yaml
206
+ elsif @opts[:yaml_colored]
207
+ Blufin::Terminal::code_highlight(results.to_yaml, 'yml', 0)
202
208
  else
203
209
  unless silent
204
210
  if @columns.has_key?(resource_title)
@@ -0,0 +1,76 @@
1
+ module AppCommand
2
+
3
+ class AWSSwitch < ::Convoy::ActionCommand::Base
4
+
5
+ def execute
6
+
7
+ begin
8
+
9
+ @opts = command_options
10
+ @args = arguments
11
+
12
+ opts_validate
13
+ opts_routing
14
+
15
+ rescue => e
16
+
17
+ Blufin::Terminal::print_exception(e)
18
+
19
+ end
20
+
21
+ end
22
+
23
+ def opts_validate
24
+
25
+ end
26
+
27
+ def opts_routing
28
+
29
+ config_file = File.expand_path(App::CONFIG_FILE)
30
+
31
+ # Bomb-out if file went missing...
32
+ Blufin::Terminal::error("File not found: #{Blufin::Terminal::format_invalid(config_file)}") unless Blufin::Files::file_exists(config_file)
33
+
34
+ # Create profile options.
35
+ profiles = []
36
+ App::AWSProfile::get_profile_names.each do |profile|
37
+ option = {
38
+ :text => profile,
39
+ :value => profile
40
+ }
41
+ # Uncomment this if you want to disable current profile.
42
+ # option[:disabled] = 'Current Profile' if profile == App::AWSProfile::get_profile_name
43
+ profiles << option
44
+ end
45
+
46
+ # Display current profile.
47
+ Blufin::Terminal::info("Current profile: #{Blufin::Terminal::format_highlight(App::AWSProfile::get_profile_name)}")
48
+
49
+ # Prompt for new profile.
50
+ new_profile = Blufin::Terminal::prompt_select('Select a profile', profiles)
51
+
52
+ # Replace profile in config file.
53
+ Blufin::Files::write_line_to_file(config_file, "DefaultProfile: #{new_profile}", /^\s*DefaultProfile:/, false, true)
54
+
55
+ # Display new profile confirmation.
56
+ Blufin::Terminal::success("Your new active profile is: #{Blufin::Terminal::format_highlight(new_profile)}", "All #{Blufin::Terminal::format_command('awx')} commands will now run against this profile.")
57
+
58
+ # Re-link configuration file.
59
+ if App::is_albert_mac
60
+ config_file = App::CONFIG_FILE
61
+ symlinked_file = Blufin::Config::get['CustomOptions']['ConfigFilePath']
62
+ Blufin::Terminal::error("File not found: #{Blufin::Terminal::format_invalid(symlinked_file)}", "A symlink to #{Blufin::Terminal::format_directory(config_file)} was broken and could not be re-created.") unless Blufin::Files::file_exists(symlinked_file)
63
+ res = []
64
+ res[0] = Blufin::Terminal::execute("cp #{File.expand_path(config_file)} #{File.expand_path(symlinked_file)} ")
65
+ res[1] = Blufin::Terminal::execute("ln -sfv #{File.expand_path(symlinked_file)} #{File.expand_path(config_file)}")
66
+ puts
67
+ puts "\x1B[38;5;240m File successfully copied/symlinked.\x1B[0m" if res[0] && res[1]
68
+ puts "\x1B[38;5;196m Something went wrong. The cp/symlink command(s) did not return successful exit code(s).\x1B[0m" if !res[0] || !res[1]
69
+ puts
70
+ end
71
+
72
+ end
73
+
74
+ end
75
+
76
+ end
data/lib/version.rb CHANGED
@@ -1 +1 @@
1
- AWX_VERSION = '0.2.0'
1
+ AWX_VERSION = '0.3.0'
@@ -6,9 +6,9 @@ AcmCertificates:
6
6
  command: acm list-certificates --certificate-statuses ISSUED
7
7
  root: CertificateSummaryList
8
8
  export:
9
- id: AcmCertificateARN
10
- value: CertificateArn
11
- description: DomainName
9
+ - id: AcmCertificateArn
10
+ value: CertificateArn
11
+ description: DomainName
12
12
  columns:
13
13
  - [ title: CertificateARN, key: CertificateArn, width: 90 ]
14
14
  - [ title: DomainName, key: DomainName, width: "*" ]
@@ -19,9 +19,9 @@ APIs:
19
19
  command: apigateway get-rest-apis
20
20
  root: items
21
21
  export:
22
- id: RestApiId
23
- value: id
24
- description: name
22
+ - id: RestApiId
23
+ value: id
24
+ description: name
25
25
  columns:
26
26
  - [ title: Name, key: name, width: 90 ]
27
27
  - [ title: Id, key: id, width: 29 ]
@@ -33,7 +33,7 @@ CloudFormationStacks:
33
33
  command: cloudformation list-stacks --stack-status-filter CREATE_IN_PROGRESS CREATE_FAILED CREATE_COMPLETE ROLLBACK_IN_PROGRESS ROLLBACK_FAILED ROLLBACK_COMPLETE DELETE_IN_PROGRESS DELETE_FAILED UPDATE_IN_PROGRESS UPDATE_COMPLETE_CLEANUP_IN_PROGRESS UPDATE_COMPLETE UPDATE_ROLLBACK_IN_PROGRESS UPDATE_ROLLBACK_FAILED UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS UPDATE_ROLLBACK_COMPLETE REVIEW_IN_PROGRESS
34
34
  root: StackSummaries
35
35
  columns:
36
- - [ title: StackId, key: StackId, width: 169 ]
36
+ - [ title: StackId, key: StackId, width: 169, formatter: cloudformation-stack ]
37
37
  - [ title: DriftStatus, key: DriftInformation.StackDriftStatus, width: 15 ]
38
38
  - [ title: Status, key: StackStatus, width: "*" ]
39
39
  CloudFrontDistributions:
@@ -94,13 +94,16 @@ Route53HostedZones:
94
94
  command: route53 list-hosted-zones
95
95
  root: HostedZones
96
96
  export:
97
- id: Route53HostedZoneId
98
- value: Id
99
- valueFormatter: route-53-hosted-zone-id
100
- description: Name
97
+ - id: Route53HostedZoneId
98
+ value: Id
99
+ valueFormatter: route-53-hosted-zone-id
100
+ description: Name
101
+ - id: Route53DomainName
102
+ value: Name
103
+ valueFormatter: route-53-domain-name
101
104
  columns:
102
105
  - [ title: HostedZoneId, key: Id, width: 90, formatter: route-53-hosted-zone-id ]
103
- - [ title: DomainName, key: Name, width: "*" ]
106
+ - [ title: DomainName, key: Name, width: "*", formatter: route-53-domain-name ]
104
107
  WorkMailOrganizations:
105
108
  regions: [ us-east-1, us-west-2 ]
106
109
  regionsPreferred: [ us-east-1 ]
@@ -0,0 +1,63 @@
1
+ type: map
2
+ mapping:
3
+ CustomOptions:
4
+ type: map
5
+ mapping:
6
+ Secret:
7
+ required: true
8
+ ConfigFilePath:
9
+ required: true
10
+ DefaultProfile:
11
+ required: yes
12
+ DynamoDBPath:
13
+ Profiles:
14
+ type: seq
15
+ required: yes
16
+ sequence:
17
+ - type: map
18
+ mapping:
19
+ Profile:
20
+ type: str
21
+ required: yes
22
+ CloudFormation:
23
+ type: map
24
+ mapping:
25
+ S3Bucket:
26
+ required: yes
27
+ S3BucketPath:
28
+ required: yes
29
+ S3BucketRegion:
30
+ required: yes
31
+ TemplatePath:
32
+ required: yes
33
+ Defaults:
34
+ type: map
35
+ required: yes
36
+ mapping:
37
+ StackName:
38
+ required: yes
39
+ Regions:
40
+ type: seq
41
+ required: yes
42
+ sequence:
43
+ - type: str
44
+ Timeout:
45
+ type: int
46
+ required: yes
47
+ Projects:
48
+ type: map
49
+ mapping:
50
+ Local:
51
+ type: map
52
+ mapping:
53
+ File:
54
+ required: yes
55
+ S3Bucket:
56
+ type: map
57
+ mapping:
58
+ Name:
59
+ required: yes
60
+ File:
61
+ required: yes
62
+ Region:
63
+ required: yes
@@ -0,0 +1,21 @@
1
+ DefaultProfile: default
2
+ DynamoDBPath: <<-path/to/folder->>
3
+ Profiles:
4
+ - Profile: default
5
+ CloudFormation:
6
+ S3Bucket: <<-S3-bucket-name->>
7
+ S3BucketPath: <<-S3-bucket-path/to/folder->>
8
+ S3BucketRegion: <<-S3-bucket-region->>
9
+ TemplatePath: <<-path/to/folder->>
10
+ Defaults:
11
+ StackName: "{{CATEGORY}}-{{TEMPLATE}}-{{PROJECT}}-{{ENVIRONMENT}}-{{REGION}}-{{UUID}}"
12
+ Timeout: 60
13
+ Regions:
14
+ - us-west-2
15
+ Projects:
16
+ Local:
17
+ File: <<-path/to/file->>
18
+ S3Bucket:
19
+ Name: <<-S3-bucket-name->>
20
+ File: <<-S3-bucket-path/to/file->>
21
+ Region: <<-S3-bucket-region->>
metadata CHANGED
@@ -1,63 +1,63 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Albert Rannetsperger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-08 00:00:00.000000000 Z
11
+ date: 2019-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: columnist
14
+ name: blufin-lib
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 1.1.0
19
+ version: 1.5.3
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.5.3
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - '='
25
28
  - !ruby/object:Gem::Version
26
- version: 1.1.0
29
+ version: 1.5.3
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.5.3
27
33
  - !ruby/object:Gem::Dependency
28
- name: convoy
34
+ name: columnist
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
37
  - - '='
32
38
  - !ruby/object:Gem::Version
33
- version: 1.2.0
39
+ version: 1.1.0
34
40
  type: :runtime
35
41
  prerelease: false
36
42
  version_requirements: !ruby/object:Gem::Requirement
37
43
  requirements:
38
44
  - - '='
39
45
  - !ruby/object:Gem::Version
40
- version: 1.2.0
46
+ version: 1.1.0
41
47
  - !ruby/object:Gem::Dependency
42
- name: blufin-lib
48
+ name: convoy
43
49
  requirement: !ruby/object:Gem::Requirement
44
50
  requirements:
45
51
  - - '='
46
52
  - !ruby/object:Gem::Version
47
- version: 1.5.0
48
- - - ">="
49
- - !ruby/object:Gem::Version
50
- version: 1.5.0
53
+ version: 1.2.0
51
54
  type: :runtime
52
55
  prerelease: false
53
56
  version_requirements: !ruby/object:Gem::Requirement
54
57
  requirements:
55
58
  - - '='
56
59
  - !ruby/object:Gem::Version
57
- version: 1.5.0
58
- - - ">="
59
- - !ruby/object:Gem::Version
60
- version: 1.5.0
60
+ version: 1.2.0
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: parseconfig
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -80,26 +80,28 @@ extensions: []
80
80
  extra_rdoc_files: []
81
81
  files:
82
82
  - bin/awx
83
+ - lib/aws/aws.rb
83
84
  - lib/aws/aws_cache.rb
84
85
  - lib/aws/aws_cli.rb
85
86
  - lib/aws/aws_cloudformation.rb
86
- - lib/aws/aws_config.rb
87
87
  - lib/aws/aws_credentials.rb
88
88
  - lib/aws/aws_outputter.rb
89
+ - lib/aws/aws_profile.rb
89
90
  - lib/aws/aws_reports.rb
90
91
  - lib/aws/aws_validator.rb
91
92
  - lib/awx.rb
92
- - lib/core/config.rb
93
- - lib/core/config_unique.rb
94
93
  - lib/core/opt.rb
95
94
  - lib/routes/aws_cloudformation_create.rb
96
95
  - lib/routes/aws_cloudformation_delete.rb
97
96
  - lib/routes/aws_cloudformation_detect_drift.rb
98
- - lib/routes/aws_lambda.rb
97
+ - lib/routes/aws_deploy.rb
98
+ - lib/routes/aws_dynamo_db.rb
99
99
  - lib/routes/aws_list.rb
100
- - lib/routes/setup.rb
100
+ - lib/routes/aws_switch.rb
101
101
  - lib/version.rb
102
- - opt/yml/aws-reports.yml
102
+ - opt/awx/reports.yml
103
+ - opt/config/schema.yml
104
+ - opt/config/template.yml
103
105
  homepage: http://rubygems.org/gems/awx
104
106
  licenses:
105
107
  - MIT