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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bacb24cf31184be3d62d63db871a716c6b45cf5f
4
- data.tar.gz: fb03557be00e92bb30ee3cf3184dc2645d82334c
3
+ metadata.gz: 266a40b1f827da05891126299803c352a393f7ed
4
+ data.tar.gz: c98d7e1948b6a8f32d8dbc47af2a744a5615b9f7
5
5
  SHA512:
6
- metadata.gz: 2a0618e9dbf1e5470a784c22b45a0050d3d33fb147731a0ad0389d02d2d9a69e8a28b87e574d38ae8d5a3031c48341fc776d726a2a9c2b49b32c07cb7880ddf1
7
- data.tar.gz: 9605213a3e326437561bf5a76fcfd84505fc949fe077af7a6aba3e28c0c1fc534bfc957a1951544e0746c079ab488c3c94a9bb2b3793dded282c6fbf520cdc91
6
+ metadata.gz: acf88004bb3707fb096a613a5c7e1a66d13bbfaaef6efc882093c3056655c913f4ea5923d20862bf2b660f1eb89ab216298f135e26620c7a906e43e4f5ecbad5
7
+ data.tar.gz: b49c59dcc5a1d5bb12d1be21f7db94ad1e970ac600a468719d11f785ae1116cbc3f5a295c75b47b4e1522d6bc2b4337d3679600554741b44a439e562e02094b1
@@ -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'
@@ -202,6 +202,9 @@ module XClarityClient
202
202
  excludeAttributes,
203
203
  User)
204
204
  end
205
-
205
+
206
+ def validate_configuration
207
+ XClarityBase.new(@connection, '/')
208
+ end
206
209
  end
207
210
  end
@@ -1,9 +1,7 @@
1
- require 'securerandom'
2
-
3
1
  module XClarityClient
4
2
  class Configuration
5
3
 
6
- attr_accessor :username, :password, :host, :csrf_token, :auth_type, :generated_token, :port, :verify_ssl
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
@@ -0,0 +1,10 @@
1
+ module XClarityClient
2
+ module Error
3
+ class AuthenticationError < StandardError
4
+ def initialize(msg = nil)
5
+ msg = msg.nil? ? 'Invalid credentials for this host.' : msg
6
+ super(msg)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module XClarityClient
2
+ module Error
3
+ class ConnectionFailed < StandardError
4
+ def initialize(msg = nil)
5
+ msg = msg.nil? ? 'Execution expired or invalid port.' : msg
6
+ super(msg)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module XClarityClient
2
+ module Error
3
+ class ConnectionFailedUnknown < StandardError
4
+ def initialize(msg)
5
+ msg = "Connection failed, #{msg.nil? ? 'reason unknown' : msg}."
6
+ super(msg)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module XClarityClient
2
+ module Error
3
+ class ConnectionRefused < StandardError
4
+ def initialize(msg = nil)
5
+ msg = msg.nil? ? 'Connection refused, invalid host.' : msg
6
+ super(msg)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module XClarityClient
2
+ module Error
3
+ class HostnameUnknown < StandardError
4
+ def initialize(msg = nil)
5
+ msg = msg.nil? ? 'Connection failed, hostname unknown.' : msg
6
+ super(msg)
7
+ end
8
+ end
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module XClarityClient
2
- VERSION = "0.5.4"
2
+ VERSION = "0.5.5"
3
3
  end
@@ -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
- response = authentication(conf) unless conf.auth_type != 'token'
36
- #TODO: What's to do with the response of authentication request?
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 '/session'
78
+ request.url '/sessions'
78
79
  request.headers['Content-Type'] = 'application/json'
79
80
  request.body = {:UserId => conf.username,
80
- :password => conf.password,
81
- :heartBeatEnabled => true,
82
- :maxLostHeartBeats => 3,
83
- :csrf => conf.csrf_token}.to_json
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
@@ -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
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-08-25 00:00:00.000000000 Z
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