sport_ngin_aws_auditor 3.8.3 → 3.9.0

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: 61c18acb4a0425eecc7d1c34475b6f9e4782a591
4
- data.tar.gz: b64e797ac47c77b29c8572336f0a096e293f785d
3
+ metadata.gz: beef821f62dfeb8b9235d25a120b2faf8ddec09a
4
+ data.tar.gz: f0c504bfd3cbd9fbdd8f305c733f8eba50ce7ac9
5
5
  SHA512:
6
- metadata.gz: 65a9c6b87a00aa2b941b40876a2e2ff96c42ad0a2719fc05e8ebe57a21aa576ef99f1640e99adf81f5e95d48c0414e6cc409e7727759cacefee2f69e30787c39
7
- data.tar.gz: be320dedfbd0384a24f185067e8b870e11c1566cf4aeb21aa2245821cdd6835ef6d2bd308fc84420cb35bf3def5161f1da704ebf65674e28365f623e19ddc24d
6
+ metadata.gz: 62da765c56b2599a4817d1b585bd3844bec7397e4a1c2cd93ab7e1d409c0e255fa5123b2fecf56e0463cce87e497436620764a34c4caba67accba942f4317d5c
7
+ data.tar.gz: 71545feabd3057e6062725598b98b565cc31a99ed1c2847edc9867ae2ae721b8e78826395ad181657e4faa60277cbb12b7426eb7f47a74389db50484ddbc267a
data/.travis.yml CHANGED
@@ -6,8 +6,6 @@ branches:
6
6
 
7
7
  language: ruby
8
8
  rvm:
9
- - 2.0.0
10
- - 2.1
11
9
  - 2.2
12
10
  cache: bundler
13
11
  script: bundle exec rspec
data/CHANGELOG.markdown CHANGED
@@ -1,3 +1,8 @@
1
+ #### v3.9.0
2
+ * Add the ability to pass config data in as a flag
3
+
4
+ > Emma Sax: Andy Fleener, Unknown User: https://github.com/sportngin/sport_ngin_aws_auditor/pull/24
5
+
1
6
  #### v3.8.3
2
7
  * Fixing bugs with outputs and counts
3
8
 
@@ -7,6 +7,7 @@ command 'audit' do |c|
7
7
  c.switch [:r, :reserved], :desc => "Shows reserved instance counts"
8
8
  c.switch [:i, :instances], :desc => "Shows current instance counts"
9
9
  c.flag [:t, :tag], :default_value => "no-reserved-instance", :desc => "Read a tag and group separately during audit"
10
+ c.flag [:h, :config_json], :default_value => nil, :desc => "Print the audit according to this config json object instead of to config file"
10
11
  c.switch [:n, :no_tag], :desc => "Ignore all tags during audit"
11
12
  c.switch [:s, :slack], :desc => "Will print condensed version of audit to a Slack channel"
12
13
  c.action do |global_options, options, args|
@@ -1,24 +1,28 @@
1
1
  require 'httparty'
2
+ require 'json'
2
3
 
3
4
  module SportNginAwsAuditor
4
5
  class NotifySlack
5
- attr_accessor :text, :channel, :webhook, :username, :icon_url, :icon_emoji, :attachments
6
+ attr_accessor :text, :channel, :webhook, :username, :icon_url, :icon_emoji, :attachments, :config
6
7
 
7
- def initialize(text)
8
+ def initialize(text, config_params)
8
9
  self.text = text
9
10
  self.attachments = []
10
- if SportNginAwsAuditor::Config.slack
11
- self.channel = SportNginAwsAuditor::Config.slack[:channel]
12
- self.username = SportNginAwsAuditor::Config.slack[:username]
13
- self.webhook = SportNginAwsAuditor::Config.slack[:webhook]
14
- self.icon_url = SportNginAwsAuditor::Config.slack[:icon_url]
11
+ config_file = SportNginAwsAuditor::Config.slack.to_h || {}
12
+ self.config = config_params ? config_file.merge(JSON.parse(config_params)) : config_file
13
+
14
+ if self.config
15
+ self.channel = self.config['channel']
16
+ self.username = self.config['username']
17
+ self.webhook = self.config['webhook']
18
+ self.icon_url = self.config['icon_url']
15
19
  else
16
- puts "To use Slack, you must provide a separate config file. See the README for more information."
20
+ puts "To use Slack, you must provide either a separate config file or a hash of config data. See the README for more information."
17
21
  end
18
22
  end
19
23
 
20
24
  def perform
21
- if SportNginAwsAuditor::Config.slack
25
+ if config
22
26
  options = {text: text,
23
27
  webhook: webhook,
24
28
  channel: channel,
@@ -126,7 +126,7 @@ module SportNginAwsAuditor
126
126
 
127
127
  def self.print_discrepancies(discrepancy_array, audit_results, class_type, environment)
128
128
  title = "Some #{class_type} discrepancies for #{environment} exist:\n"
129
- slack_instances = NotifySlack.new(title)
129
+ slack_instances = NotifySlack.new(title, options[:config_json])
130
130
 
131
131
  discrepancy_array.each do |discrepancy|
132
132
  type = discrepancy.type
@@ -144,7 +144,7 @@ module SportNginAwsAuditor
144
144
 
145
145
  def self.print_tagged(tagged_array, audit_results, class_type, environment)
146
146
  title = "There are currently some tagged #{class_type}s in #{environment}:\n"
147
- slack_instances = NotifySlack.new(title)
147
+ slack_instances = NotifySlack.new(title, options[:config_json])
148
148
 
149
149
  tagged_array.each do |tagged|
150
150
  type = tagged.type
@@ -173,7 +173,7 @@ module SportNginAwsAuditor
173
173
  message << "*#{name}* (#{count}) on *#{expiration_date}*\n"
174
174
  end
175
175
 
176
- slack_retired_ris = NotifySlack.new(message)
176
+ slack_retired_ris = NotifySlack.new(message, options[:config_json])
177
177
  slack_retired_ris.perform
178
178
  end
179
179
 
@@ -188,7 +188,7 @@ module SportNginAwsAuditor
188
188
  end
189
189
  end
190
190
 
191
- slack_retired_tags = NotifySlack.new(message)
191
+ slack_retired_tags = NotifySlack.new(message, options[:config_json])
192
192
  slack_retired_tags.perform
193
193
  end
194
194
 
@@ -1,3 +1,3 @@
1
1
  module SportNginAwsAuditor
2
- VERSION = "3.8.3"
2
+ VERSION = "3.9.0"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require "sport_ngin_aws_auditor"
2
+ require 'json'
2
3
 
3
4
  module SportNginAwsAuditor
4
5
  describe NotifySlack do
@@ -16,17 +17,29 @@ module SportNginAwsAuditor
16
17
  it 'should ping Slack Notifier' do
17
18
  notifier = double('notifier')
18
19
  expect(HTTParty).to receive(:post)
19
- message = NotifySlack.new("Test message")
20
+ message = NotifySlack.new("Test message", nil)
20
21
  message.perform
21
22
  end
22
23
 
23
24
  it 'should define certain values' do
24
- message = NotifySlack.new("Test message")
25
+ message = NotifySlack.new("Test message", nil)
25
26
  expect(message.text).to eq("Test message")
26
27
  expect(message.channel).to eq("#random-test-channel")
27
28
  expect(message.username).to eq("Random User")
28
29
  expect(message.webhook).to eq("https://hooks.slack.com/services/totallyrandom/fakewebhookurl")
29
30
  expect(message.icon_url).to eq("http://random-picture.jpg")
30
31
  end
32
+
33
+ it 'should ping Slack Notifier even when passing in config as a hash' do
34
+ notifier = double('notifier')
35
+ config_hash = {:username=>"AWS Auditor",
36
+ :icon_url=>"http://i.imgur.com/86x8PSg.jpg",
37
+ :channel=>"#test-webhook-channel",
38
+ :webhook=>"https://hooks.slack.com/services/thisisafake"
39
+ }.to_json
40
+ expect(HTTParty).to receive(:post)
41
+ message = NotifySlack.new("Test message", config_hash)
42
+ message.perform
43
+ end
31
44
  end
32
45
  end
@@ -24,8 +24,8 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency 'highline', '~> 1.6'
25
25
  spec.add_dependency 'google_drive', '~> 1.0.0.pre2'
26
26
  spec.add_dependency 'google-api-client', '~> 0.8.6'
27
- spec.add_dependency 'rack', '~> 1.3.0'
28
- spec.add_dependency 'activesupport', '~> 3.2'
27
+ spec.add_dependency 'rack', '>= 1.3.0'
28
+ spec.add_dependency 'activesupport', '>= 3.2'
29
29
  spec.add_dependency 'httparty'
30
30
  spec.add_dependency 'colorize'
31
31
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sport_ngin_aws_auditor
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.8.3
4
+ version: 3.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elliot Hursh
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-11-10 00:00:00.000000000 Z
13
+ date: 2016-11-11 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: aws-sdk
@@ -100,28 +100,28 @@ dependencies:
100
100
  name: rack
101
101
  requirement: !ruby/object:Gem::Requirement
102
102
  requirements:
103
- - - "~>"
103
+ - - ">="
104
104
  - !ruby/object:Gem::Version
105
105
  version: 1.3.0
106
106
  type: :runtime
107
107
  prerelease: false
108
108
  version_requirements: !ruby/object:Gem::Requirement
109
109
  requirements:
110
- - - "~>"
110
+ - - ">="
111
111
  - !ruby/object:Gem::Version
112
112
  version: 1.3.0
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: activesupport
115
115
  requirement: !ruby/object:Gem::Requirement
116
116
  requirements:
117
- - - "~>"
117
+ - - ">="
118
118
  - !ruby/object:Gem::Version
119
119
  version: '3.2'
120
120
  type: :runtime
121
121
  prerelease: false
122
122
  version_requirements: !ruby/object:Gem::Requirement
123
123
  requirements:
124
- - - "~>"
124
+ - - ">="
125
125
  - !ruby/object:Gem::Version
126
126
  version: '3.2'
127
127
  - !ruby/object:Gem::Dependency