class NexposeThycotic::InsightvmClient
Public Class Methods
new(host, port, user, pass, logger)
click to toggle source
# File lib/nexpose_thycotic/operations.rb, line 128 def initialize(host, port, user, pass, logger) @host = host @port = port @auth_header = {'Authorization': "Basic #{Base64.strict_encode64("#{user}:#{pass}")}"} @logger = logger end
Public Instance Methods
create_site_credential(site_id, credential)
click to toggle source
# File lib/nexpose_thycotic/operations.rb, line 229 def create_site_credential(site_id, credential) uri = URI("https://#{@host}:#{@port}/api/3/sites/#{site_id}/site_credentials") begin post(uri, credential) @logger.info("Site #{site_id} credential successfully created") rescue Exception => e @logger.error("Failed to create Site #{site_id} credential #{credential[:name]}; #{e}") end end
delete(uri, content_type = 'application/json')
click to toggle source
# File lib/nexpose_thycotic/operations.rb, line 177 def delete(uri, content_type = 'application/json') request = Net::HTTP::Delete.new(uri.request_uri, @auth_header) request.set_content_type(content_type) request(uri, request) end
delete_site_credential(site_id, credential_id)
click to toggle source
# File lib/nexpose_thycotic/operations.rb, line 196 def delete_site_credential(site_id, credential_id) uri = URI("https://#{@host}:#{@port}/api/3/sites/#{site_id}/site_credentials/#{credential_id}") begin delete(uri) @logger.info("Site #{site_id} credential removed successfully") rescue Exception => e @logger.error("Failed to remove Site #{site_id} credential; #{e}") end end
delete_site_credentials(site_id)
click to toggle source
# File lib/nexpose_thycotic/operations.rb, line 207 def delete_site_credentials(site_id) uri = URI("https://#{@host}:#{@port}/api/3/sites/#{site_id}/site_credentials") begin delete(uri) @logger.info("Site #{site_id} credentials removed successfully") rescue Exception => e @logger.error("Failed to remove Site #{site_id} credentials; #{e}") end end
get(uri, content_type = 'application/json')
click to toggle source
# File lib/nexpose_thycotic/operations.rb, line 154 def get(uri, content_type = 'application/json') request = Net::HTTP::Get.new(uri.request_uri, @auth_header) request.set_content_type(content_type) request(uri, request) end
get_site_credentials(site_id)
click to toggle source
# File lib/nexpose_thycotic/operations.rb, line 184 def get_site_credentials(site_id) uri = URI("https://#{@host}:#{@port}/api/3/sites/#{site_id}/site_credentials") begin credentials = get(uri) creds = JSON.parse(credentials) return creds["resources"] rescue Exception => e @logger.error("Failed to retrieve Site #{site_id} credentials; #{e}") end end
post(uri, payload = nil, content_type = 'application/json')
click to toggle source
# File lib/nexpose_thycotic/operations.rb, line 161 def post(uri, payload = nil, content_type = 'application/json') request = Net::HTTP::Post.new(uri.request_uri, @auth_header) request.set_content_type(content_type) request.body = payload.to_json if payload request(uri, request) end
put(uri, payload = nil, content_type = 'application/json')
click to toggle source
# File lib/nexpose_thycotic/operations.rb, line 169 def put(uri, payload = nil, content_type = 'application/json') request = Net::HTTP::Put.new(uri.request_uri, @auth_header) request.set_content_type(content_type) request.body = payload.to_json if payload request(uri, request) end
request(uri, request)
click to toggle source
# File lib/nexpose_thycotic/operations.rb, line 135 def request(uri, request) # Set up http client http = Net::HTTP.new(uri.host, uri.port) # Ignore certificate verification if using https; this is consistent with the rest of the integration if uri.scheme == "https" http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE end response = http.request(request) case response when Net::HTTPOK, Net::HTTPCreated, Net::HTTPNoContent response.body else raise Nexpose::AJAX.get_api_error(request, response) end end
update_site_credentials(site_id, credentials=[])
click to toggle source
# File lib/nexpose_thycotic/operations.rb, line 218 def update_site_credentials(site_id, credentials=[]) uri = URI("https://#{@host}:#{@port}/api/3/sites/#{site_id}/site_credentials") begin put(uri, credentials) @logger.info("Site #{site_id} updated successfully with #{credentials.length} credentials") rescue Exception => e @logger.error("Failed to update Site #{site_id} credentials; #{e}") end end