class PasswordManagerProGem
Attributes
api_key[RW]
baseUri[RW]
disable_ssl[RW]
port[RW]
server[RW]
ssl_certificte_path[RW]
Public Class Methods
new(server, api_key, certpath = "nopath", port = 7272)
click to toggle source
# File lib/PasswordManagerPro_Gem.rb, line 31 def initialize(server, api_key, certpath = "nopath", port = 7272) @server = server @api_key = api_key @port = port @disable_ssl = false @ssl_certificte_path = certpath constructBaseUri() end
Public Instance Methods
getAccountDetails(resource_name,account_name)
click to toggle source
# File lib/PasswordManagerPro_Gem.rb, line 97 def getAccountDetails(resource_name,account_name) #return account password as string resource_id, account_id = self.getResourceIdAndAccountId(resource_name,account_name) return self.getAccountDetailsById(resource_id, account_id) end
getAccountPassword(resource_name,account_name)
click to toggle source
# File lib/PasswordManagerPro_Gem.rb, line 102 def getAccountPassword(resource_name,account_name) resource_id, account_id = self.getResourceIdAndAccountId(resource_name,account_name) data = self.getAccountPasswordById(resource_id, account_id) if(data["PASSWORD"]) return data["PASSWORD"].to_s else return data.throw :failure end end
getGemInfo()
click to toggle source
# File lib/PasswordManagerPro_Gem.rb, line 89 def getGemInfo() puts("This Gem is developed by Password Manager Pro\nCurrent Gem Version : 1.0.0\n Methods and description : \n--------------------------\n") puts(" getAccountDetails(resourceName,AccountName) : \n \t This method returns array of JSON variables , the [0] has resource details and [1] has account details and its password \n") puts(" getAccountPassword(resourceName,AccountName) : \n \t This method returns the decrypted password as String\n") puts("-----------------------\nThis Gem is Licensed to Manage Engine Password Manager Pro\n") puts("For further assist email to : passwordmanagerpro-support@manageengine.com ") end
Protected Instance Methods
constructBaseUri()
click to toggle source
# File lib/PasswordManagerPro_Gem.rb, line 40 def constructBaseUri() @baseUri = "https://" + @server + ":" + @port.to_s + "/restapi/json/v1/resources/" end
constructUri(query)
click to toggle source
# File lib/PasswordManagerPro_Gem.rb, line 43 def constructUri(query) return "#{@baseUri}#{query}&APP_AUTHTOKEN=#{@api_key}" end
getAccountDetailsById(resource_id,account_id)
click to toggle source
# File lib/PasswordManagerPro_Gem.rb, line 80 def getAccountDetailsById(resource_id,account_id) data = self.getJsonData("getResourceAccountDetails?&RESOURCEID=#{resource_id}&ACCOUNTID=#{account_id}") return data["RESOURCEDETAILS"],data["ACCOUNTDETAILS"] end
getAccountPasswordById(resource_id,account_id)
click to toggle source
# File lib/PasswordManagerPro_Gem.rb, line 84 def getAccountPasswordById(resource_id,account_id) return self.getJsonData("#{resource_id}/accounts/#{account_id}/password?"); end
getJsonData(query)
click to toggle source
# File lib/PasswordManagerPro_Gem.rb, line 46 def getJsonData(query) #validate the Url uri = URI.parse(constructUri(query)) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true if(@disable_ssl) http.verify_mode = OpenSSL::SSL::VERIFY_NONE else if (!"nopath".eql? @ssl_certificte_path) http.ca_file = @ssl_certificte_path http.verify_mode = OpenSSL::SSL::VERIFY_PEER else return throw :failure end end #Getting json data begin jsonData = JSON.parse(http.get(uri.request_uri).body) if(jsonData["operation"]["result"]["status"] == "Success") return jsonData["operation"]["Details"] else return jsonData.throw :failure end raise "Exception Occured" rescue return [nil].to_json.throw :failure end end
getResourceIdAndAccountId(resource_name,account_name)
click to toggle source
# File lib/PasswordManagerPro_Gem.rb, line 75 def getResourceIdAndAccountId(resource_name,account_name) #return reource id and account id in an array data = self.getJsonData("getResourceIdAccountId?RESOURCENAME=#{resource_name}&ACCOUNTNAME=#{account_name}") return data["RESOURCEID"].to_s, data["ACCOUNTID"].to_s end