storedsafe 0.0.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 +7 -0
- data/LICENSE +201 -0
- data/README.md +3 -0
- data/lib/storedsafe.rb +22 -0
- data/lib/storedsafe/api.rb +113 -0
- data/lib/storedsafe/api/auth.rb +63 -0
- data/lib/storedsafe/api/objects.rb +79 -0
- data/lib/storedsafe/api/templates.rb +23 -0
- data/lib/storedsafe/api/vaults.rb +62 -0
- data/lib/storedsafe/config.rb +49 -0
- data/lib/storedsafe/config/configurable.rb +14 -0
- data/lib/storedsafe/config/env_reader.rb +34 -0
- data/lib/storedsafe/config/rc_reader.rb +48 -0
- data/lib/storedsafe/parser.rb +9 -0
- data/lib/storedsafe/parser/raw_parser.rb +20 -0
- metadata +57 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ed587808626883a211cda1842c737f3ca31354e99ab76b3fb173ee202a4b0090
|
4
|
+
data.tar.gz: c7ffc7a27d41c6a0cf3833ce3d4630745a6390f817a3b328ea7660b4429836a7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 835ba721f4fdfe1692fdeb5c8f42d50c4cdf60edeb5c30254c1d4f664b566bea5338081278dc9ab3587c8fb62aac648b097bbdec003e78c5a51b6f960ac2fe0d
|
7
|
+
data.tar.gz: b81917058e9c348d0c7f75cc35711354510b7cc8c9dafc606836a8a00926f8e427a8d397c3b5b63b365dfbdf9699db1f681a44e1d425849fb4d77d450e282710
|
data/LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright {yyyy} {name of copyright owner}
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
data/README.md
ADDED
data/lib/storedsafe.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
##
|
4
|
+
# Ruby wrapper for the Storedsafe RESTlike API.
|
5
|
+
module Storedsafe
|
6
|
+
class << self
|
7
|
+
require 'storedsafe/api'
|
8
|
+
require 'storedsafe/config'
|
9
|
+
require 'storedsafe/parser'
|
10
|
+
|
11
|
+
##
|
12
|
+
# Set up a new API instance configured to communicate with your Storedsafe
|
13
|
+
# server.
|
14
|
+
# @see Storedsafe::Config::Configurable for more information about the
|
15
|
+
# available fields for configuration.
|
16
|
+
def configure
|
17
|
+
API.new do |api|
|
18
|
+
yield api if block_given?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require 'openssl'
|
5
|
+
require 'json'
|
6
|
+
|
7
|
+
require 'storedsafe/config'
|
8
|
+
|
9
|
+
require_relative 'api/auth'
|
10
|
+
require_relative 'api/objects'
|
11
|
+
require_relative 'api/vaults'
|
12
|
+
require_relative 'api/templates'
|
13
|
+
|
14
|
+
module Storedsafe
|
15
|
+
##
|
16
|
+
# Contains all interaction and configuration relating to the remote API.
|
17
|
+
class API
|
18
|
+
include Storedsafe::Config::Configurable
|
19
|
+
|
20
|
+
##
|
21
|
+
# Supported Login Types
|
22
|
+
module LoginType
|
23
|
+
YUBIKEY = 'yubikey' # HOTP with Yubico YubiKey device
|
24
|
+
TOTP = 'totp' # Time-Based OTP using Authenticator
|
25
|
+
SMARTCARD = 'smc_rest' # Smartcard
|
26
|
+
end
|
27
|
+
|
28
|
+
##
|
29
|
+
# Creates a new API handler with the passed configuration,
|
30
|
+
# then allocates remaining uninitialized values with values from
|
31
|
+
# alternate sources.
|
32
|
+
# @see Storedsafe::Config
|
33
|
+
def initialize
|
34
|
+
yield self
|
35
|
+
Config.apply(self)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
##
|
41
|
+
# Sends a request to the StoredSafe API.
|
42
|
+
# @param [String] method HTTP method used for request.
|
43
|
+
# @param [String] path Endpoint path relative to the API
|
44
|
+
# root on the server.
|
45
|
+
# @param [Hash] params Data to be sent with the request.
|
46
|
+
def request(method, path, params)
|
47
|
+
url = "https://#{@server}/api/#{@api_version}#{path}"
|
48
|
+
uri = URI.parse(url)
|
49
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
50
|
+
http.use_ssl = true
|
51
|
+
|
52
|
+
assign_verify_mode(http)
|
53
|
+
request = create_request(method, uri, params)
|
54
|
+
|
55
|
+
http.request(request) if request
|
56
|
+
end
|
57
|
+
|
58
|
+
def assign_verify_mode(http)
|
59
|
+
if @skip_verify
|
60
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
61
|
+
else
|
62
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
63
|
+
http.ca_path = @ca_path if @ca_path
|
64
|
+
http.verify_depth = 5
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def create_request(method, uri, params)
|
69
|
+
case method
|
70
|
+
when :get
|
71
|
+
create_get_request(uri, params)
|
72
|
+
when :post
|
73
|
+
create_post_request(uri, params)
|
74
|
+
when :delete
|
75
|
+
create_delete_request(uri, params)
|
76
|
+
when :put
|
77
|
+
create_put_request(uri, params)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def create_get_request(uri, params)
|
82
|
+
uri.query = URI.encode_www_form(params)
|
83
|
+
request = Net::HTTP::Get.new(uri)
|
84
|
+
request
|
85
|
+
end
|
86
|
+
|
87
|
+
def create_delete_request(uri, params)
|
88
|
+
headers = { 'Content-Type': 'application/json' }
|
89
|
+
request = Net::HTTP::Delete.new(uri, headers)
|
90
|
+
request.body = params.to_json
|
91
|
+
request
|
92
|
+
end
|
93
|
+
|
94
|
+
def create_post_request(uri, params)
|
95
|
+
headers = { 'Content-Type': 'application/json' }
|
96
|
+
request = Net::HTTP::Post.new(uri, headers)
|
97
|
+
request.body = params.to_json
|
98
|
+
request
|
99
|
+
end
|
100
|
+
|
101
|
+
def create_put_request(uri, params)
|
102
|
+
headers = { 'Content-Type': 'application/json' }
|
103
|
+
request = Net::HTTP::Put.new(uri, headers)
|
104
|
+
request.body = params.to_json
|
105
|
+
request
|
106
|
+
end
|
107
|
+
|
108
|
+
def parse_body(response)
|
109
|
+
body = response.body
|
110
|
+
@parser.parse_response(body)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Storedsafe
|
4
|
+
##
|
5
|
+
# Handles API requests to the /auth path.
|
6
|
+
class API
|
7
|
+
##
|
8
|
+
# Authenticates a user with a Yubico OTP.
|
9
|
+
# @param [String] passphrase
|
10
|
+
# @param [String] otp Yubikey press
|
11
|
+
# @see authenticate Authentication with other OTP types.
|
12
|
+
def authenticate_yubikey(passphrase, otp)
|
13
|
+
res = request(
|
14
|
+
:post, '/auth',
|
15
|
+
username: @username, keys: "#{passphrase}#{@api_key}#{otp}"
|
16
|
+
)
|
17
|
+
data = parse_body(res)
|
18
|
+
@token = data['CALLINFO']['token']
|
19
|
+
data
|
20
|
+
end
|
21
|
+
|
22
|
+
# rubocop:disable Metrics/MethodLength
|
23
|
+
|
24
|
+
##
|
25
|
+
# Authenticates a user with specified OTP method.
|
26
|
+
# @param [String] passphrase
|
27
|
+
# @param [String] otp One-time password
|
28
|
+
# @param [String] logintype See Storedsafe::API::LoginType
|
29
|
+
def authenticate(passphrase, otp, logintype = LoginType::TOTP)
|
30
|
+
if logintype == LoginType::YUBIKEY
|
31
|
+
return authenticate_yubikey(passphrase, otp)
|
32
|
+
end
|
33
|
+
|
34
|
+
res = request(
|
35
|
+
:post, '/auth',
|
36
|
+
username: @username, passphrase: passphrase, otp: otp,
|
37
|
+
apikey: @api_key, logintype: logintype
|
38
|
+
)
|
39
|
+
data = parse_body(res)
|
40
|
+
@token = data['CALLINFO']['token']
|
41
|
+
data
|
42
|
+
end
|
43
|
+
|
44
|
+
# rubocop:enable Metrics/MethodLength
|
45
|
+
|
46
|
+
##
|
47
|
+
# Invalidates the token.
|
48
|
+
def logout
|
49
|
+
res = request(:get, '/auth/logout', token: @token)
|
50
|
+
data = parse_body(res)
|
51
|
+
@token = nil if data['CALLINFO']['status'] == 'SUCCESS'
|
52
|
+
data
|
53
|
+
end
|
54
|
+
|
55
|
+
##
|
56
|
+
# Checks whether or not the token is valid and refreshes the
|
57
|
+
# timeout for that token if valid.
|
58
|
+
def check
|
59
|
+
res = request(:get, '/auth/check', token: @token)
|
60
|
+
parse_body(res)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Storedsafe
|
4
|
+
##
|
5
|
+
# Handles API requests to the /object path.
|
6
|
+
class API
|
7
|
+
# rubocop:disable Metrics/ParameterLists
|
8
|
+
|
9
|
+
##
|
10
|
+
# Lists all information regarding an object and optionally decrypts
|
11
|
+
# encrypted fields.
|
12
|
+
# @param [Integer] object_id
|
13
|
+
# @param [Boolean] decrypt
|
14
|
+
def object(object_id, decrypt = false)
|
15
|
+
res = request(
|
16
|
+
:get, "/object/#{object_id}", token: @token, decrypt: decrypt
|
17
|
+
)
|
18
|
+
parse_body(res)
|
19
|
+
end
|
20
|
+
|
21
|
+
##
|
22
|
+
# Creates a new object in an existing vault.
|
23
|
+
# @param [Integer] template_id See Storedsafe::API#list_templates.
|
24
|
+
# @param [Integer] group_id Vault ID.
|
25
|
+
# @param [Integer] parent_id ID of parent Object.
|
26
|
+
# @param [String] object_name
|
27
|
+
# @param [Hash] template_args See Storedsafe::API#list_templates.
|
28
|
+
def create_object(
|
29
|
+
template_id, group_id, parent_id, object_name, template_args
|
30
|
+
)
|
31
|
+
res = request(
|
32
|
+
:post, '/object', {
|
33
|
+
token: @token, templateid: template_id, groupid: group_id,
|
34
|
+
parentid: parent_id, objectname: object_name
|
35
|
+
}.merge(template_args)
|
36
|
+
)
|
37
|
+
parse_body(res)
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# Edits an existing object.
|
42
|
+
# @param [Integer] object_id Object to edit.
|
43
|
+
# @param [Integer] template_id See Storedsafe::API#list_templates.
|
44
|
+
# @param [Integer] group_id Vault ID.
|
45
|
+
# @param [Integer] parent_id ID of parent Object.
|
46
|
+
# @param [String] object_name New Object name.
|
47
|
+
# @param [Hash] template_args New Object values,
|
48
|
+
# see Storedsafe::API#list_templates.
|
49
|
+
def edit_object(
|
50
|
+
object_id, template_id, group_id, parent_id, object_name, template_args
|
51
|
+
)
|
52
|
+
res = request(
|
53
|
+
:put, "/object/#{object_id}", {
|
54
|
+
token: @token, templateid: template_id, groupid: group_id,
|
55
|
+
parentid: parent_id, objectname: object_name
|
56
|
+
}.merge(template_args)
|
57
|
+
)
|
58
|
+
parse_body(res)
|
59
|
+
end
|
60
|
+
|
61
|
+
##
|
62
|
+
# Deletes an existing object.
|
63
|
+
# @param [Integer] object_id
|
64
|
+
def delete_object(object_id)
|
65
|
+
res = request(:delete, "/object/#{object_id}", token: @token)
|
66
|
+
parse_body(res)
|
67
|
+
end
|
68
|
+
|
69
|
+
##
|
70
|
+
# Search in unencrypted data to find Objects.
|
71
|
+
# @param [String] needle String to match Objects with.
|
72
|
+
def find_object(needle)
|
73
|
+
res = request(:get, '/find', token: @token, needle: needle)
|
74
|
+
parse_body(res)
|
75
|
+
end
|
76
|
+
|
77
|
+
# rubocop:enable Metrics/ParameterLists
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Storedsafe
|
4
|
+
##
|
5
|
+
# Handles API requests to the /template path.
|
6
|
+
class API
|
7
|
+
##
|
8
|
+
# Obtains a list with information about all available templates.
|
9
|
+
def list_templates
|
10
|
+
res = request(:get, '/template', token: @token)
|
11
|
+
parse_body(res)
|
12
|
+
end
|
13
|
+
|
14
|
+
##
|
15
|
+
# Obtains information about the specified template.
|
16
|
+
# @param [Integer] template_id
|
17
|
+
# @see list_templates
|
18
|
+
def retrieve_template(template_id)
|
19
|
+
res = request(:get, "/template/#{template_id}", token: @token)
|
20
|
+
parse_body(res)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Storedsafe
|
4
|
+
##
|
5
|
+
# Handles API requests to the /vault path.
|
6
|
+
class API
|
7
|
+
##
|
8
|
+
# Lists all Vaults associated with the logged in user.
|
9
|
+
def list_vaults
|
10
|
+
res = request(:get, '/vault', token: @token)
|
11
|
+
parse_body(res)
|
12
|
+
end
|
13
|
+
|
14
|
+
##
|
15
|
+
# Lists all objects within the specified Vault.
|
16
|
+
# @param [Integer] vault_id
|
17
|
+
# @see list_vaults
|
18
|
+
def list_objects(vault_id)
|
19
|
+
res = request(:get, "/vault/#{vault_id}", token: @token)
|
20
|
+
parse_body(res)
|
21
|
+
end
|
22
|
+
|
23
|
+
##
|
24
|
+
# Creates an empty Vault, setting current user as "Data Custodian".
|
25
|
+
# Requires the authenticated user to have the "Create Vault" capability.
|
26
|
+
# @param [String] groupname Name of Vault.
|
27
|
+
# @param [Integer] policy Password policy.
|
28
|
+
# @param [String] description
|
29
|
+
def create_vault(groupname, policy, description)
|
30
|
+
res = request(
|
31
|
+
:post, '/vault',
|
32
|
+
token: @token,
|
33
|
+
groupname: groupname, policy: policy, description: description
|
34
|
+
)
|
35
|
+
parse_body(res)
|
36
|
+
end
|
37
|
+
|
38
|
+
##
|
39
|
+
# Changes information about an existing Vault using the optional
|
40
|
+
# parameters passed in the last argument Hash.
|
41
|
+
# @param [Integer] vault_id
|
42
|
+
# @param [Hash] args
|
43
|
+
# @option args [String] groupname New name of Vault
|
44
|
+
# @option args [Integer] policy New password policy
|
45
|
+
# @option args [String] description New Vault description.
|
46
|
+
def edit_vault(vault_id, args)
|
47
|
+
res = request(:put, "/vault/#{vault_id}", { token: @token }.merge(args))
|
48
|
+
parse_body(res)
|
49
|
+
end
|
50
|
+
|
51
|
+
##
|
52
|
+
# Deletes an existing Vault.
|
53
|
+
# Requires the vault to be empty and the authenticated user to have the
|
54
|
+
# "Create Vault" capability as well as being "Data Custodian" for the
|
55
|
+
# specified Vault.
|
56
|
+
# @param [Integer] vault_id
|
57
|
+
def delete_vault(vault_id)
|
58
|
+
res = request(:delete, "/vault/#{vault_id}", token: @token)
|
59
|
+
parse_body(res)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'storedsafe/parser/raw_parser'
|
4
|
+
|
5
|
+
require_relative 'config/configurable'
|
6
|
+
require_relative 'config/rc_reader'
|
7
|
+
require_relative 'config/env_reader'
|
8
|
+
|
9
|
+
module Storedsafe
|
10
|
+
##
|
11
|
+
# Contains modules and classes related to parsing configuration sources and
|
12
|
+
# merging said configurations into an object including the Configurable mixin.
|
13
|
+
# @see Storedsafe::Config::Configurable for more information about the
|
14
|
+
# available fields for configuration.
|
15
|
+
module Config
|
16
|
+
# Default configuration values
|
17
|
+
DEFAULTS = {
|
18
|
+
config_sources: [
|
19
|
+
RcReader.new(File.join(Dir.home, '.storedsafe-client.rc')),
|
20
|
+
EnvReader.new
|
21
|
+
],
|
22
|
+
api_version: '1.0',
|
23
|
+
parser: Parser::RawParser
|
24
|
+
}.freeze
|
25
|
+
|
26
|
+
##
|
27
|
+
# Allocate uninitialized values in a configurable object with
|
28
|
+
# values from environment variables or an RC-file.
|
29
|
+
# @param [Storedsafe::Config::Configurable] configurable
|
30
|
+
def self.apply(configurable)
|
31
|
+
apply_config(configurable, DEFAULTS)
|
32
|
+
|
33
|
+
configurable.config_sources.each do |source|
|
34
|
+
apply_config(configurable, source.read)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.apply_config(configurable, config)
|
39
|
+
config.each do |key, val|
|
40
|
+
key = "@#{key}"
|
41
|
+
if configurable.instance_variable_get(key).nil?
|
42
|
+
configurable.instance_variable_set(key, val)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private_class_method :apply_config
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Storedsafe
|
4
|
+
module Config
|
5
|
+
##
|
6
|
+
# Set up fields needed for configuration of Storedsafe connection.
|
7
|
+
module Configurable
|
8
|
+
attr_accessor(
|
9
|
+
:server, :token, :ca_bundle, :skip_verify, :config_sources,
|
10
|
+
:username, :api_key, :api_version, :parser
|
11
|
+
)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Storedsafe
|
4
|
+
module Config
|
5
|
+
##
|
6
|
+
# Reads configuration items from environment variables.
|
7
|
+
class EnvReader
|
8
|
+
attr_reader :config
|
9
|
+
|
10
|
+
##
|
11
|
+
# Read configuration from environment variables.
|
12
|
+
# @param [Hash] fields Mapping from configuration field to environment
|
13
|
+
# variable name.
|
14
|
+
def initialize(fields = {
|
15
|
+
server: 'STOREDSAFE_SERVER',
|
16
|
+
token: 'STOREDSAFE_TOKEN',
|
17
|
+
ca_bundle: 'STOREDSAFE_CABUNDLE',
|
18
|
+
skip_verify: 'STOREDSAFE_SKIP_VERIFY'
|
19
|
+
})
|
20
|
+
@fields = fields
|
21
|
+
@config = {}
|
22
|
+
end
|
23
|
+
|
24
|
+
##
|
25
|
+
# Read values from file into the @config hash.
|
26
|
+
def read
|
27
|
+
@fields.each do |key, val|
|
28
|
+
@config[key] = ENV[val]
|
29
|
+
end
|
30
|
+
@config
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Storedsafe
|
4
|
+
module Config
|
5
|
+
##
|
6
|
+
# Reads configuration items from rc file.
|
7
|
+
class RcReader
|
8
|
+
attr_reader :config
|
9
|
+
|
10
|
+
##
|
11
|
+
# Read configuration from Storedsafe RC file.
|
12
|
+
# @param [String] path Path to RC file.
|
13
|
+
def initialize(path)
|
14
|
+
@path = path
|
15
|
+
@config = {}
|
16
|
+
end
|
17
|
+
|
18
|
+
##
|
19
|
+
# Read values from file into the @config hash.
|
20
|
+
def read
|
21
|
+
if File.exists?(@path)
|
22
|
+
File.open(@path, 'r').each do |line|
|
23
|
+
key, val = line.split(':', 2)
|
24
|
+
key = key.strip
|
25
|
+
val = val.strip
|
26
|
+
parse_line(key, val)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
@config
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def parse_line(key, val)
|
35
|
+
case key
|
36
|
+
when 'token'
|
37
|
+
@config[:token] = val
|
38
|
+
when 'username'
|
39
|
+
@config[:username] = val
|
40
|
+
when 'apikey'
|
41
|
+
@config[:api_key] = val
|
42
|
+
when 'mysite'
|
43
|
+
@config[:server] = val
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Storedsafe
|
6
|
+
module Parser
|
7
|
+
##
|
8
|
+
# Transparent parser for the Storedsafe API.
|
9
|
+
module RawParser
|
10
|
+
class << self
|
11
|
+
##
|
12
|
+
# Transparently parses the Storedsafe API response into a ruby Hash.
|
13
|
+
# @return [Hash]
|
14
|
+
def parse_response(res)
|
15
|
+
JSON.parse(res)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: storedsafe
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Oscar Mattsson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-06-07 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email: oscar_mattsson@live.se
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- LICENSE
|
20
|
+
- README.md
|
21
|
+
- lib/storedsafe.rb
|
22
|
+
- lib/storedsafe/api.rb
|
23
|
+
- lib/storedsafe/api/auth.rb
|
24
|
+
- lib/storedsafe/api/objects.rb
|
25
|
+
- lib/storedsafe/api/templates.rb
|
26
|
+
- lib/storedsafe/api/vaults.rb
|
27
|
+
- lib/storedsafe/config.rb
|
28
|
+
- lib/storedsafe/config/configurable.rb
|
29
|
+
- lib/storedsafe/config/env_reader.rb
|
30
|
+
- lib/storedsafe/config/rc_reader.rb
|
31
|
+
- lib/storedsafe/parser.rb
|
32
|
+
- lib/storedsafe/parser/raw_parser.rb
|
33
|
+
homepage: https://github.com/storedsafe/storedsafe-ruby
|
34
|
+
licenses:
|
35
|
+
- Apache-2.0
|
36
|
+
metadata:
|
37
|
+
storedsafe_uri: https://storedsafe.com/
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubygems_version: 3.0.3
|
54
|
+
signing_key:
|
55
|
+
specification_version: 4
|
56
|
+
summary: Storedsafe is a ruby wrapper for the Storedsafe REST-like API.
|
57
|
+
test_files: []
|