onering-client 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/bin/onering CHANGED
@@ -16,15 +16,16 @@ Usage:
16
16
  where [global] options are:
17
17
  EOS
18
18
 
19
- opt :url, "The URL of the Onering server to connect to", :short => '-s', :type => :string
20
- opt :path, "The base path to prepend to all requests (default: /api)", :type => :string
21
- opt :source, "Specify the source IP address to use (i.e. which network interface the request should originate from)", :short => '-I', :type => :string
22
- opt :param, "Additional query string parameters to include with the request in the format FIELD=VALUE. Can be specified multiple times.", :short => '-p', :type => :string, :multi => true
23
- opt :format, "The output format for return values (i.e.: json, yaml, text)", :default => 'text', :short => '-t', :type => :string
24
- opt :sslkey, "Location of the SSL client key to use for authentication", :short => '-c', :type => :string
25
- opt :apikey, "The API token to use for authentication", :short => '-k', :type => :string
26
- opt :quiet, "Suppress standard output", :short => '-q'
27
- opt :verbosity, "Set the log level (fatal, error, warn, info, debug)", :short => '-v', :type => :string, :default => 'warn'
19
+ opt :url, "The URL of the Onering server to connect to", :short => '-s', :type => :string
20
+ opt :path, "The base path to prepend to all requests (default: /api)", :type => :string
21
+ opt :source, "Specify the source IP address to use (i.e. which network interface the request should originate from)", :short => '-I', :type => :string
22
+ opt :param, "Additional query string parameters to include with the request in the format FIELD=VALUE. Can be specified multiple times.", :short => '-p', :type => :string, :multi => true
23
+ opt :format, "The output format for return values (i.e.: json, yaml, text)", :default => 'text', :short => '-t', :type => :string
24
+ opt :sslkey, "Location of the SSL client key to use for authentication", :short => '-c', :type => :string
25
+ opt :nosslverify, "Disable verification of the server SSL certificate", :type => :boolean
26
+ opt :apikey, "The API token to use for authentication", :short => '-k', :type => :string
27
+ opt :quiet, "Suppress standard output", :short => '-q'
28
+ opt :verbosity, "Set the log level (fatal, error, warn, info, debug)", :short => '-v', :type => :string, :default => 'warn'
28
29
 
29
30
  stop_on plugins
30
31
  end
data/lib/onering/api.rb CHANGED
@@ -1,16 +1,4 @@
1
1
  require 'openssl'
2
-
3
- # This is perhaps the saddest thing I have ever written...
4
- #
5
- # Don't cry for me...I'm already dead.
6
- #
7
- module OpenSSL
8
- module SSL
9
- remove_const :VERIFY_PEER
10
- VERIFY_PEER = VERIFY_NONE
11
- end
12
- end
13
-
14
2
  require 'yaml'
15
3
  require 'hashlib'
16
4
  require 'deep_merge'
@@ -58,39 +46,59 @@ module Onering
58
46
  # load and merge all config file sources
59
47
  Onering::Config.load(@_connection_options[:configfile], @_connection_options.get(:config, {}))
60
48
 
61
- # source interface specified
62
- # !! HAX !! HAX !! HAX !! HAX !! HAX !! HAX !! HAX !! HAX !! HAX !! HAX !!
63
- # Due to certain versions of Ruby's Net::HTTP not allowing you explicitly
64
- # specify the source IP/interface to use, this horrific monkey patch is
65
- # necessary, if not right.
66
- #
67
- # If at least some of your code doesn't make you feel bottomless shame
68
- # then you aren't coding hard enough.
69
- #
70
- if options.get('config.source').is_a?(String)
71
- if options.get('config.source') =~ /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/
72
- # insert firing pin into the hack
73
- TCPSocket.instance_eval do
74
- (class << self; self; end).instance_eval do
75
- alias_method :_stock_open, :open
76
- attr_writer :_hack_local_ip
77
-
78
- define_method(:open) do |conn_address, conn_port|
79
- _stock_open(conn_address, conn_port, @_hack_local_ip)
80
- end
49
+ if options.get('config.nosslverify', false) == true
50
+ # deliberately break SSL verification
51
+ Onering::Logger.warn("Disabling SSL peer verification for #{options.get('config.url')}")
52
+ OpenSSL::SSL.send(:const_set, :OLD_VERIFY_PEER, OpenSSL::SSL::VERIFY_PEER)
53
+ OpenSSL::SSL.send(:remove_const, :VERIFY_PEER)
54
+ OpenSSL::SSL.send(:const_set, :VERIFY_PEER, OpenSSL::SSL::VERIFY_NONE)
55
+ else
56
+ # restore SSL verification if it's currently broken
57
+ if defined?(OpenSSL::SSL::OLD_VERIFY_PEER)
58
+ if OpenSSL::SSL::VERIFY_PEER == OpenSSL::SSL::VERIFY_NONE and OpenSSL::SSL::OLD_VERIFY_PEER != OpenSSL::SSL::VERIFY_NONE
59
+ OpenSSL::SSL.send(:remove_const, :VERIFY_PEER)
60
+ OpenSSL::SSL.send(:const_set, :VERIFY_PEER, OpenSSL::SSL::OLD_VERIFY_PEER)
81
61
  end
82
62
  end
63
+ end
83
64
 
84
- # arm the hack
85
- TCPSocket._hack_local_ip = options.get('config.source')
65
+ if OpenSSL::SSL::VERIFY_PEER == OpenSSL::SSL::VERIFY_NONE
66
+ Onering::Logger.warn("Disabling SSL peer verification for #{options.get('config.url')}")
67
+ end
86
68
 
87
- # sound the siren
88
- Onering::Logger.info("Using local interface #{options.get('config.source')} to connect", "Onering::API")
69
+ # source interface specified
70
+ # !! HAX !! HAX !! HAX !! HAX !! HAX !! HAX !! HAX !! HAX !! HAX !! HAX !!
71
+ # Due to certain versions of Ruby's Net::HTTP not allowing you explicitly
72
+ # specify the source IP/interface to use, this horrific monkey patch is
73
+ # necessary, if not right.
74
+ #
75
+ # If at least some of your code doesn't make you feel bottomless shame
76
+ # then you aren't coding hard enough.
77
+ #
78
+ if options.get('config.source').is_a?(String)
79
+ if options.get('config.source') =~ /^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/
80
+ # insert firing pin into the hack
81
+ TCPSocket.instance_eval do
82
+ (class << self; self; end).instance_eval do
83
+ alias_method :_stock_open, :open
84
+ attr_writer :_hack_local_ip
85
+
86
+ define_method(:open) do |conn_address, conn_port|
87
+ _stock_open(conn_address, conn_port, @_hack_local_ip)
88
+ end
89
+ end
90
+ end
89
91
 
90
- else
91
- raise "Invalid source IP address #{options.get('config.source')}"
92
+ # arm the hack
93
+ TCPSocket._hack_local_ip = options.get('config.source')
94
+
95
+ # sound the siren
96
+ Onering::Logger.info("Using local interface #{options.get('config.source')} to connect", "Onering::API")
97
+
98
+ else
99
+ raise "Invalid source IP address #{options.get('config.source')}"
100
+ end
92
101
  end
93
- end
94
102
 
95
103
  # set API connectivity details
96
104
  Onering::API.base_uri(options.get('config.url', Onering::Config.get(:url, DEFAULT_BASE)))
data/lib/onering/cli.rb CHANGED
@@ -11,13 +11,14 @@ module Onering
11
11
  return Onering::API.new({
12
12
  'autoconnect' => cliargs[:autoconnect],
13
13
  'config' => {
14
- 'url' => cliargs[:url],
15
- 'path' => cliargs[:path],
16
- 'source' => cliargs[:source],
17
- 'params' => Hash[(cliargs[:param] || []).collect{|i| i.split('=',2) }],
14
+ 'url' => cliargs[:url],
15
+ 'path' => cliargs[:path],
16
+ 'source' => cliargs[:source],
17
+ 'nosslverify' => cliargs[:nosslverify],
18
+ 'params' => Hash[(cliargs[:param] || []).collect{|i| i.split('=',2) }],
18
19
  'authentication' => {
19
- 'type' => (cliargs[:apikey_given] ? :token : nil),
20
- 'keyfile' => (cliargs[:apikey] || cliargs[:sslkey])
20
+ 'type' => (cliargs[:apikey_given] ? :token : nil),
21
+ 'keyfile' => (cliargs[:apikey] || cliargs[:sslkey])
21
22
  }.compact
22
23
  }.compact
23
24
  }.compact)
@@ -0,0 +1,27 @@
1
+ module Onering
2
+ class API
3
+ class Configuration < API
4
+ def get(key, options={})
5
+ get("/config/#{key}").parsed_response
6
+ end
7
+
8
+ def set(key, value)
9
+ if not value.is_a?(Hash) and not value.is_a?(Array)
10
+ return save(key, value)
11
+ end
12
+
13
+ return nil
14
+ end
15
+
16
+ def save(key, data=nil, &block)
17
+ if block_given?
18
+ post("/config/#{key}", {}, &block)
19
+ else
20
+ post("/config/#{key}", {
21
+ :body => data
22
+ })
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
data/lib/onering.rb CHANGED
@@ -2,7 +2,7 @@ $: << File.expand_path(File.dirname(__FILE__))
2
2
 
3
3
  module Onering
4
4
  module Client
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.2"
6
6
 
7
7
  class Error < Exception; end
8
8
  class FatalError < Error; end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onering-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-01-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: facter
16
- requirement: &24589080 !ruby/object:Gem::Requirement
16
+ requirement: &11003660 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.7.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *24589080
24
+ version_requirements: *11003660
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: deep_merge
27
- requirement: &24588580 !ruby/object:Gem::Requirement
27
+ requirement: &11019380 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - =
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.0.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *24588580
35
+ version_requirements: *11019380
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: addressable
38
- requirement: &24588080 !ruby/object:Gem::Requirement
38
+ requirement: &11018780 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - =
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.3.5
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *24588080
46
+ version_requirements: *11018780
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: httparty
49
- requirement: &24587560 !ruby/object:Gem::Requirement
49
+ requirement: &11018280 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - =
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.11.0
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *24587560
57
+ version_requirements: *11018280
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: hashlib
60
- requirement: &24587060 !ruby/object:Gem::Requirement
60
+ requirement: &11017620 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 0.0.35
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *24587060
68
+ version_requirements: *11017620
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: multi_json
71
- requirement: &24586560 !ruby/object:Gem::Requirement
71
+ requirement: &11016940 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - =
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 1.7.9
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *24586560
79
+ version_requirements: *11016940
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rainbow
82
- requirement: &24586080 !ruby/object:Gem::Requirement
82
+ requirement: &11016220 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - <=
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 1.1.4
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *24586080
90
+ version_requirements: *11016220
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: trollop
93
- requirement: &24606560 !ruby/object:Gem::Requirement
93
+ requirement: &11015380 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - =
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '2.0'
99
99
  type: :runtime
100
100
  prerelease: false
101
- version_requirements: *24606560
101
+ version_requirements: *11015380
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: xml-simple
104
- requirement: &24606100 !ruby/object:Gem::Requirement
104
+ requirement: &11013900 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - =
@@ -109,7 +109,7 @@ dependencies:
109
109
  version: 1.1.2
110
110
  type: :runtime
111
111
  prerelease: false
112
- version_requirements: *24606100
112
+ version_requirements: *11013900
113
113
  description: A Ruby wrapper for Onering
114
114
  email: ghetzel@outbrain.com
115
115
  executables:
@@ -117,22 +117,23 @@ executables:
117
117
  extensions: []
118
118
  extra_rdoc_files: []
119
119
  files:
120
- - lib/onering/config.rb
120
+ - lib/onering.rb
121
121
  - lib/onering/logger.rb
122
122
  - lib/onering/cli.rb
123
- - lib/onering/plugins/devices.rb
124
- - lib/onering/plugins/reporter.rb
123
+ - lib/onering/config.rb
124
+ - lib/onering/api.rb
125
+ - lib/onering/util.rb
125
126
  - lib/onering/plugins/authentication.rb
127
+ - lib/onering/plugins/reporter.rb
128
+ - lib/onering/plugins/devices.rb
129
+ - lib/onering/plugins/config.rb
126
130
  - lib/onering/plugins/automation.rb
127
- - lib/onering/cli/devices.rb
128
131
  - lib/onering/cli/reporter.rb
132
+ - lib/onering/cli/devices.rb
129
133
  - lib/onering/cli/config.rb
130
- - lib/onering/cli/fact.rb
131
134
  - lib/onering/cli/automation.rb
135
+ - lib/onering/cli/fact.rb
132
136
  - lib/onering/cli/call.rb
133
- - lib/onering/api.rb
134
- - lib/onering/util.rb
135
- - lib/onering.rb
136
137
  - bin/onering
137
138
  homepage: https://github.com/outbrain/onering-ruby
138
139
  licenses: []