totvs_password_vault 0.2.2 → 0.3.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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rspec +1 -0
- data/README.md +2 -1
- data/config/password_vault.yml +28 -0
- data/lib/totvs/password_vault.rb +4 -1
- data/lib/totvs/password_vault/base.rb +128 -0
- data/lib/totvs/password_vault/connection.rb +20 -0
- data/lib/totvs/password_vault/information.rb +7 -53
- data/lib/totvs/password_vault/key.rb +5 -117
- data/lib/totvs/password_vault/password.rb +13 -0
- data/lib/totvs/password_vault/translator.rb +22 -0
- data/lib/totvs/password_vault/version.rb +1 -1
- data/totvs_password_vault.gemspec +1 -0
- metadata +21 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 010ef7c910164a6d91d792f7a935177ad9d2d034
|
4
|
+
data.tar.gz: 0a38e14d95bcdb9b0d6abd3ebab1822266d91e76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b0ed20292ebfca6eaa3dbadd1ea5fe492edb2340ad92d2d7ecf1e18a1a36b5ddb24e8a71c71233588e7d09af8960835c7416ddca5bb7c5f179f40f3c0b28010
|
7
|
+
data.tar.gz: 2762fc9a1ce0304fb9c0681de354136e65926d5ae6a52db84104c39738f5d20e3211c29af921cb447a55453b8ba8339040847b13cb801c9d4e87f4911e16964e
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
data/README.md
CHANGED
@@ -58,6 +58,8 @@ info.retrieve(id: "keyid") #=> { "some" => "value" }
|
|
58
58
|
|
59
59
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
60
60
|
|
61
|
+
To run integration tests run `rspec --tag integration`. They are skipped by default.
|
62
|
+
|
61
63
|
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
62
64
|
|
63
65
|
## Contributing
|
@@ -73,4 +75,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/diegoa
|
|
73
75
|
## License
|
74
76
|
|
75
77
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
76
|
-
|
@@ -0,0 +1,28 @@
|
|
1
|
+
groups:
|
2
|
+
key: chave
|
3
|
+
password: senha
|
4
|
+
info: info
|
5
|
+
|
6
|
+
fields:
|
7
|
+
commom: &commom
|
8
|
+
id: id
|
9
|
+
hostname: hostname
|
10
|
+
ip: ip
|
11
|
+
username: username
|
12
|
+
maker: fabricante
|
13
|
+
device_type: tipo
|
14
|
+
device_model: modelo
|
15
|
+
site: site
|
16
|
+
password_type: tipo_senha
|
17
|
+
expiration_time: datahora_expiracao
|
18
|
+
tags: tags
|
19
|
+
key:
|
20
|
+
<<: *commom
|
21
|
+
public_key: chave_publica
|
22
|
+
private_key: chave_privada
|
23
|
+
password: senha
|
24
|
+
password:
|
25
|
+
<<: *commom
|
26
|
+
password: conteudo
|
27
|
+
info:
|
28
|
+
content: conteudo
|
data/lib/totvs/password_vault.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
require "totvs/password_vault/version"
|
2
2
|
require "totvs/password_vault/connection"
|
3
|
-
require "totvs/password_vault/
|
3
|
+
require "totvs/password_vault/translator"
|
4
|
+
require "totvs/password_vault/base"
|
4
5
|
require "totvs/password_vault/key"
|
6
|
+
require "totvs/password_vault/password"
|
7
|
+
require "totvs/password_vault/information"
|
5
8
|
require "totvs/password_vault/response"
|
6
9
|
require "totvs/password_vault/parsers/json_parser"
|
7
10
|
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require "forwardable"
|
2
|
+
require "time"
|
3
|
+
require "totvs/password_vault/parsers/json_parser"
|
4
|
+
|
5
|
+
module Totvs
|
6
|
+
module PasswordVault
|
7
|
+
class Base
|
8
|
+
class Error < StandardError; end
|
9
|
+
class RequiredParameter < Error; end
|
10
|
+
|
11
|
+
extend Forwardable
|
12
|
+
include JsonParser
|
13
|
+
|
14
|
+
def_delegators :connection, :get, :post, :delete
|
15
|
+
|
16
|
+
# @!attribute [w] connection
|
17
|
+
# @return [Connection]
|
18
|
+
attr_writer :connection
|
19
|
+
|
20
|
+
def initialize(connection: nil)
|
21
|
+
@connection = connection
|
22
|
+
end
|
23
|
+
|
24
|
+
def connection
|
25
|
+
@connection ||= Connection.new
|
26
|
+
end
|
27
|
+
|
28
|
+
# @param id [String] the id key to fetch info from
|
29
|
+
# @return [Hash<Symbol, String>] content the saved content
|
30
|
+
# @raise [Totvs::PasswordVault::Connection::RequestFailure] if the request was not a success
|
31
|
+
def retrieve(id:)
|
32
|
+
headers = { "Accept" => "application/json" }
|
33
|
+
response = get(path: build_path(id), headers: headers)
|
34
|
+
response = parse_json response.body
|
35
|
+
|
36
|
+
result = {}
|
37
|
+
response[translated_group].each do |key, value|
|
38
|
+
result[(field_key(key) || key).to_sym] = value
|
39
|
+
end
|
40
|
+
|
41
|
+
result
|
42
|
+
end
|
43
|
+
|
44
|
+
# @param id [String] the id key to save info
|
45
|
+
# @param kwargs [Hash]
|
46
|
+
def save(id:, **kwargs)
|
47
|
+
headers = {
|
48
|
+
"Accept" => "application/json",
|
49
|
+
"Content-Type" => "application/json"
|
50
|
+
}
|
51
|
+
validate_params!(kwargs)
|
52
|
+
|
53
|
+
post path: build_path(id), body: save_body(kwargs), headers: headers
|
54
|
+
end
|
55
|
+
|
56
|
+
# @param id [String] the id key to be removed
|
57
|
+
# @raise [Totvs::PasswordVault::Connection::RequestFailure] if the request was not a success
|
58
|
+
def destroy(id:)
|
59
|
+
headers = { "Accept" => "application/json" }
|
60
|
+
delete path: build_path(id), headers: headers
|
61
|
+
end
|
62
|
+
|
63
|
+
def required_params
|
64
|
+
fail NotImplementedError
|
65
|
+
end
|
66
|
+
|
67
|
+
def data_group
|
68
|
+
fail NotImplementedError
|
69
|
+
end
|
70
|
+
|
71
|
+
protected
|
72
|
+
|
73
|
+
# validate presence of all required params
|
74
|
+
def validate_params!(params)
|
75
|
+
required_params.each do |req_param|
|
76
|
+
fail RequiredParameter, "Required parameter {#{req_param}}" if params[req_param].nil?
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# mount body to save request
|
81
|
+
# @param params [Hash]
|
82
|
+
# @return [Hash] translated body params
|
83
|
+
def save_body(params)
|
84
|
+
body = {}
|
85
|
+
params.each do |key, value|
|
86
|
+
body[field_translation(key.to_s).to_sym] = prepare_value_for_saving(value) if field_translation(key.to_s)
|
87
|
+
end
|
88
|
+
body.delete_if { |_, value| value.nil? || value.empty? }
|
89
|
+
end
|
90
|
+
|
91
|
+
# treat some type of value objects
|
92
|
+
# @param value [Object] to be prepared
|
93
|
+
# @return value with some kind of treatment
|
94
|
+
def prepare_value_for_saving(value)
|
95
|
+
case value
|
96
|
+
when Array
|
97
|
+
value.join(", ")
|
98
|
+
when Time
|
99
|
+
value.iso8601
|
100
|
+
when Hash
|
101
|
+
value.to_json
|
102
|
+
else
|
103
|
+
value
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def field_translation(key)
|
108
|
+
translator.translate_field(data_group, key)
|
109
|
+
end
|
110
|
+
|
111
|
+
def field_key(name)
|
112
|
+
translator.field_key(data_group, name)
|
113
|
+
end
|
114
|
+
|
115
|
+
def translator
|
116
|
+
@translator ||= Translator.new
|
117
|
+
end
|
118
|
+
|
119
|
+
def translated_group
|
120
|
+
translator.translate_group(data_group)
|
121
|
+
end
|
122
|
+
|
123
|
+
def build_path(key)
|
124
|
+
"/iso/coe/#{translated_group}/#{key}"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -7,6 +7,7 @@ module Totvs
|
|
7
7
|
class TimeoutError < Error; end
|
8
8
|
class RegistryNotFoundError < Error; end
|
9
9
|
class InactiveRegistryError < Error; end
|
10
|
+
class EnvironmentVariableError < Error; end
|
10
11
|
|
11
12
|
class RequestFailure < Error
|
12
13
|
attr_reader :response
|
@@ -76,6 +77,8 @@ module Totvs
|
|
76
77
|
#
|
77
78
|
# @raise [TimeoutError]
|
78
79
|
def make_request(http_method, path, *args)
|
80
|
+
validate_environment_variables!
|
81
|
+
|
79
82
|
requester.request http_method, path, *args
|
80
83
|
rescue Timeout::Error => e
|
81
84
|
raise TimeoutError, "#{http_method.to_s.upcase}: #{path}. #{e}"
|
@@ -121,6 +124,16 @@ module Totvs
|
|
121
124
|
wrap_response response
|
122
125
|
end
|
123
126
|
|
127
|
+
def required_environment_variables
|
128
|
+
%w(
|
129
|
+
VAULT_CONSUMER_KEY
|
130
|
+
VAULT_CONSUMER_SECRET
|
131
|
+
VAULT_BASE_URL
|
132
|
+
VAULT_ACCESS_TOKEN
|
133
|
+
VAULT_ACCESS_TOKEN_SECRET
|
134
|
+
)
|
135
|
+
end
|
136
|
+
|
124
137
|
# @return [String]
|
125
138
|
def consumer_key
|
126
139
|
@consumer_key ||= ENV["VAULT_CONSUMER_KEY"]
|
@@ -156,6 +169,13 @@ module Totvs
|
|
156
169
|
|
157
170
|
protected
|
158
171
|
|
172
|
+
# validates presence of environment variables
|
173
|
+
def validate_environment_variables!
|
174
|
+
required_environment_variables.each do |variable|
|
175
|
+
fail EnvironmentVariableError, "Missing environment variable: #{variable}" unless ENV[variable]
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
159
179
|
def validate_success!(response)
|
160
180
|
if response.is_a? Net::HTTPNotFound
|
161
181
|
fail RegistryNotFoundError
|
@@ -1,63 +1,17 @@
|
|
1
|
-
require "forwardable"
|
2
|
-
require "totvs/password_vault/parsers/json_parser"
|
3
|
-
|
4
1
|
module Totvs
|
5
2
|
module PasswordVault
|
6
|
-
class Information
|
7
|
-
extend Forwardable
|
8
|
-
include JsonParser
|
9
|
-
|
10
|
-
def_delegators :connection, :get, :post, :delete
|
11
|
-
|
12
|
-
# @!attribute [w] connection
|
13
|
-
# @return [Connection]
|
14
|
-
attr_writer :connection
|
15
|
-
|
16
|
-
def initialize(connection: nil)
|
17
|
-
@connection = connection
|
18
|
-
end
|
19
|
-
|
20
|
-
def connection
|
21
|
-
@connection ||= Connection.new
|
22
|
-
end
|
23
|
-
|
24
|
-
# @param id [String] the id key to fetch info from
|
25
|
-
# @return [Hash, Array] content the saved content
|
26
|
-
# @raise [Totvs::PasswordVault::Connection::RequestFailure] if the request was not a success
|
3
|
+
class Information < Base
|
27
4
|
def retrieve(id:)
|
28
|
-
|
29
|
-
|
30
|
-
response = parse_json(response.body)
|
31
|
-
|
32
|
-
parse_json(response["info"]["conteudo"])
|
5
|
+
result = super
|
6
|
+
parse_json result[:content]
|
33
7
|
end
|
34
8
|
|
35
|
-
|
36
|
-
|
37
|
-
def save(id:, content:, **kwargs)
|
38
|
-
headers = {
|
39
|
-
"Accept" => "application/json",
|
40
|
-
"Content-Type" => "application/json"
|
41
|
-
}
|
42
|
-
|
43
|
-
body = {
|
44
|
-
conteudo: content.to_json
|
45
|
-
}.merge(kwargs)
|
46
|
-
|
47
|
-
post path: build_path(id), body: body, headers: headers
|
9
|
+
def required_params
|
10
|
+
[:content]
|
48
11
|
end
|
49
12
|
|
50
|
-
|
51
|
-
|
52
|
-
def destroy(id:)
|
53
|
-
headers = { "Accept" => "application/json" }
|
54
|
-
delete path: build_path(id), headers: headers
|
55
|
-
end
|
56
|
-
|
57
|
-
protected
|
58
|
-
|
59
|
-
def build_path(key)
|
60
|
-
"/iso/coe/info/#{key}"
|
13
|
+
def data_group
|
14
|
+
"info"
|
61
15
|
end
|
62
16
|
end
|
63
17
|
end
|
@@ -1,124 +1,12 @@
|
|
1
|
-
require "forwardable"
|
2
|
-
require "time"
|
3
|
-
require "totvs/password_vault/parsers/json_parser"
|
4
|
-
|
5
1
|
module Totvs
|
6
2
|
module PasswordVault
|
7
|
-
class Key
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
def_delegators :connection, :get, :post, :delete
|
12
|
-
|
13
|
-
# @!attribute [w] connection
|
14
|
-
# @return [Connection]
|
15
|
-
attr_writer :connection
|
16
|
-
|
17
|
-
def initialize(connection: nil)
|
18
|
-
@connection = connection
|
19
|
-
end
|
20
|
-
|
21
|
-
def connection
|
22
|
-
@connection ||= Connection.new
|
23
|
-
end
|
24
|
-
|
25
|
-
# @param id [String] the id key to fetch info from
|
26
|
-
# @return [Hash<Symbol, String>] content the saved content
|
27
|
-
# @param public_key [String]
|
28
|
-
# @param private_key [String]
|
29
|
-
# @param hostname [String]
|
30
|
-
# @param ip [String]
|
31
|
-
# @param username [String]
|
32
|
-
# @param maker [String]
|
33
|
-
# @param device_type [String]
|
34
|
-
# @param device_model [String]
|
35
|
-
# @param site [String]
|
36
|
-
# @param password_type [String]
|
37
|
-
# @param tags [Array]
|
38
|
-
# @raise [Totvs::PasswordVault::Connection::RequestFailure] if the request was not a success
|
39
|
-
def retrieve(id:)
|
40
|
-
headers = { "Accept" => "application/json" }
|
41
|
-
response = get(path: build_path(id), headers: headers)
|
42
|
-
response = parse_json response.body
|
43
|
-
|
44
|
-
{
|
45
|
-
public_key: response["chave"]["chave_publica"],
|
46
|
-
private_key: response["chave"]["chave_privada"],
|
47
|
-
hostname: response["chave"]["hostname"],
|
48
|
-
ip: response["chave"]["ip"],
|
49
|
-
username: response["chave"]["username"],
|
50
|
-
maker: response["chave"]["fabricante"],
|
51
|
-
device_type: response["chave"]["tipo"],
|
52
|
-
device_model: response["chave"]["modelo"],
|
53
|
-
site: response["chave"]["site"],
|
54
|
-
password_type: response["chave"]["tipo_senha"],
|
55
|
-
expiration_time: response["chave"]["datahora_expiracao"],
|
56
|
-
tags: response["chave"]["tags"]
|
57
|
-
}
|
58
|
-
end
|
59
|
-
|
60
|
-
# @param id [String] the id key to save info
|
61
|
-
# @param public_key [String]
|
62
|
-
# @param private_key [String]
|
63
|
-
# @param hostname [String]
|
64
|
-
# @param ip [String]
|
65
|
-
# @param maker [String, nil]
|
66
|
-
# @param device_type [String, nil]
|
67
|
-
# @param device_model [String, nil]
|
68
|
-
# @param site [String, nil]
|
69
|
-
# @param password_type [String, nil]
|
70
|
-
# @param expiration_time [Time, nil]
|
71
|
-
# @param tags [Array[String], nil]
|
72
|
-
def save(
|
73
|
-
id:,
|
74
|
-
public_key:,
|
75
|
-
private_key:,
|
76
|
-
hostname:,
|
77
|
-
ip:,
|
78
|
-
username: nil,
|
79
|
-
maker: nil,
|
80
|
-
device_type: nil,
|
81
|
-
device_model: nil,
|
82
|
-
site: nil,
|
83
|
-
password_type: nil,
|
84
|
-
expiration_time: nil,
|
85
|
-
tags: [],
|
86
|
-
**kwargs
|
87
|
-
)
|
88
|
-
headers = {
|
89
|
-
"Accept" => "application/json",
|
90
|
-
"Content-Type" => "application/json"
|
91
|
-
}
|
92
|
-
|
93
|
-
body = {
|
94
|
-
chave_publica: public_key,
|
95
|
-
chave_privada: private_key,
|
96
|
-
hostname: hostname,
|
97
|
-
ip: ip,
|
98
|
-
username: username,
|
99
|
-
fabricante: maker,
|
100
|
-
tipo: device_type,
|
101
|
-
modelo: device_model,
|
102
|
-
site: site,
|
103
|
-
tipo_senha: password_type,
|
104
|
-
datahora_expiracao: expiration_time ? expiration_time.iso8601 : nil,
|
105
|
-
tags: tags.compact.join(", ")
|
106
|
-
}.merge(kwargs).delete_if { |_, value| value.nil? || value.empty? }
|
107
|
-
|
108
|
-
post path: build_path(id), body: body, headers: headers
|
109
|
-
end
|
110
|
-
|
111
|
-
# @param id [String] the id key to be removed
|
112
|
-
# @raise [Totvs::PasswordVault::Connection::RequestFailure] if the request was not a success
|
113
|
-
def destroy(id:)
|
114
|
-
headers = { "Accept" => "application/json" }
|
115
|
-
delete path: build_path(id), headers: headers
|
3
|
+
class Key < Base
|
4
|
+
def required_params
|
5
|
+
[:public_key, :private_key, :hostname, :ip]
|
116
6
|
end
|
117
7
|
|
118
|
-
|
119
|
-
|
120
|
-
def build_path(key)
|
121
|
-
"/iso/coe/chave/#{key}"
|
8
|
+
def data_group
|
9
|
+
"key"
|
122
10
|
end
|
123
11
|
end
|
124
12
|
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "yaml"
|
2
|
+
|
3
|
+
module Totvs
|
4
|
+
module PasswordVault
|
5
|
+
class Translator
|
6
|
+
ACTION_CODES = YAML.load_file(
|
7
|
+
File.join(File.expand_path("../../../..", __FILE__), "config", "password_vault.yml")).freeze
|
8
|
+
|
9
|
+
def translate_field(group, key)
|
10
|
+
ACTION_CODES["fields"][group][key]
|
11
|
+
end
|
12
|
+
|
13
|
+
def field_key(group, name)
|
14
|
+
ACTION_CODES["fields"][group].key(name)
|
15
|
+
end
|
16
|
+
|
17
|
+
def translate_group(name)
|
18
|
+
ACTION_CODES["groups"][name]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: totvs_password_vault
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guilherme da Silva Mello
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-10-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth
|
@@ -108,6 +108,20 @@ dependencies:
|
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0.10'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: dotenv
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
111
125
|
description: This gem allows you to manage your data on totvs password vault.
|
112
126
|
email:
|
113
127
|
- guilhermesilvamello@gmail.com
|
@@ -125,12 +139,16 @@ files:
|
|
125
139
|
- Rakefile
|
126
140
|
- bin/console
|
127
141
|
- bin/setup
|
142
|
+
- config/password_vault.yml
|
128
143
|
- lib/totvs/password_vault.rb
|
144
|
+
- lib/totvs/password_vault/base.rb
|
129
145
|
- lib/totvs/password_vault/connection.rb
|
130
146
|
- lib/totvs/password_vault/information.rb
|
131
147
|
- lib/totvs/password_vault/key.rb
|
132
148
|
- lib/totvs/password_vault/parsers/json_parser.rb
|
149
|
+
- lib/totvs/password_vault/password.rb
|
133
150
|
- lib/totvs/password_vault/response.rb
|
151
|
+
- lib/totvs/password_vault/translator.rb
|
134
152
|
- lib/totvs/password_vault/version.rb
|
135
153
|
- lib/totvs_password_vault.rb
|
136
154
|
- totvs_password_vault.gemspec
|
@@ -154,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
172
|
version: '0'
|
155
173
|
requirements: []
|
156
174
|
rubyforge_project:
|
157
|
-
rubygems_version: 2.4.
|
175
|
+
rubygems_version: 2.4.8
|
158
176
|
signing_key:
|
159
177
|
specification_version: 4
|
160
178
|
summary: Totvs password vault manager.
|