xclarity_client 0.5.6 → 0.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: afa0735b197e5c93de96e83bf43e52a5466e91ed
4
- data.tar.gz: 080e6f25bc575688bab8820dea1a5622ebaff067
3
+ metadata.gz: dc0c90ab2b83fd6fefcfe489a3f5080e9184550b
4
+ data.tar.gz: a3eb16607e4d725e2c6b838c8e1527b79f3dca0d
5
5
  SHA512:
6
- metadata.gz: 7b40d1b4d99e95daa833cc6af168f5807ffc12912f3116d64ac61709ed182a783ba29d8344b39943b9b5271441a143b48a960ec47aba89e6ce9161e373b83e55
7
- data.tar.gz: 0840c8a10ad6578aaf3192c7ff373938cc8ff866643436659d355be74fbd76f153d989e5eb45031ae0470b8eb3db3a76d0150cb57f7903bbe04a8bff8c5843f5
6
+ metadata.gz: 340aa4f91681ca8092346c54851a4bb145004e135a69305dfb4d541f1875c4f114637dba5632df59a8945660e5a0f3f59ab3a33f1300799ed86742cb4df6d891
7
+ data.tar.gz: 8d27a026b294d34a1ae45e57894b2e9f16d0c5a0aff6e7e230d25c6d708e91684ff61cd1b7b60cc79bc8cc64a5e618eed507bcbf9e3c8d50b3d2eac36f618d57
data/example/simple.rb CHANGED
@@ -6,7 +6,8 @@ conf = XClarityClient::Configuration.new(
6
6
  :host => '',
7
7
  :port => '',
8
8
  :auth_type => '',
9
- :verify_ssl => ''
9
+ :verify_ssl => '',
10
+ :user_agent_label => ''
10
11
  )
11
12
 
12
13
  # virtual_appliance = XClarityClient::VirtualApplianceManagement.new(conf)
@@ -276,7 +276,7 @@ module XClarityClient
276
276
  end
277
277
 
278
278
  def validate_configuration
279
- XClarityBase.new(@connection, '/')
279
+ XClarityCredentialsValidator.new(@connection).validate
280
280
  end
281
281
  end
282
282
  end
@@ -1,7 +1,7 @@
1
1
  module XClarityClient
2
2
  class Configuration
3
3
 
4
- attr_accessor :username, :password, :host, :auth_type, :port, :verify_ssl
4
+ attr_accessor :username, :password, :host, :auth_type, :port, :verify_ssl, :user_agent_label
5
5
 
6
6
  def initialize(args)
7
7
 
@@ -1,3 +1,3 @@
1
1
  module XClarityClient
2
- VERSION = "0.5.6"
2
+ VERSION = "0.5.7"
3
3
  end
@@ -1,6 +1,5 @@
1
1
  require 'faraday'
2
2
  require 'faraday-cookie_jar'
3
- require 'json'
4
3
  require 'uri'
5
4
  require 'uri/https'
6
5
 
@@ -32,9 +31,8 @@ module XClarityClient
32
31
  faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
33
32
  faraday.ssl[:verify] = conf.verify_ssl == 'PEER'
34
33
  end
35
-
36
- authentication(conf) if conf.auth_type == 'token'
37
-
34
+
35
+ @conn.headers[:user_agent] = "LXCA via Ruby Client/#{XClarityClient::VERSION}" + (conf.user_agent_label.nil? ? "" : " (#{conf.user_agent_label})")
38
36
  @conn.basic_auth(conf.username, conf.password) if conf.auth_type == 'basic_auth'
39
37
  $lxca_log.info "XClarityClient::XclarityBase connection_builder", "Connection created Successfuly"
40
38
  @conn
@@ -86,31 +84,5 @@ module XClarityClient
86
84
  req.headers['Content-Type'] = 'application/json'
87
85
  end
88
86
  end
89
-
90
- def authentication(conf)
91
- response = @conn.post do |request|
92
- request.url '/sessions'
93
- request.headers['Content-Type'] = 'application/json'
94
- request.body = {:UserId => conf.username,
95
- :password => conf.password}.to_json
96
- end
97
- if not response.success?
98
- raise Faraday::Error::ConnectionFailed
99
- end
100
-
101
- rescue => err
102
- cause = err.cause.to_s.downcase
103
- if cause.include?('connection refused')
104
- raise XClarityClient::Error::ConnectionRefused
105
- elsif cause.include?('name or service not known')
106
- raise XClarityClient::Error::HostnameUnknown
107
- elsif response.nil?
108
- raise XClarityClient::Error::ConnectionFailed
109
- elsif response.status == 403
110
- raise XClarityClient::Error::AuthenticationError
111
- else
112
- raise XClarityClient::Error::ConnectionFailedUnknown.new("status #{response.status}")
113
- end
114
- end
115
87
  end
116
88
  end
@@ -0,0 +1,51 @@
1
+ require 'json'
2
+
3
+ module XClarityClient
4
+ class XClarityCredentialsValidator < XClarityBase
5
+ BASE_URI = '/sessions'.freeze
6
+
7
+ def initialize(conf)
8
+ super(conf, BASE_URI)
9
+ @configuration = conf
10
+ end
11
+
12
+ def validate
13
+ $lxca_log.info 'XClarityClient::XClarityValidate validate', 'Creating session ...'
14
+ build_session(@configuration)
15
+
16
+ id_session = JSON.parse(@response.body)['messages'].first['id']
17
+ $lxca_log.info 'XClarityClient::XClarityValidate validate', 'Session created ...'
18
+
19
+ close_session(id_session)
20
+ rescue => err
21
+ cause = err.cause.to_s.downcase
22
+ if cause.include?('connection refused')
23
+ raise XClarityClient::Error::ConnectionRefused
24
+ elsif cause.include?('name or service not known')
25
+ raise XClarityClient::Error::HostnameUnknown
26
+ elsif @response.nil?
27
+ raise XClarityClient::Error::ConnectionFailed
28
+ elsif @response.status == 403
29
+ raise XClarityClient::Error::AuthenticationError
30
+ else
31
+ raise XClarityClient::Error::ConnectionFailedUnknown.new("status #{@response.status}")
32
+ end
33
+ end
34
+
35
+ def build_session(conf)
36
+ @response = @conn.post do |request|
37
+ request.headers['Content-Type'] = 'application/json'
38
+ request.body = { :UserId => conf.username,
39
+ :password => conf.password }.to_json
40
+ end
41
+ raise Faraday::Error::ConnectionFailed unless @response.success?
42
+ end
43
+
44
+ def close_session(id_session)
45
+ @conn.delete do |request|
46
+ request.url "#{BASE_URI}/#{id_session}"
47
+ request.headers['Content-Type'] = 'application/json'
48
+ end
49
+ end
50
+ end
51
+ end
@@ -10,6 +10,7 @@ require 'xclarity_client/xclarity_base'
10
10
  require 'xclarity_client/xclarity_resource'
11
11
  require 'xclarity_client/xclarity_management_mixin'
12
12
  require 'xclarity_client/xclarity_power_management_mixin'
13
+ require 'xclarity_client/xclarity_credentials_validator'
13
14
  require 'xclarity_client/virtual_appliance_management'
14
15
  require 'xclarity_client/node'
15
16
  require 'xclarity_client/node_management'
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.6
4
+ version: 0.5.7
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-10-09 00:00:00.000000000 Z
12
+ date: 2017-10-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -228,6 +228,7 @@ files:
228
228
  - lib/xclarity_client/version.rb
229
229
  - lib/xclarity_client/virtual_appliance_management.rb
230
230
  - lib/xclarity_client/xclarity_base.rb
231
+ - lib/xclarity_client/xclarity_credentials_validator.rb
231
232
  - lib/xclarity_client/xclarity_management_mixin.rb
232
233
  - lib/xclarity_client/xclarity_power_management_mixin.rb
233
234
  - lib/xclarity_client/xclarity_resource.rb