cloudcover 0.2.0 → 0.2.3

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: dbb728764310a4e52eee3275ad788c2e9d7c7878
4
- data.tar.gz: 156433fe14e1d78052f70a4432c7eeb74f1a1fef
3
+ metadata.gz: 827ed9004b2577a85ff3f64e5f483b37c5fe8afa
4
+ data.tar.gz: b698e0d5fb89f603f180ba778aafb8b2069009a3
5
5
  SHA512:
6
- metadata.gz: e50396dcbbbce2a0ad2d276847ebf3b8b024f4b09a149bc173d9b41ea3b7527903cf716c3171585ef7f594918e3db97c9f355a351a3880f07c2965d8fd81ca4e
7
- data.tar.gz: 8dd3cf589676ca586921628d4cab961d3ef2165d8d018c5c2d3d6791b1f607d5dfb17dbf4b9c3ef7a0851eb3e28f8a892926dd151ce0bc4d90bab52b702c1212
6
+ metadata.gz: abfae0d9a1d5aab70cf77f39ec43f3edacf959b544fae6c43a14d9c308c6bd2904368112bff23d2abfe3f7af4de7c326d33f469d59327099311939d57b9931ed
7
+ data.tar.gz: aa4668da2ed37d3ed83bc68ffbe4274d5700601c446f8b1741cba944de2b8ca1a330d3f2f750be391e0ded664dbfe85d86d345d863119600b61d92543220b7bb
data/.gitignore CHANGED
@@ -3,3 +3,4 @@ test.creds
3
3
  .DS_Store
4
4
  .idea
5
5
  *.gem
6
+ spec/examples.txt
data/bin/cloudcover CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'gli'
3
3
  require 'cloudcover'
4
+ require 'pp'
4
5
 
5
6
  include GLI::App
6
7
 
@@ -10,12 +11,27 @@ version Cloudcover::VERSION
10
11
 
11
12
  subcommand_option_handling :normal
12
13
  arguments :strict
14
+ wrap_help_text :verbatim
15
+ sort_help :manually
16
+
17
+ accept(Hash) do |value|
18
+ result = {}
19
+ value.split(/,/).each do |pair|
20
+ k,v = pair.split(/:/)
21
+ result[k] = v
22
+ end
23
+ result
24
+ end
25
+
26
+ flag [:okta_domain], :desc => "Your organization's Okta domain"
27
+ flag [:config], :desc => "Cloudcover config file path", :default_value => Cloudcover::DefaultPaths.config
28
+ flag ['session-path'], :desc => "Cloudcover cookie file path", :default_value => Cloudcover::DefaultPaths.cookie
29
+ flag [:slack], :desc => Cloudcover::FlagDescriptions.slack, :type => Hash
30
+
31
+ switch [:v,:verbose], :desc => "Verbose output", :negatable => false
32
+ switch [:d,:debug], :desc => "Debug output (Includes verbose)", :negatable => false
33
+ switch [:color], :desc => "Colorize output", :default_value => true
13
34
 
14
- switch [:v,:verbose], :desc => 'Verbose output', :negatable => false
15
- switch [:d,:debug], :desc => 'Debug output (Includes verbose)', :negatable => false
16
- switch [:color], :desc => 'Colorize output', :default_value => true
17
- flag [:config], :desc => 'Cloudcover config file path', :default_value => Cloudcover::DefaultPaths.config
18
- flag ['session-path'], :desc => 'Cloudcover cookie file path', :default_value => Cloudcover::DefaultPaths.cookie
19
35
 
20
36
  desc 'Simply verify that a set of credentials are valid to login to Okta. Returns 0 on success and non-zero on failure.'
21
37
  arg_name '[credential file path]'
@@ -36,12 +52,13 @@ command 'simple-auth' do |c|
36
52
  end
37
53
 
38
54
  pre do |global,command,options,args|
39
- ENV['HOME'] = "." if ENV['HOME'].nil? # Hack to fix contexts where the env is not set. Should probably find a better way to handle this.
40
- $verbose = global[:verbose] || global[:debug]
41
- $debug = global[:debug]
42
- $color = global[:color]
43
- Cloudcover::Config.load(global[:config])
44
- Cloudcover::Config.set_config_options(global)
55
+ Cloudcover::GlobalConfig.load(global[:config]) if global[:config]
56
+ Cloudcover::GlobalConfig.merge! global.reject{ |key,value| value.nil?}
57
+ Cloudcover::GlobalConfig.merge! options.reject{ |key,value| value.nil?}
58
+ if global[:debug]
59
+ puts "Compiled config: "
60
+ pp Cloudcover::GlobalConfig.config
61
+ end
45
62
  true
46
63
  end
47
64
 
data/cloudcover.gemspec CHANGED
@@ -13,6 +13,7 @@ spec = Gem::Specification.new do |s|
13
13
  s.require_paths << 'lib'
14
14
  s.bindir = 'bin'
15
15
  s.executables << 'cloudcover'
16
+ s.required_ruby_version = '~> 2.2'
16
17
 
17
18
  s.add_dependency 'httparty'
18
19
  s.add_dependency 'http-cookie'
@@ -20,9 +21,12 @@ spec = Gem::Specification.new do |s|
20
21
  s.add_dependency "terminal-table"
21
22
  s.add_dependency "minitar"
22
23
  s.add_dependency "hashdiff"
24
+ s.add_dependency "hashie", "~>3.4"
25
+
23
26
 
24
27
  s.add_development_dependency 'rake'
25
28
  s.add_development_dependency 'rdoc'
29
+ s.add_development_dependency 'rspec'
26
30
 
27
31
 
28
32
  s.add_runtime_dependency "gli", "~>2.13.4"
@@ -23,6 +23,7 @@ module Cloudcover
23
23
  def auth_response(auth, msg)
24
24
  if auth
25
25
  if @opts[:radius]
26
+ send_to_slack(msg) if Cloudcover::GlobalConfig.slack[:report_auth_success]
26
27
  p "Accept"
27
28
  else
28
29
  p msg
@@ -31,7 +32,7 @@ module Cloudcover
31
32
  if @opts[:radius]
32
33
  abort 'Reject'
33
34
  else
34
- send_to_slack(msg) if Cloudcover::Config.slack[:report_auth_failures]
35
+ send_to_slack(msg) if Cloudcover::GlobalConfig.slack[:report_auth_failures]
35
36
  abort msg
36
37
  end
37
38
  end
@@ -82,7 +83,7 @@ module Cloudcover
82
83
  end
83
84
 
84
85
  def date_format
85
- Cloudcover::Config.date_format ? Cloudcover::Config.date_format : "%a %b %e %H:%M:%S %Y"
86
+ Cloudcover::GlobalConfig.date_format ? Cloudcover::GlobalConfig.date_format : "%a %b %e %H:%M:%S %Y"
86
87
  end
87
88
 
88
89
  def app_id
@@ -106,10 +107,10 @@ module Cloudcover
106
107
  slackvars = [:username, :icon_url, :channel]
107
108
  payload = { text: msg }
108
109
  slackvars.each do |var|
109
- payload.merge!({var=> Cloudcover::Config.slack[var]}) if Cloudcover::Config.slack[var]
110
+ payload.merge!({var=> Cloudcover::GlobalConfig.slack[var]}) if Cloudcover::GlobalConfig.slack[var]
110
111
  end
111
112
 
112
- HTTParty.post(Cloudcover::Config.slack[:webhook],
113
+ HTTParty.post(Cloudcover::GlobalConfig.slack[:webhook],
113
114
  :body => "payload=#{payload.to_json}"
114
115
  )
115
116
  end
@@ -1,11 +1,12 @@
1
1
  require 'yaml'
2
+ require 'hashie'
2
3
 
3
4
  module Cloudcover
4
-
5
- module PrivateAttrAccessor
6
- def private_attr_accessor(*names)
7
- private
8
- attr_accessor *names
5
+ class FlagDescriptions
6
+ class << self
7
+ def slack
8
+ "Hash of slack options\n\tExample: \"username:SlackUser, icon_url:http://fake.url, channel:#test-channel, webhook:https://slack.web.hook\"\n\t"
9
+ end
9
10
  end
10
11
  end
11
12
 
@@ -25,72 +26,38 @@ module Cloudcover
25
26
  end
26
27
  end
27
28
 
28
- class Config
29
-
30
- CONFIG_DEFAULTS = {}
31
-
32
- class << self
33
- extend PrivateAttrAccessor
34
- private_attr_accessor :config_data
35
-
36
- def config
37
- CONFIG_DEFAULTS.merge data
38
- end
39
-
40
- def load(path)
41
- load_config(path)
42
- config
43
- end
44
-
45
- def set_config_options(opts = {})
46
- data.merge! opts
47
- config
48
- end
29
+ module GlobalConfig
30
+ extend self
49
31
 
50
- def data
51
- self.config_data ||= {}
52
- end
53
- private :data
54
-
55
- def default_value(key)
56
- CONFIG_DEFAULTS[key.to_sym]
57
- end
58
- private :default_value
32
+ def config
33
+ config_data.to_hash
34
+ end
59
35
 
60
- def method_missing(method, args=false)
61
- return data[method] if data[method]
62
- return default_value(method) if default_value(method)
63
- nil
64
- end
65
- private :method_missing
36
+ def load(path)
37
+ load_config(path)
38
+ config
39
+ end
66
40
 
67
- def load_config(file)
68
- Output.say_debug("Loading the config file from #{file}")
69
- raise MissingConfig, "Missing configuration file: #{file} Run 'cloudcover help'" unless File.exist?(file)
70
- self.config_data = symbolize_keys(YAML.load_file(file)) rescue {}
71
- end
72
- private :load_config
41
+ def config_data
42
+ @config_data ||= Hashie::Mash.new
43
+ end
44
+ private :config_data
73
45
 
74
- # We want all ouf our YAML loaded keys to be symbols
75
- # taken from http://devblog.avdi.org/2009/07/14/recursively-symbolize-keys/
76
- def symbolize_keys(hash)
77
- hash.inject({}){|result, (key, value)|
78
- new_key = case key
79
- when String then key.to_sym
80
- else key
81
- end
82
- new_value = case value
83
- when Hash then symbolize_keys(value)
84
- else value
85
- end
86
- result[new_key] = new_value
87
- result
88
- }
89
- end
90
- private :symbolize_keys
46
+ def method_missing(method, args=false)
47
+ config_data.send(method, args)
48
+ end
49
+ private :method_missing
91
50
 
51
+ def load_config(file)
52
+ raise MissingConfig, "Missing configuration file: #{file} Run 'cloudcover help'" unless File.exist?(file)
53
+ config_data.merge! YAML.load_file(file)
92
54
  end
55
+ private :load_config
56
+ end
93
57
 
94
- MissingConfig = Class.new(StandardError)
58
+ class ConfigInstance
59
+ include GlobalConfig
95
60
  end
61
+
62
+ MissionConfig = Class.new(StandardError)
96
63
  end
@@ -9,8 +9,8 @@ module Cloudcover
9
9
  attr_reader :headers
10
10
 
11
11
  def initialize
12
- self.class.debug_output if Cloudcover::Config.debug
13
- self.class.base_uri "https://#{Cloudcover::Config.okta_domain}.okta.com"
12
+ self.class.debug_output if Cloudcover::GlobalConfig.debug
13
+ self.class.base_uri "https://#{Cloudcover::GlobalConfig.okta_domain}.okta.com"
14
14
  @headers = {
15
15
  'Content-Type' => "application/json",
16
16
  'Accept' => "application/json",
@@ -1,3 +1,3 @@
1
1
  module Cloudcover
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.3'
3
3
  end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+ require 'cloudcover'
3
+
4
+ module Cloudcover
5
+ describe GlobalConfig do
6
+
7
+ context "config key methods" do
8
+ it "should return nil when not set" do
9
+ expect(GlobalConfig.doesnt_exist).to eql(nil)
10
+ expect(GlobalConfig.doesnt_exist?).to eql(false)
11
+ end
12
+ it "should return the config value when set" do
13
+ GlobalConfig.new_value = "testing"
14
+ expect(GlobalConfig.new_value).to eql("testing")
15
+ end
16
+ end
17
+
18
+ context "after loading a config file" do
19
+ before do
20
+ config_file = {"domain"=>"example_domain", "slack"=>{"slack_option"=>true, "username"=>"Rspec Tester", "icon_url"=>"http://fake.url", "channel"=>"#test-channel", "webhook"=>"https://slack.web.hook"}}
21
+ allow(YAML).to receive(:load_file).and_return(config_file)
22
+ allow(File).to receive(:exist?).and_return(true)
23
+ GlobalConfig.load("dummy/path")
24
+ end
25
+
26
+ it "calling a method corresponding to a key in the file should return the value" do
27
+ expect(GlobalConfig.domain).to eql("example_domain")
28
+ expect(GlobalConfig.slack).to be_kind_of(Hash)
29
+ expect(GlobalConfig.slack[:slack_option]).to eql(true)
30
+ end
31
+
32
+ it "overwriting values should work" do
33
+ expect(GlobalConfig.slack).to be_kind_of(Hash)
34
+ GlobalConfig.slack = "this is a string now"
35
+ expect(GlobalConfig.slack).to eql("this is a string now")
36
+ end
37
+
38
+ end
39
+ end
40
+ end
41
+
@@ -0,0 +1,24 @@
1
+ RSpec.configure do |config|
2
+ config.expect_with :rspec do |expectations|
3
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
4
+ end
5
+
6
+ config.mock_with :rspec do |mocks|
7
+ mocks.verify_partial_doubles = true
8
+ end
9
+
10
+ config.color = true
11
+ config.filter_run :focus
12
+ config.run_all_when_everything_filtered = true
13
+ config.example_status_persistence_file_path = "spec/examples.txt"
14
+ config.disable_monkey_patching!
15
+ #config.profile_examples = 10
16
+ config.order = :random
17
+ Kernel.srand config.seed
18
+ config.expose_dsl_globally = true
19
+ if config.files_to_run.one?
20
+ config.default_formatter = 'doc'
21
+ end
22
+
23
+ end
24
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cloudcover
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Krieger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-21 00:00:00.000000000 Z
11
+ date: 2016-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: hashie
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.4'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.4'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rake
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -122,6 +136,20 @@ dependencies:
122
136
  - - ">="
123
137
  - !ruby/object:Gem::Version
124
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
125
153
  - !ruby/object:Gem::Dependency
126
154
  name: gli
127
155
  requirement: !ruby/object:Gem::Requirement
@@ -158,6 +186,8 @@ files:
158
186
  - lib/cloudcover/okta/client.rb
159
187
  - lib/cloudcover/output.rb
160
188
  - lib/cloudcover/version.rb
189
+ - spec/cloudcover/config_spec.rb
190
+ - spec/spec_helper.rb
161
191
  homepage: http://www.sportngin.com
162
192
  licenses: []
163
193
  metadata: {}
@@ -168,9 +198,9 @@ require_paths:
168
198
  - lib
169
199
  required_ruby_version: !ruby/object:Gem::Requirement
170
200
  requirements:
171
- - - ">="
201
+ - - "~>"
172
202
  - !ruby/object:Gem::Version
173
- version: '0'
203
+ version: '2.2'
174
204
  required_rubygems_version: !ruby/object:Gem::Requirement
175
205
  requirements:
176
206
  - - ">="
@@ -178,7 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
208
  version: '0'
179
209
  requirements: []
180
210
  rubyforge_project:
181
- rubygems_version: 2.4.8
211
+ rubygems_version: 2.5.1
182
212
  signing_key:
183
213
  specification_version: 4
184
214
  summary: Provides a simple interface for using Okta authentication in command line