xclarity_client 0.5.6 → 0.5.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/example/simple.rb +2 -1
- data/lib/xclarity_client/client.rb +1 -1
- data/lib/xclarity_client/configuration.rb +1 -1
- data/lib/xclarity_client/version.rb +1 -1
- data/lib/xclarity_client/xclarity_base.rb +2 -30
- data/lib/xclarity_client/xclarity_credentials_validator.rb +51 -0
- data/lib/xclarity_client.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc0c90ab2b83fd6fefcfe489a3f5080e9184550b
|
4
|
+
data.tar.gz: a3eb16607e4d725e2c6b838c8e1527b79f3dca0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 340aa4f91681ca8092346c54851a4bb145004e135a69305dfb4d541f1875c4f114637dba5632df59a8945660e5a0f3f59ab3a33f1300799ed86742cb4df6d891
|
7
|
+
data.tar.gz: 8d27a026b294d34a1ae45e57894b2e9f16d0c5a0aff6e7e230d25c6d708e91684ff61cd1b7b60cc79bc8cc64a5e618eed507bcbf9e3c8d50b3d2eac36f618d57
|
data/example/simple.rb
CHANGED
@@ -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
|
-
|
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
|
data/lib/xclarity_client.rb
CHANGED
@@ -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.
|
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-
|
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
|