PasswordManagerPro_Gem 1.0.0

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/PasswordManagerPro_Gem.rb +111 -0
  3. metadata +49 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2773c385cb5646ba8be3158806f4df8c6f9b2693ca4fe2a431c15e46ed8cbf44
4
+ data.tar.gz: 1a123ad6c556ea296015684d139a0ddba9d2ada8cfcb57f6da4f704b1a08739e
5
+ SHA512:
6
+ metadata.gz: e0cb9be047c233b95b47a7f10083c3262ee481c2d291d7342cfb88e468488617de0fac993fcb164874d1c60a6399a6e183f3e58d8e25c14a6e41f6fc0a714550
7
+ data.tar.gz: cd538adf51608dda522319023648fd29a493e41812a5365744742b8bbfc0f56035c3268c60a304d4d13bdbe6b3b80730cf909fd9182d27f55d8d1553b4c0fd16
@@ -0,0 +1,111 @@
1
+ =begin
2
+
3
+ Copyright 2019 Password Manager Pro
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+
17
+ =end
18
+ #Auth : Somes Kumar K
19
+ require 'net/http'
20
+ require 'json'
21
+ require 'openssl'
22
+
23
+ class PasswordManagerProGem
24
+ attr_accessor :server
25
+ attr_accessor :api_key
26
+ attr_accessor :port
27
+ attr_accessor :disable_ssl
28
+ attr_accessor :baseUri
29
+ attr_accessor :ssl_certificte_path
30
+
31
+ def initialize(server, api_key, certpath = "nopath", port = 7272)
32
+ @server = server
33
+ @api_key = api_key
34
+ @port = port
35
+ @disable_ssl = false
36
+ @ssl_certificte_path = certpath
37
+ constructBaseUri()
38
+ end
39
+ protected
40
+ def constructBaseUri()
41
+ @baseUri = "https://" + @server + ":" + @port.to_s + "/restapi/json/v1/resources/"
42
+ end
43
+ def constructUri(query)
44
+ return "#{@baseUri}#{query}&APP_AUTHTOKEN=#{@api_key}"
45
+ end
46
+ def getJsonData(query)
47
+ #validate the Url
48
+ uri = URI.parse(constructUri(query))
49
+ http = Net::HTTP.new(uri.host, uri.port)
50
+ http.use_ssl = true
51
+ if(@disable_ssl)
52
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
53
+ else
54
+ if (!"nopath".eql? @ssl_certificte_path)
55
+ http.ca_file = @ssl_certificte_path
56
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
57
+ else
58
+ return throw :failure
59
+ end
60
+
61
+ end
62
+ #Getting json data
63
+ begin
64
+ jsonData = JSON.parse(http.get(uri.request_uri).body)
65
+ if(jsonData["operation"]["result"]["status"] == "Success")
66
+ return jsonData["operation"]["Details"]
67
+ else
68
+ return jsonData.throw :failure
69
+ end
70
+ raise "Exception Occured"
71
+ rescue
72
+ return [nil].to_json.throw :failure
73
+ end
74
+ end
75
+ def getResourceIdAndAccountId(resource_name,account_name)
76
+ #return reource id and account id in an array
77
+ data = self.getJsonData("getResourceIdAccountId?RESOURCENAME=#{resource_name}&ACCOUNTNAME=#{account_name}")
78
+ return data["RESOURCEID"].to_s, data["ACCOUNTID"].to_s
79
+ end
80
+ def getAccountDetailsById(resource_id,account_id)
81
+ data = self.getJsonData("getResourceAccountDetails?&RESOURCEID=#{resource_id}&ACCOUNTID=#{account_id}")
82
+ return data["RESOURCEDETAILS"],data["ACCOUNTDETAILS"]
83
+ end
84
+ def getAccountPasswordById(resource_id,account_id)
85
+ return self.getJsonData("#{resource_id}/accounts/#{account_id}/password?");
86
+ end
87
+ #-----------------------------------------------------------------------------------------------------------------------
88
+ public
89
+ def getGemInfo()
90
+ puts("This Gem is developed by Password Manager Pro\nCurrent Gem Version : 1.0.0\n
91
+ Methods and description : \n--------------------------\n")
92
+ 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")
93
+ puts(" getAccountPassword(resourceName,AccountName) : \n \t This method returns the decrypted password as String\n")
94
+ puts("-----------------------\nThis Gem is Licensed to Manage Engine Password Manager Pro\n")
95
+ puts("For further assist email to : passwordmanagerpro-support@manageengine.com ")
96
+ end
97
+ def getAccountDetails(resource_name,account_name)
98
+ #return account password as string
99
+ resource_id, account_id = self.getResourceIdAndAccountId(resource_name,account_name)
100
+ return self.getAccountDetailsById(resource_id, account_id)
101
+ end
102
+ def getAccountPassword(resource_name,account_name)
103
+ resource_id, account_id = self.getResourceIdAndAccountId(resource_name,account_name)
104
+ data = self.getAccountPasswordById(resource_id, account_id)
105
+ if(data["PASSWORD"])
106
+ return data["PASSWORD"].to_s
107
+ else
108
+ return data.throw :failure
109
+ end
110
+ end
111
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: PasswordManagerPro_Gem
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Password Manager Pro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-08-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple Password Manager Pro gem that helps you retrieve passwords from
14
+ ruby-based platforms over RestAPI.
15
+ email:
16
+ - passwordmanagerpro-support@manageengine.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/PasswordManagerPro_Gem.rb
22
+ homepage: https://www.manageengine.com/products/passwordmanagerpro
23
+ licenses:
24
+ - Apache-2.0
25
+ metadata:
26
+ documentation_uri: https://www.manageengine.com/products/passwordmanagerpro
27
+ homepage_uri: https://www.manageengine.com/products/passwordmanagerpro
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.7.6
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: A simple Password Manager Pro gem that helps you retrieve passwords for chef
48
+ and puppet platforms over RestAPI.
49
+ test_files: []