Class: XClarityClient::XClarityCredentialsValidator
- Inherits:
-
Object
- Object
- XClarityClient::XClarityCredentialsValidator
- Defined in:
- lib/xclarity_client/xclarity_credentials_validator.rb
Constant Summary collapse
- BASE_URI =
'/sessions'.freeze
Instance Method Summary collapse
- #build_session(conf) ⇒ Object
- #close_session(id_session) ⇒ Object
-
#initialize(conf) ⇒ XClarityCredentialsValidator
constructor
A new instance of XClarityCredentialsValidator.
- #validate ⇒ Object
Constructor Details
#initialize(conf) ⇒ XClarityCredentialsValidator
Returns a new instance of XClarityCredentialsValidator.
7 8 9 10 |
# File 'lib/xclarity_client/xclarity_credentials_validator.rb', line 7 def initialize(conf) @connection = XClarityClient::Connection.new(conf) @configuration = conf end |
Instance Method Details
#build_session(conf) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/xclarity_client/xclarity_credentials_validator.rb', line 35 def build_session(conf) @response = @connection.do_post(BASE_URI, { :UserId => conf.username, :password => conf.password }.to_json) raise Faraday::Error::ConnectionFailed unless @response.success? end |
#close_session(id_session) ⇒ Object
44 45 46 |
# File 'lib/xclarity_client/xclarity_credentials_validator.rb', line 44 def close_session(id_session) @connection.do_delete("#{BASE_URI}/#{id_session}") end |
#validate ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/xclarity_client/xclarity_credentials_validator.rb', line 12 def validate $lxca_log.info 'XClarityClient::XClarityValidate validate', 'Creating session ...' build_session(@configuration) id_session = JSON.parse(@response.body)['messages'].first['id'] $lxca_log.info 'XClarityClient::XClarityValidate validate', 'Session created ...' close_session(id_session) rescue => err cause = err.cause.to_s.downcase if cause.include?('connection refused') raise XClarityClient::Error::ConnectionRefused elsif cause.include?('name or service not known') raise XClarityClient::Error::HostnameUnknown elsif @response.nil? raise XClarityClient::Error::ConnectionFailed elsif @response.status == 403 raise XClarityClient::Error::AuthenticationError else raise XClarityClient::Error::ConnectionFailedUnknown.new("status #{@response.status}") end end |