awx 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 387197029107fc3f0061d3a18ed29c4cfb411540
4
- data.tar.gz: 51d23676040bac0444f4ac73f261fd48e08f0e24
3
+ metadata.gz: 41303bbb644a98338fb8cb92edc742f09e51aee7
4
+ data.tar.gz: dc6356a37d780996e215f4edca139ffc98bd06b8
5
5
  SHA512:
6
- metadata.gz: f96e2cc1fe271437e8422cd3866bc4f9d9c0474a4ca4d392e0f7e15788ee02ac0fa3f5348f5611d105e39f3b3aeaaee7879f7a5ee7dbad4917c330a17e3393d1
7
- data.tar.gz: f0a15ab29c5674987ebacef867fef0d0ab320e8e5d684e3d9f13b653cf03dd38a0b3b441ac1008681b1c2c3ebf901e1223efc18cbd74063f47acfce9b251e74e
6
+ metadata.gz: '0796592c71cc98b79fbda89dea698616de11ee17f667cfa18c11ab8dbcf7903287a7e69c3cb87b7154623e887b366c4242be6eed2c914edf0d124548529fd6cb'
7
+ data.tar.gz: 6eef364efe94d7aa45e97f9d7b50910583cfc648304601cb2d3cb5b21c8819de23bf272540e66a5e3c34730b4e8c7ac8b3115a8c36dcb8e90325c441a698fdef
data/lib/aws/aws.rb CHANGED
@@ -4,6 +4,13 @@ module App
4
4
 
5
5
  VALID_REGIONS = %w(ap-south-1 eu-west-3 eu-west-2 eu-west-1 ap-northeast-2 ap-northeast-1 sa-east-1 ca-central-1 ap-southeast-1 ap-southeast-2 eu-central-1 us-east-1 us-east-2 us-west-1 us-west-2)
6
6
 
7
+ # Returns either ' --profile [profile-name]' or '', depending on whether the machine we're running on has credentials or is an EC2 (which uses IAM roles).
8
+ # @return string
9
+ def self.get_profile_for_cli
10
+ profile_name = App::AWSProfile::get_profile_name
11
+ profile_name.nil? ? '' : " --profile #{profile_name}"
12
+ end
13
+
7
14
  end
8
15
 
9
16
  end
data/lib/aws/aws_cli.rb CHANGED
@@ -73,7 +73,9 @@ module App
73
73
  term_protect = term_protect ? ' --enable-termination-protection' : ' --no-enable-termination-protection'
74
74
  timeout = timeout.nil? ? '' : " --timeout-in-minutes #{timeout}"
75
75
  command = "cloudformation create-stack --stack-name #{stack_name} --template-url #{s3_url}#{params}#{tags}#{capabilities}#{term_protect}#{timeout}"
76
- App::AWSOutputter::output_cli_command("aws #{command} --region #{region} --profile #{App::AWSProfile::get_profile_name}")
76
+ profile_name = App::AWSProfile::get_profile_name
77
+ profile = profile_name.nil? ? '' : " --profile #{profile_name}"
78
+ App::AWSOutputter::output_cli_command("aws #{command} --region #{region}#{profile}")
77
79
  puts
78
80
  stack_send = execute_as_proc("Sending CloudFormation Stack: #{Blufin::Terminal::format_highlight(stack_name)}", command, region, json: true)
79
81
  begin
@@ -131,9 +133,9 @@ module App
131
133
  raise RuntimeError, "Invalid region: #{region}" unless get_regions.include?(region) || region == REGION_SKIP
132
134
  begin
133
135
  region = region == REGION_SKIP ? '' : " --region #{region}"
134
- puts "\x1B[38;5;70m$ \x1B[38;5;240maws #{command}#{region} --profile #{App::AWSProfile::get_profile_name}\x1B[0m" if verbose
136
+ puts "\x1B[38;5;70m$ \x1B[38;5;240maws #{command}#{region}#{App::AWS::get_profile_for_cli}\x1B[0m" if verbose
135
137
  if json
136
- result = `aws #{command}#{region} --profile #{App::AWSProfile::get_profile_name} 2>/tmp/execute-output-aws`
138
+ result = `aws #{command}#{region}#{App::AWS::get_profile_for_cli} 2>/tmp/execute-output-aws`
137
139
  # If no JSON, simply return the output.
138
140
  return `cat /tmp/execute-output-aws` if result == ''
139
141
  begin
@@ -142,12 +144,12 @@ module App
142
144
  raise RuntimeError, "JSON Parsing Failed:\n\n#{e.message}"
143
145
  end
144
146
  else
145
- result = system("aws #{command}#{region} --profile #{App::AWSProfile::get_profile_name} 1>/dev/null 2>/tmp/execute-output-aws")
147
+ result = system("aws #{command}#{region}#{App::AWS::get_profile_for_cli} 1>/dev/null 2>/tmp/execute-output-aws")
146
148
  `cat /tmp/execute-output-aws` unless result
147
149
  return result
148
150
  end
149
151
  rescue => e
150
- Blufin::Terminal::error("Command Failed: #{Blufin::Terminal::format_command("aws #{command}#{region} --profile #{App::AWSProfile::get_profile_name}")}", e.message, true)
152
+ Blufin::Terminal::error("Command Failed: #{Blufin::Terminal::format_command("aws #{command}#{region}#{App::AWS::get_profile_for_cli}")}", e.message, true)
151
153
  end
152
154
  end
153
155
 
@@ -86,6 +86,8 @@ module App
86
86
  errors << "aws-cli error. Cannot find #{profile}: #{Blufin::Terminal::format_invalid('aws_access_key_id')} in: #{Blufin::Terminal::format_directory(FILE_AWS_CREDENTIALS)}" if @@credentials.aws_key.nil?
87
87
  errors << "aws-cli error. Cannot find #{profile}: #{Blufin::Terminal::format_invalid('aws_secret_access_key')} in: #{Blufin::Terminal::format_directory(FILE_AWS_CREDENTIALS)}" if @@credentials.aws_secret.nil?
88
88
  else
89
+ # Returns 'yes' if running on EC2 instance, 'no' if not.
90
+ return if `#{App::Opt::get_base_path}/#{App::Opt::OPT_PATH}/shell/ec2-check` == 'yes'
89
91
  errors << "aws-cli error. Cannot find file: #{Blufin::Terminal::format_invalid(FILE_AWS_CREDENTIALS)}"
90
92
  end
91
93
 
@@ -103,6 +105,7 @@ module App
103
105
  # Convenience method to just get the profile name.
104
106
  # @return string
105
107
  def self.get_profile_name
108
+ return nil if @@credentials.nil?
106
109
  @@profile[PROFILE]
107
110
  end
108
111
 
@@ -127,7 +127,7 @@ module App
127
127
  response[region] = {} if response[region].nil?
128
128
  sleep(0.01) unless silent
129
129
  threads << Thread.new {
130
- cmd = "aws #{resource[App::AWSReports::KEY_CLI][App::AWSReports::KEY_COMMAND]}#{region == App::AWSReports::CONST_GLOBAL ? '' : " --region #{region}"} --profile #{App::AWSProfile::get_profile_name}"
130
+ cmd = "aws #{resource[App::AWSReports::KEY_CLI][App::AWSReports::KEY_COMMAND]}#{region == App::AWSReports::CONST_GLOBAL ? '' : " --region #{region}"}#{App::AWS::get_profile_for_cli}"
131
131
  App::AWSOutputter::output_cli_command(cmd) unless silent
132
132
  json = `#{cmd}`
133
133
  begin
data/lib/awx.rb CHANGED
@@ -145,7 +145,7 @@ TEMPLATE
145
145
  end
146
146
 
147
147
  # S - SWITCH
148
- if ARGV[0] != 'setup' && ARGV[0] != 'x' && App::AWSProfile::get_profile_names.length > 1
148
+ if ARGV[0] != 'setup' && ARGV[0] != 'x' && App::AWSProfile::get_profile_names.length > 1 && !App::AWSProfile::get_credentials.nil?
149
149
  # Only show if we have multiple profiles.
150
150
  awx.command :switch, :aliases => [:S] do |switch|
151
151
  switch.summary 'Switch Profiles'
@@ -573,7 +573,7 @@ module AppCommand
573
573
  # If no 'after' actions necessary, give option to terminate script.
574
574
  term_script = false
575
575
  if @template[:method_after_create].nil? && !@template[:single_serve]
576
- options = [{:text => "Yes \xe2\x80\x94 Script will wait until stack is fully built.", :value => false}, {:text => 'No', :value => true}]
576
+ options = [{:text => "Yes \xe2\x80\x94 Wait for stack to finish building.", :value => false}, {:text => 'No', :value => true}]
577
577
  help_text = "Select 'No' to end the script immediately. Status can still be viewed in the AWS console."
578
578
  term_script = Blufin::Terminal::prompt_select('Wait for stack to build?', options, help: help_text)
579
579
  puts
@@ -41,7 +41,7 @@ module AppCommand
41
41
  stacks.each do |stack|
42
42
  sleep(0.01)
43
43
  threads << Thread.new {
44
- cmd = "aws cloudformation detect-stack-drift --stack-name #{stack[:name]} --region #{stack[:region]} --profile #{App::AWSProfile::get_profile_name} >> #{TMP_OUTPUT} 2>&1"
44
+ cmd = "aws cloudformation detect-stack-drift --stack-name #{stack[:name]} --region #{stack[:region]}#{App::AWS::get_profile_for_cli} >> #{TMP_OUTPUT} 2>&1"
45
45
  App::AWSOutputter::output_cli_command(cmd)
46
46
  `#{cmd}`
47
47
  }
data/lib/routes/list.rb CHANGED
@@ -41,7 +41,7 @@ module AppCommand
41
41
  raise RuntimeError, 'Not yet implemented!'
42
42
  end
43
43
 
44
- # Throw error if -m is set with any other flas.
44
+ # Throw error if -m is set with any other flags.
45
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
46
46
 
47
47
  if @opts[:json_prompt]
@@ -149,7 +149,9 @@ module AppCommand
149
149
  cmd_regions = @regions.join(',')
150
150
  cmd_regions = resource[App::AWSReports::KEY_REGIONS].join(',') if resource.has_key?(App::AWSReports::KEY_REGIONS)
151
151
  cmd_regions = "\x1B[38;5;#{cmd_color}m[\x1B[38;5;246m#{cmd_regions}\x1B[38;5;#{cmd_color}m]"
152
- 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")
152
+ profile_name = App::AWSProfile::get_profile_name
153
+ profile_output = profile_name.nil? ? '' : "\x1B[38;5;240 --profile \x1B[38;5;246m#{profile_name}"
154
+ App::AWSOutputter::output_cli_command("aws #{resource[App::AWSReports::KEY_CLI][App::AWSReports::KEY_COMMAND]} --region #{cmd_regions}#{profile_output}\x1B[0m")
153
155
  threads << Thread.new {
154
156
  uber_results[resource_title] = App::AWSReports::get_aws_data(@regions, resource, resource_title, silent: true)
155
157
  }
data/lib/version.rb CHANGED
@@ -1 +1 @@
1
- AWX_VERSION = '0.6.0'
1
+ AWX_VERSION = '0.6.1'
@@ -0,0 +1,24 @@
1
+ #!/bin/bash
2
+
3
+ # Checks if we are running on an EC2 instance.
4
+ # https://serverfault.com/questions/462903/how-to-know-if-a-machine-is-an-ec2-instance
5
+
6
+ if [ -f /sys/hypervisor/uuid ]; then
7
+ if [ `head -c 3 /sys/hypervisor/uuid` == "ec2" ]; then
8
+ echo yes
9
+ else
10
+ echo no
11
+ fi
12
+ elif [ -r /sys/devices/virtual/dmi/id/product_uuid ]; then
13
+ if [ `head -c 3 /sys/devices/virtual/dmi/id/product_uuid` == "EC2" ]; then
14
+ echo yes
15
+ else
16
+ echo no
17
+ fi
18
+ else
19
+ if $(curl -s -m 1 http://169.254.169.254/latest/dynamic/instance-identity/document | grep -q availabilityZone) ; then
20
+ echo yes
21
+ else
22
+ echo no
23
+ fi
24
+ fi
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: awx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
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-09-07 00:00:00.000000000 Z
11
+ date: 2019-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: blufin-lib
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.7.0
19
+ version: 1.7.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 1.7.0
26
+ version: 1.7.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: json
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -116,6 +116,7 @@ files:
116
116
  - opt/awx/reports.yml
117
117
  - opt/config/schema.yml
118
118
  - opt/config/template.yml
119
+ - opt/shell/ec2-check
119
120
  homepage: http://rubygems.org/gems/awx
120
121
  licenses:
121
122
  - MIT