abiraj 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/lib/{securden → abiraj}/version.rb +1 -1
- data/lib/abiraj.rb +150 -122
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b5894ed4fd9f1f42f60427ef95452ad54a5933cd32c3454ea11a4674300946ea
|
4
|
+
data.tar.gz: e1db6072dc4c4ce90613e11502b3f138ae36f061bbc3e05fea49bdbcd20ef7de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc1147d7ee3a4dec5bb05076b055d1460a30301d851c6f5d35bb8415bf28776d7405b3da36da58e45806b2e3cbd63fcf019a266b551b67c621caf354496f3fad
|
7
|
+
data.tar.gz: a6e2dacfe433ad8c92bffe69645fa59af42f599abf0ac1d4ca240a065d2e982562af47568709381c2fc0df2ca28138991dff219161daee0d6f780f5532e150f7
|
data/lib/abiraj.rb
CHANGED
@@ -1,122 +1,150 @@
|
|
1
|
-
require "net/http"
|
2
|
-
require "json"
|
3
|
-
require
|
4
|
-
|
5
|
-
module Abiraj
|
6
|
-
class Error < StandardError; end
|
7
|
-
|
8
|
-
def self.logger(message:, level:
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class Account
|
26
|
-
def initialize(server_url:, authtoken:, org: nil, certificate: nil)
|
27
|
-
@init = false
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
1
|
+
require "net/http"
|
2
|
+
require "json"
|
3
|
+
require "openssl"
|
4
|
+
|
5
|
+
module Abiraj
|
6
|
+
class Error < StandardError; end
|
7
|
+
|
8
|
+
def self.logger(message:, level: "info")
|
9
|
+
prefix = "[Abiraj] "
|
10
|
+
message = message.to_s
|
11
|
+
puts prefix + message
|
12
|
+
case level.downcase
|
13
|
+
when "error"
|
14
|
+
Chef::Log.error(prefix + message)
|
15
|
+
nil
|
16
|
+
when "debug"
|
17
|
+
Chef::Log.debug(prefix + message)
|
18
|
+
when "warn"
|
19
|
+
Chef::Log.warn(prefix + message)
|
20
|
+
when "info"
|
21
|
+
Chef::Log.info(prefix + message)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Account
|
26
|
+
def initialize(server_url:, authtoken:, org: nil, certificate: nil)
|
27
|
+
@init = false
|
28
|
+
if server_url.nil? || authtoken.nil? || server_url.strip.empty? || authtoken.strip.empty?
|
29
|
+
logger("Server URL and authtoken are required to initialize Abiraj.", "error")
|
30
|
+
end
|
31
|
+
|
32
|
+
unless server_url.start_with?("http://", "https://")
|
33
|
+
logger("Invalid server URL. It must start with http:// or https://", "error")
|
34
|
+
return
|
35
|
+
end
|
36
|
+
@server_url = server_url.strip
|
37
|
+
@authtoken = authtoken.strip
|
38
|
+
@org = org&.strip
|
39
|
+
if certificate
|
40
|
+
@certificate = certificate
|
41
|
+
end
|
42
|
+
@init = true
|
43
|
+
logger("Abiraj initialized successfully.")
|
44
|
+
end
|
45
|
+
|
46
|
+
def get(account_id: nil, account_name: nil, account_title: nil)
|
47
|
+
if !@init
|
48
|
+
logger("Abiraj is not initialized.", "error")
|
49
|
+
return
|
50
|
+
end
|
51
|
+
logger("Fetching account data.")
|
52
|
+
params = {}
|
53
|
+
params["account_id"] = account_id.to_s if account_id
|
54
|
+
params["account_name"] = account_name unless account_name.to_s.strip.empty?
|
55
|
+
params["account_title"] = account_title unless account_title.to_s.strip.empty?
|
56
|
+
account_data = get_request(params, "/api/get_account_details_dict")
|
57
|
+
if account_data
|
58
|
+
logger("Account data fetched successfully.")
|
59
|
+
return account_data
|
60
|
+
else
|
61
|
+
logger("Unable to fetch account data.", "error")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def logger(message, level = "info")
|
68
|
+
Abiraj.logger(message: message, level: level)
|
69
|
+
if level == "error"
|
70
|
+
return nil
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_request(params, endpoint)
|
75
|
+
logger("Raising API request to Abiraj server.")
|
76
|
+
|
77
|
+
uri = URI(@server_url + endpoint)
|
78
|
+
uri.query = URI.encode_www_form(params) unless params.empty?
|
79
|
+
http = set_http(uri)
|
80
|
+
request = Net::HTTP::Get.new(uri)
|
81
|
+
request["authtoken"] = @authtoken
|
82
|
+
if @org && !@org.strip.empty?
|
83
|
+
request["org"] = @org
|
84
|
+
end
|
85
|
+
begin
|
86
|
+
response = http.request(request)
|
87
|
+
if response.code.to_i == 200
|
88
|
+
JSON.parse(response.body)
|
89
|
+
else
|
90
|
+
logger("Unexpected response code #{response.code}: #{response.body}", "error")
|
91
|
+
end
|
92
|
+
rescue JSON::ParserError => e
|
93
|
+
logger("Failed to parse JSON response: #{e.message}", "error")
|
94
|
+
rescue StandardError => e
|
95
|
+
logger("HTTP request failed: #{e.message}", "error")
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def set_http(uri)
|
100
|
+
begin
|
101
|
+
logger("Setting up HTTP connection.")
|
102
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
103
|
+
http.use_ssl = uri.scheme == "https"
|
104
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
105
|
+
http = set_ssl(http)
|
106
|
+
return http
|
107
|
+
rescue StandardError => e
|
108
|
+
logger("Failed to set HTTP connection: #{e.message}", "error")
|
109
|
+
return nil
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def set_ssl(http)
|
114
|
+
begin
|
115
|
+
if @server_url.start_with?("https://") && @certificate
|
116
|
+
logger("Setting SSL connection with certificate.")
|
117
|
+
|
118
|
+
if @certificate.start_with?("-----BEGIN CERTIFICATE-----")
|
119
|
+
logger("Binding certificate value.")
|
120
|
+
|
121
|
+
cert_object = OpenSSL::X509::Certificate.new(@certificate)
|
122
|
+
http.cert_store = OpenSSL::X509::Store.new
|
123
|
+
http.cert_store.add_cert(cert_object)
|
124
|
+
|
125
|
+
elsif File.exist?(@certificate)
|
126
|
+
logger("Binding certificate file.")
|
127
|
+
http.ca_file = @certificate
|
128
|
+
|
129
|
+
else
|
130
|
+
logger("Invalid certificate content or file path.", "error")
|
131
|
+
return nil
|
132
|
+
end
|
133
|
+
|
134
|
+
elsif @server_url.start_with?("https://") && !@certificate
|
135
|
+
logger("Disabling SSL verification. Certificate required for SSL secure connection", "warn")
|
136
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
137
|
+
end
|
138
|
+
|
139
|
+
return http
|
140
|
+
|
141
|
+
rescue OpenSSL::X509::CertificateError => e
|
142
|
+
logger("Invalid certificate format: #{e.message}", "error")
|
143
|
+
return nil
|
144
|
+
rescue StandardError => e
|
145
|
+
logger("Failed to set SSL connection: #{e.message}", "error")
|
146
|
+
return nil
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: abiraj
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Abiraj
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: This plugin sends a GET request to an API to fetch account data (passwords,
|
14
14
|
etc.) based on the account ID, name, and title.
|
@@ -19,11 +19,11 @@ extensions: []
|
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
21
|
- lib/abiraj.rb
|
22
|
-
- lib/
|
23
|
-
homepage:
|
22
|
+
- lib/abiraj/version.rb
|
23
|
+
homepage:
|
24
24
|
licenses: []
|
25
25
|
metadata: {}
|
26
|
-
post_install_message:
|
26
|
+
post_install_message:
|
27
27
|
rdoc_options: []
|
28
28
|
require_paths:
|
29
29
|
- lib
|
@@ -38,8 +38,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '0'
|
40
40
|
requirements: []
|
41
|
-
rubygems_version: 3.
|
42
|
-
signing_key:
|
41
|
+
rubygems_version: 3.5.23
|
42
|
+
signing_key:
|
43
43
|
specification_version: 4
|
44
44
|
summary: Abiraj Chef plugin tool to extend and securely manage secrets and credential.
|
45
45
|
test_files: []
|