xclarity_client 0.5.4 → 0.5.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/xclarity_client.rb +6 -0
- data/lib/xclarity_client/client.rb +4 -1
- data/lib/xclarity_client/configuration.rb +2 -5
- data/lib/xclarity_client/error/authentication_error.rb +10 -0
- data/lib/xclarity_client/error/connection_failed.rb +10 -0
- data/lib/xclarity_client/error/connection_failed_unknown.rb +10 -0
- data/lib/xclarity_client/error/connection_refused.rb +10 -0
- data/lib/xclarity_client/error/hostname_unknown.rb +10 -0
- data/lib/xclarity_client/version.rb +1 -1
- data/lib/xclarity_client/xclarity_base.rb +24 -9
- data/xclarity_client.gemspec +1 -0
- metadata +21 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 266a40b1f827da05891126299803c352a393f7ed
|
4
|
+
data.tar.gz: c98d7e1948b6a8f32d8dbc47af2a744a5615b9f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acf88004bb3707fb096a613a5c7e1a66d13bbfaaef6efc882093c3056655c913f4ea5923d20862bf2b660f1eb89ab216298f135e26620c7a906e43e4f5ecbad5
|
7
|
+
data.tar.gz: b49c59dcc5a1d5bb12d1be21f7db94ad1e970ac600a468719d11f785ae1116cbc3f5a295c75b47b4e1522d6bc2b4337d3679600554741b44a439e562e02094b1
|
data/lib/xclarity_client.rb
CHANGED
@@ -43,3 +43,9 @@ require 'xclarity_client/user'
|
|
43
43
|
require 'xclarity_client/user_management'
|
44
44
|
require 'xclarity_client/discover'
|
45
45
|
require 'xclarity_client/client'
|
46
|
+
|
47
|
+
require 'xclarity_client/error/authentication_error'
|
48
|
+
require 'xclarity_client/error/connection_failed'
|
49
|
+
require 'xclarity_client/error/connection_failed_unknown'
|
50
|
+
require 'xclarity_client/error/connection_refused'
|
51
|
+
require 'xclarity_client/error/hostname_unknown'
|
@@ -1,9 +1,7 @@
|
|
1
|
-
require 'securerandom'
|
2
|
-
|
3
1
|
module XClarityClient
|
4
2
|
class Configuration
|
5
3
|
|
6
|
-
attr_accessor :username, :password, :host, :
|
4
|
+
attr_accessor :username, :password, :host, :auth_type, :port, :verify_ssl
|
7
5
|
|
8
6
|
def initialize(args)
|
9
7
|
|
@@ -24,8 +22,7 @@ module XClarityClient
|
|
24
22
|
end
|
25
23
|
|
26
24
|
$lxca_log.info "XClarityClient::Configuration initialize","Configuration built successfuly"
|
27
|
-
|
28
|
-
@csrf_token ||= SecureRandom.base64(120) if @auth_type == 'token'
|
25
|
+
|
29
26
|
end
|
30
27
|
|
31
28
|
def self.default
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'faraday'
|
2
|
+
require 'faraday-cookie_jar'
|
2
3
|
require 'json'
|
3
4
|
require 'uri'
|
4
5
|
require 'uri/https'
|
@@ -6,9 +7,8 @@ require 'uri/https'
|
|
6
7
|
module XClarityClient
|
7
8
|
class XClarityBase
|
8
9
|
|
9
|
-
token_auth = '/session'.freeze
|
10
10
|
attr_reader :conn
|
11
|
-
|
11
|
+
|
12
12
|
def initialize(conf, uri)
|
13
13
|
connection_builder(conf, uri)
|
14
14
|
end
|
@@ -28,12 +28,13 @@ module XClarityClient
|
|
28
28
|
@conn = Faraday.new(url: url) do |faraday|
|
29
29
|
faraday.request :url_encoded # form-encode POST params
|
30
30
|
faraday.response :logger # log requests to STDOUT -- This line, should be uncommented if you wanna inspect the URL Request
|
31
|
+
faraday.use :cookie_jar if conf.auth_type == 'token'
|
31
32
|
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
32
33
|
faraday.ssl[:verify] = conf.verify_ssl == 'PEER'
|
33
34
|
end
|
34
35
|
|
35
|
-
|
36
|
-
|
36
|
+
authentication(conf) if conf.auth_type == 'token'
|
37
|
+
|
37
38
|
@conn.basic_auth(conf.username, conf.password) if conf.auth_type == 'basic_auth'
|
38
39
|
$lxca_log.info "XClarityClient::XclarityBase connection_builder", "Connection created Successfuly"
|
39
40
|
@conn
|
@@ -74,13 +75,27 @@ module XClarityClient
|
|
74
75
|
|
75
76
|
def authentication(conf)
|
76
77
|
response = @conn.post do |request|
|
77
|
-
request.url '/
|
78
|
+
request.url '/sessions'
|
78
79
|
request.headers['Content-Type'] = 'application/json'
|
79
80
|
request.body = {:UserId => conf.username,
|
80
|
-
:password => conf.password
|
81
|
-
|
82
|
-
|
83
|
-
|
81
|
+
:password => conf.password}.to_json
|
82
|
+
end
|
83
|
+
if not response.success?
|
84
|
+
raise Faraday::Error::ConnectionFailed
|
85
|
+
end
|
86
|
+
|
87
|
+
rescue => err
|
88
|
+
cause = err.cause.to_s.downcase
|
89
|
+
if cause.include?('connection refused')
|
90
|
+
raise XClarityClient::Error::ConnectionRefused
|
91
|
+
elsif cause.include?('name or service not known')
|
92
|
+
raise XClarityClient::Error::HostnameUnknown
|
93
|
+
elsif response.nil?
|
94
|
+
raise XClarityClient::Error::ConnectionFailed
|
95
|
+
elsif response.status == 403
|
96
|
+
raise XClarityClient::Error::AuthenticationError
|
97
|
+
else
|
98
|
+
raise XClarityClient::Error::ConnectionFailedUnknown.new("status #{response.status}")
|
84
99
|
end
|
85
100
|
end
|
86
101
|
end
|
data/xclarity_client.gemspec
CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.add_development_dependency "apib-mock_server", "~> 1.0.3"
|
24
24
|
spec.add_development_dependency "webmock", "~> 2.1.0"
|
25
25
|
spec.add_dependency "faraday", "~> 0.9.2"
|
26
|
+
spec.add_dependency "faraday-cookie_jar", "~> 0.0.6"
|
26
27
|
spec.add_dependency "uuid", "~> 2.3.8"
|
27
28
|
spec.add_dependency "faker", "~> 1.8.3"
|
28
29
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: xclarity_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manasa Rao
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2017-
|
12
|
+
date: 2017-09-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -95,6 +95,20 @@ dependencies:
|
|
95
95
|
- - "~>"
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: 0.9.2
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: faraday-cookie_jar
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - "~>"
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 0.0.6
|
105
|
+
type: :runtime
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - "~>"
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: 0.0.6
|
98
112
|
- !ruby/object:Gem::Dependency
|
99
113
|
name: uuid
|
100
114
|
requirement: !ruby/object:Gem::Requirement
|
@@ -175,6 +189,11 @@ files:
|
|
175
189
|
- lib/xclarity_client/cmm_management.rb
|
176
190
|
- lib/xclarity_client/configuration.rb
|
177
191
|
- lib/xclarity_client/discover.rb
|
192
|
+
- lib/xclarity_client/error/authentication_error.rb
|
193
|
+
- lib/xclarity_client/error/connection_failed.rb
|
194
|
+
- lib/xclarity_client/error/connection_failed_unknown.rb
|
195
|
+
- lib/xclarity_client/error/connection_refused.rb
|
196
|
+
- lib/xclarity_client/error/hostname_unknown.rb
|
178
197
|
- lib/xclarity_client/event.rb
|
179
198
|
- lib/xclarity_client/event_management.rb
|
180
199
|
- lib/xclarity_client/fan.rb
|