storedsafe 0.0.2 → 0.0.3
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/README.md +13 -5
- data/lib/storedsafe.rb +5 -3
- data/lib/storedsafe/api.rb +8 -1
- data/lib/storedsafe/api/auth.rb +4 -12
- data/lib/storedsafe/api/objects.rb +15 -15
- data/lib/storedsafe/api/templates.rb +2 -4
- data/lib/storedsafe/api/vaults.rb +5 -10
- data/lib/storedsafe/version.rb +3 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c21ee6c1c19d8c978e38fc35f06e80ab74f45fa89a4523accea45babbbbe592
|
4
|
+
data.tar.gz: e3d4001ef178c9f8da95e8de1c441c3d19736950e5bad25fba49652aa07e2a74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2aa4eec337404560da5b5e54fcbc7f48ba1c324dd30874d90b1c4c9c1eea3e97d457b5b75525b604a7aa57a526b6d6b3852d7d3866693db4114b19297c7f96b
|
7
|
+
data.tar.gz: 8a1bca50bab2de5237e7a48be258202325a78bd4a2f44e2174eecf609039352c6239ecb3d19f65ff543e3674e83c918214f53cb92aae6f278382e02e1f47ff8c
|
data/README.md
CHANGED
@@ -8,16 +8,24 @@ This is a ruby wrapper for the Storedsafe REST-like API (See full [docs here](ht
|
|
8
8
|
|
9
9
|
Install from rubygems `gem install storedsafe`
|
10
10
|
|
11
|
-
Add to Gemfile `gem 'storedsafe', '~> 0.0.
|
11
|
+
Add to Gemfile `gem 'storedsafe', '~> 0.0.3'`
|
12
|
+
|
13
|
+
Alternatively, if you whish to install the gem manually, you can clone this repo and build the gem yourself.
|
14
|
+
|
15
|
+
```
|
16
|
+
git clone https://github.com/storedsafe/storedsafe-ruby
|
17
|
+
cd storedsafe-ruby
|
18
|
+
gem build storedsafe.gemspec
|
19
|
+
gem install storedsafe-0.0.3.gem
|
20
|
+
```
|
12
21
|
|
13
22
|
## Usage
|
14
23
|
To pass a manual configuration, you simply pass a block to *Storedsafe.configure*.
|
15
24
|
```
|
16
25
|
api = Storedsafe.configure do |config|
|
17
26
|
config.server = 'storedsafe.example.com'
|
18
|
-
config.
|
27
|
+
config.api_key = 'abc123'
|
19
28
|
config.token = 'secret'
|
20
|
-
config.username = 'bob'
|
21
29
|
end
|
22
30
|
```
|
23
31
|
|
@@ -59,11 +67,11 @@ api.authenticate('abc123', 'abcdef123456', Storedsafe::API::LoginType::YUBIKEY)
|
|
59
67
|
* retrieve\_template(template\_id)
|
60
68
|
|
61
69
|
### Objects
|
62
|
-
* object(object\_id, decrypt
|
70
|
+
* object(object\_id, decrypt: false, children: false)
|
63
71
|
* create\_object(template\_id, group\_id, parent\_id, object\_name, template\_args)
|
64
72
|
* edit\_object(object\_id, template\_id, group\_id, parent\_id, object\_name, template\_args)
|
65
73
|
* delete\_object(object\_id)
|
66
|
-
* find
|
74
|
+
* find(needle)
|
67
75
|
|
68
76
|
## Configuration
|
69
77
|
Configuration can be done in a few different ways. Other than the manual configuration, external configuration sources can be applied through the *config\_sources* array. This array contains Ruby Hashes with the fields that should be applied to the `Storedsafe::Config::Configurable` instance. By default fetch configurations through the `Storedsafe::Config::RcReader` and `Storedsafe::Config::EnvReader`.
|
data/lib/storedsafe.rb
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require 'storedsafe/api'
|
3
|
+
require 'storedsafe/config'
|
4
|
+
require 'storedsafe/parser'
|
2
5
|
|
3
6
|
##
|
4
7
|
# Ruby wrapper for the Storedsafe RESTlike API.
|
5
8
|
module Storedsafe
|
9
|
+
VERSION = '0.0.3'
|
10
|
+
|
6
11
|
class << self
|
7
|
-
require 'storedsafe/api'
|
8
|
-
require 'storedsafe/config'
|
9
|
-
require 'storedsafe/parser'
|
10
12
|
|
11
13
|
##
|
12
14
|
# Set up a new API instance configured to communicate with your Storedsafe
|
data/lib/storedsafe/api.rb
CHANGED
@@ -12,6 +12,9 @@ require_relative 'api/vaults'
|
|
12
12
|
require_relative 'api/templates'
|
13
13
|
|
14
14
|
module Storedsafe
|
15
|
+
class ConnectionError < StandardError
|
16
|
+
end
|
17
|
+
|
15
18
|
##
|
16
19
|
# Contains all interaction and configuration relating to the remote API.
|
17
20
|
class API
|
@@ -52,7 +55,11 @@ module Storedsafe
|
|
52
55
|
assign_verify_mode(http)
|
53
56
|
request = create_request(method, uri, params)
|
54
57
|
|
55
|
-
http.request(request) if request
|
58
|
+
res = http.request(request) if request
|
59
|
+
parse_body(res)
|
60
|
+
|
61
|
+
rescue SocketError => e
|
62
|
+
raise ConnectionError.new(e.message)
|
56
63
|
end
|
57
64
|
|
58
65
|
def assign_verify_mode(http)
|
data/lib/storedsafe/api/auth.rb
CHANGED
@@ -10,17 +10,14 @@ module Storedsafe
|
|
10
10
|
# @param [String] otp Yubikey press
|
11
11
|
# @see authenticate Authentication with other OTP types.
|
12
12
|
def authenticate_yubikey(passphrase, otp)
|
13
|
-
|
13
|
+
data = request(
|
14
14
|
:post, '/auth',
|
15
15
|
username: @username, keys: "#{passphrase}#{@api_key}#{otp}"
|
16
16
|
)
|
17
|
-
data = parse_body(res)
|
18
17
|
@token = data['CALLINFO']['token']
|
19
18
|
data
|
20
19
|
end
|
21
20
|
|
22
|
-
# rubocop:disable Metrics/MethodLength
|
23
|
-
|
24
21
|
##
|
25
22
|
# Authenticates a user with specified OTP method.
|
26
23
|
# @param [String] passphrase
|
@@ -31,23 +28,19 @@ module Storedsafe
|
|
31
28
|
return authenticate_yubikey(passphrase, otp)
|
32
29
|
end
|
33
30
|
|
34
|
-
|
31
|
+
data = request(
|
35
32
|
:post, '/auth',
|
36
33
|
username: @username, passphrase: passphrase, otp: otp,
|
37
34
|
apikey: @api_key, logintype: logintype
|
38
35
|
)
|
39
|
-
data = parse_body(res)
|
40
36
|
@token = data['CALLINFO']['token']
|
41
37
|
data
|
42
38
|
end
|
43
39
|
|
44
|
-
# rubocop:enable Metrics/MethodLength
|
45
|
-
|
46
40
|
##
|
47
41
|
# Invalidates the token.
|
48
42
|
def logout
|
49
|
-
|
50
|
-
data = parse_body(res)
|
43
|
+
data = request(:get, '/auth/logout', token: @token)
|
51
44
|
@token = nil if data['CALLINFO']['status'] == 'SUCCESS'
|
52
45
|
data
|
53
46
|
end
|
@@ -56,8 +49,7 @@ module Storedsafe
|
|
56
49
|
# Checks whether or not the token is valid and refreshes the
|
57
50
|
# timeout for that token if valid.
|
58
51
|
def check
|
59
|
-
|
60
|
-
parse_body(res)
|
52
|
+
request(:get, '/auth/check', token: @token)
|
61
53
|
end
|
62
54
|
end
|
63
55
|
end
|
@@ -10,12 +10,16 @@ module Storedsafe
|
|
10
10
|
# Lists all information regarding an object and optionally decrypts
|
11
11
|
# encrypted fields.
|
12
12
|
# @param [Integer] object_id
|
13
|
-
# @param [
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
# @param [Hash] options
|
14
|
+
# @option options [Boolean] :decrypt (false)
|
15
|
+
# @option options [Boolean] :children (false)
|
16
|
+
def object(object_id, options = {})
|
17
|
+
decrypt = options.fetch(:decrypt, false)
|
18
|
+
children = options.fetch(:children, false)
|
19
|
+
request(
|
20
|
+
:get, "/object/#{object_id}",
|
21
|
+
token: @token, decrypt: decrypt, children: children
|
17
22
|
)
|
18
|
-
parse_body(res)
|
19
23
|
end
|
20
24
|
|
21
25
|
##
|
@@ -28,13 +32,12 @@ module Storedsafe
|
|
28
32
|
def create_object(
|
29
33
|
template_id, group_id, parent_id, object_name, template_args
|
30
34
|
)
|
31
|
-
|
35
|
+
request(
|
32
36
|
:post, '/object', {
|
33
37
|
token: @token, templateid: template_id, groupid: group_id,
|
34
38
|
parentid: parent_id, objectname: object_name
|
35
39
|
}.merge(template_args)
|
36
40
|
)
|
37
|
-
parse_body(res)
|
38
41
|
end
|
39
42
|
|
40
43
|
##
|
@@ -45,33 +48,30 @@ module Storedsafe
|
|
45
48
|
# @param [Integer] parent_id ID of parent Object.
|
46
49
|
# @param [String] object_name New Object name.
|
47
50
|
# @param [Hash] template_args New Object values,
|
48
|
-
#
|
51
|
+
# see Storedsafe::API#list_templates.
|
49
52
|
def edit_object(
|
50
53
|
object_id, template_id, group_id, parent_id, object_name, template_args
|
51
54
|
)
|
52
|
-
|
55
|
+
request(
|
53
56
|
:put, "/object/#{object_id}", {
|
54
57
|
token: @token, templateid: template_id, groupid: group_id,
|
55
58
|
parentid: parent_id, objectname: object_name
|
56
59
|
}.merge(template_args)
|
57
60
|
)
|
58
|
-
parse_body(res)
|
59
61
|
end
|
60
62
|
|
61
63
|
##
|
62
64
|
# Deletes an existing object.
|
63
65
|
# @param [Integer] object_id
|
64
66
|
def delete_object(object_id)
|
65
|
-
|
66
|
-
parse_body(res)
|
67
|
+
request(:delete, "/object/#{object_id}", token: @token)
|
67
68
|
end
|
68
69
|
|
69
70
|
##
|
70
71
|
# Search in unencrypted data to find Objects.
|
71
72
|
# @param [String] needle String to match Objects with.
|
72
|
-
def
|
73
|
-
|
74
|
-
parse_body(res)
|
73
|
+
def find(needle)
|
74
|
+
request(:get, '/find', token: @token, needle: needle)
|
75
75
|
end
|
76
76
|
|
77
77
|
# rubocop:enable Metrics/ParameterLists
|
@@ -7,8 +7,7 @@ module Storedsafe
|
|
7
7
|
##
|
8
8
|
# Obtains a list with information about all available templates.
|
9
9
|
def list_templates
|
10
|
-
|
11
|
-
parse_body(res)
|
10
|
+
request(:get, '/template', token: @token)
|
12
11
|
end
|
13
12
|
|
14
13
|
##
|
@@ -16,8 +15,7 @@ module Storedsafe
|
|
16
15
|
# @param [Integer] template_id
|
17
16
|
# @see list_templates
|
18
17
|
def retrieve_template(template_id)
|
19
|
-
|
20
|
-
parse_body(res)
|
18
|
+
request(:get, "/template/#{template_id}", token: @token)
|
21
19
|
end
|
22
20
|
end
|
23
21
|
end
|
@@ -7,8 +7,7 @@ module Storedsafe
|
|
7
7
|
##
|
8
8
|
# Lists all Vaults associated with the logged in user.
|
9
9
|
def list_vaults
|
10
|
-
|
11
|
-
parse_body(res)
|
10
|
+
request(:get, '/vault', token: @token)
|
12
11
|
end
|
13
12
|
|
14
13
|
##
|
@@ -16,8 +15,7 @@ module Storedsafe
|
|
16
15
|
# @param [Integer] vault_id
|
17
16
|
# @see list_vaults
|
18
17
|
def list_objects(vault_id)
|
19
|
-
|
20
|
-
parse_body(res)
|
18
|
+
request(:get, "/vault/#{vault_id}", token: @token)
|
21
19
|
end
|
22
20
|
|
23
21
|
##
|
@@ -27,12 +25,11 @@ module Storedsafe
|
|
27
25
|
# @param [Integer] policy Password policy.
|
28
26
|
# @param [String] description
|
29
27
|
def create_vault(groupname, policy, description)
|
30
|
-
|
28
|
+
request(
|
31
29
|
:post, '/vault',
|
32
30
|
token: @token,
|
33
31
|
groupname: groupname, policy: policy, description: description
|
34
32
|
)
|
35
|
-
parse_body(res)
|
36
33
|
end
|
37
34
|
|
38
35
|
##
|
@@ -44,8 +41,7 @@ module Storedsafe
|
|
44
41
|
# @option args [Integer] policy New password policy
|
45
42
|
# @option args [String] description New Vault description.
|
46
43
|
def edit_vault(vault_id, args)
|
47
|
-
|
48
|
-
parse_body(res)
|
44
|
+
request(:put, "/vault/#{vault_id}", { token: @token }.merge(args))
|
49
45
|
end
|
50
46
|
|
51
47
|
##
|
@@ -55,8 +51,7 @@ module Storedsafe
|
|
55
51
|
# specified Vault.
|
56
52
|
# @param [Integer] vault_id
|
57
53
|
def delete_vault(vault_id)
|
58
|
-
|
59
|
-
parse_body(res)
|
54
|
+
request(:delete, "/vault/#{vault_id}", token: @token)
|
60
55
|
end
|
61
56
|
end
|
62
57
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: storedsafe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oscar Mattsson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: oscar_mattsson@live.se
|
@@ -30,6 +30,7 @@ files:
|
|
30
30
|
- lib/storedsafe/config/rc_reader.rb
|
31
31
|
- lib/storedsafe/parser.rb
|
32
32
|
- lib/storedsafe/parser/raw_parser.rb
|
33
|
+
- lib/storedsafe/version.rb
|
33
34
|
homepage: https://github.com/storedsafe/storedsafe-ruby
|
34
35
|
licenses:
|
35
36
|
- Apache-2.0
|
@@ -50,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
51
|
- !ruby/object:Gem::Version
|
51
52
|
version: '0'
|
52
53
|
requirements: []
|
53
|
-
rubygems_version: 3.0.
|
54
|
+
rubygems_version: 3.0.4
|
54
55
|
signing_key:
|
55
56
|
specification_version: 4
|
56
57
|
summary: Storedsafe is a ruby wrapper for the Storedsafe REST-like API.
|