vgs_api_client 0.0.1.alpha202205100806 → 0.0.1.alpha202205100944
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/VERSION +1 -1
- data/lib/openapi_client/api_client.rb +1 -1
- data/lib/openapi_client/version.rb +1 -1
- data/lib/version.rb +1 -1
- data/lib/vgs_api_client.rb +39 -10
- data/scripts/assemble/run.sh +1 -1
- data/scripts/test/run.sh +1 -1
- data/spec/test_aliases_api_spec.rb +46 -12
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c71499ab63c48769fcdabb8afaef36667c6ea81bdcfbc45506ae2f17943ed900
|
4
|
+
data.tar.gz: '042185bcfbd2337350e0a0d971d423597983008892b56ea29b5c68b0378881b6'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15fcfe391f33e3e5112ffeb3cd734eb0f767a82421e9fb72bb49a28f033ec4e6a2a1da089e4f3d7968a6f83317aef0277a9613cd2226bf4307f3ba3bbdea4daa
|
7
|
+
data.tar.gz: f84ad38b9cce07d3644286e3bb5489e9fd21d72fb04d5c97ba8e3242f8ef31eba4a0c2e8b4266fab0d4fbf7562162e3fafd45f3582ee885f6240a1cd1a5e4fbd
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.1.
|
1
|
+
0.0.1.alpha202205100944
|
@@ -31,7 +31,7 @@ module VgsApiClient
|
|
31
31
|
# @option config [Configuration] Configuration for initializing the object, default to Configuration.default
|
32
32
|
def initialize(config = Configuration.default)
|
33
33
|
@config = config
|
34
|
-
@user_agent = "vgs-api-client/0.0.1.
|
34
|
+
@user_agent = "vgs-api-client/0.0.1.alpha202205100944/ruby"
|
35
35
|
@default_headers = {
|
36
36
|
'Content-Type' => 'application/json',
|
37
37
|
'User-Agent' => @user_agent
|
data/lib/version.rb
CHANGED
data/lib/vgs_api_client.rb
CHANGED
@@ -1,14 +1,43 @@
|
|
1
1
|
require 'openapi_client'
|
2
2
|
|
3
3
|
module VGS
|
4
|
-
class
|
4
|
+
class VgsApiError < StandardError
|
5
|
+
end
|
6
|
+
|
7
|
+
class UnauthorizedError < VgsApiError
|
8
|
+
end
|
9
|
+
|
10
|
+
class NotFoundError < VgsApiError
|
11
|
+
end
|
12
|
+
|
13
|
+
class ForbiddenError < VgsApiError
|
5
14
|
end
|
6
15
|
|
7
16
|
class Aliases
|
8
17
|
def initialize(config)
|
18
|
+
raise ArgumentError, 'config is nil' if config.nil?
|
9
19
|
@aliases_api = VgsApiClient::AliasesApi.new(VgsApiClient::ApiClient.new(config))
|
10
20
|
end
|
11
21
|
|
22
|
+
private def map_exception(message, error)
|
23
|
+
error_message = message
|
24
|
+
if error.is_a? VgsApiClient::ApiError
|
25
|
+
error_message += ". Details: #{error.message}"
|
26
|
+
case error.code
|
27
|
+
when 401
|
28
|
+
UnauthorizedError.new error_message
|
29
|
+
when 403
|
30
|
+
ForbiddenError.new error_message
|
31
|
+
when 404
|
32
|
+
NotFoundError.new error_message
|
33
|
+
else
|
34
|
+
VgsApiError.new error_message
|
35
|
+
end
|
36
|
+
else
|
37
|
+
VgsApiError.new error_message
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
12
41
|
def redact(data)
|
13
42
|
begin
|
14
43
|
requests = data.map do |item|
|
@@ -26,9 +55,8 @@ module VGS
|
|
26
55
|
response = @aliases_api.create_aliases(opts = {
|
27
56
|
:create_aliases_request => create_aliases_request.to_hash
|
28
57
|
})
|
29
|
-
|
30
|
-
|
31
|
-
raise VgsApiException, "Failed to redact data #{ data }"
|
58
|
+
rescue Exception => e
|
59
|
+
raise map_exception("Failed to redact data #{ data }", e)
|
32
60
|
else
|
33
61
|
response.data
|
34
62
|
end
|
@@ -38,8 +66,8 @@ module VGS
|
|
38
66
|
begin
|
39
67
|
query = aliases.kind_of?(Array) ? aliases.join(",") : aliases
|
40
68
|
response = @aliases_api.reveal_multiple_aliases(q = query)
|
41
|
-
rescue
|
42
|
-
raise
|
69
|
+
rescue Exception => e
|
70
|
+
raise map_exception("Failed to reveal aliases #{ aliases }", e)
|
43
71
|
else
|
44
72
|
response.data
|
45
73
|
end
|
@@ -48,8 +76,8 @@ module VGS
|
|
48
76
|
def delete(_alias)
|
49
77
|
begin
|
50
78
|
@aliases_api.delete_alias(_alias = _alias)
|
51
|
-
rescue
|
52
|
-
raise
|
79
|
+
rescue Exception => e
|
80
|
+
raise map_exception("Failed to delete alias #{ _alias }", e)
|
53
81
|
end
|
54
82
|
end
|
55
83
|
|
@@ -63,8 +91,8 @@ module VGS
|
|
63
91
|
@aliases_api.update_alias(_alias = _alias, opts = {
|
64
92
|
:update_alias_request => update_alias_request.to_hash
|
65
93
|
})
|
66
|
-
rescue
|
67
|
-
raise
|
94
|
+
rescue Exception => e
|
95
|
+
raise map_exception("Failed to update alias #{ _alias }", e)
|
68
96
|
end
|
69
97
|
end
|
70
98
|
end
|
@@ -77,6 +105,7 @@ module VGS
|
|
77
105
|
config.username = username
|
78
106
|
config.password = password
|
79
107
|
config.host = host
|
108
|
+
config.server_index = nil
|
80
109
|
config
|
81
110
|
end
|
82
111
|
end
|
data/scripts/assemble/run.sh
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
LIB_VERSION=${LIB_VERSION:-0.0.1.alpha$(date "+%Y%m%d%H%M")}
|
4
4
|
|
5
5
|
# fix version
|
6
|
-
grep -rl 0.0.1.
|
6
|
+
grep -rl 0.0.1.alpha202205100944 . | xargs sed -i "s/0.0.1.alpha202205100944/${LIB_VERSION}/g"
|
7
7
|
|
8
8
|
# build
|
9
9
|
gem build vgs_api_client.gemspec
|
data/scripts/test/run.sh
CHANGED
@@ -5,7 +5,7 @@ set -e
|
|
5
5
|
echo "Installing lib from local sources"
|
6
6
|
# fix version
|
7
7
|
VERSION=0.0.1.alpha$(date "+%Y%m%d%H%M")
|
8
|
-
grep -rl 0.0.1.
|
8
|
+
grep -rl 0.0.1.alpha202205100944 . | xargs sed -i "s/0.0.1.alpha202205100944/$VERSION/g"
|
9
9
|
|
10
10
|
bundle install
|
11
11
|
|
@@ -3,9 +3,43 @@ require 'securerandom'
|
|
3
3
|
require 'vgs_api_client'
|
4
4
|
|
5
5
|
describe 'AliasesApiSpec' do
|
6
|
-
before(:
|
6
|
+
before(:each) do
|
7
7
|
config = VGS.config(username = ENV['VAULT_API_USERNAME'], password = ENV['VAULT_API_PASSWORD'])
|
8
|
-
@
|
8
|
+
@api = VGS::Aliases.new config
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'invalid auth' do
|
12
|
+
it 'should fail if invalid auth provided' do
|
13
|
+
invalid_config = VGS.config(username = 'Invalid', password = 'Invalid')
|
14
|
+
api = VGS::Aliases.new invalid_config
|
15
|
+
data = [{
|
16
|
+
format: 'UUID',
|
17
|
+
value: 'Joe Doe'
|
18
|
+
}]
|
19
|
+
|
20
|
+
expect { api.redact data }.to raise_error(VGS::UnauthorizedError)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'invalid config' do
|
25
|
+
it 'should fail if invalid config provided' do
|
26
|
+
expect { VGS::Aliases.new nil }.to raise_error(ArgumentError)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'invalid host' do
|
31
|
+
it 'should fail if invalid host provided' do
|
32
|
+
config = VGS.config(
|
33
|
+
username = ENV['VAULT_API_USERNAME'],
|
34
|
+
password = ENV['VAULT_API_PASSWORD'],
|
35
|
+
host = 'https://echo.apps.verygood.systems')
|
36
|
+
api = VGS::Aliases.new config
|
37
|
+
data = [{
|
38
|
+
format: 'UUID',
|
39
|
+
value: 'Joe Doe'
|
40
|
+
}]
|
41
|
+
expect { api.redact data }.to raise_error(VGS::NotFoundError)
|
42
|
+
end
|
9
43
|
end
|
10
44
|
|
11
45
|
describe 'redact' do
|
@@ -21,7 +55,7 @@ describe 'AliasesApiSpec' do
|
|
21
55
|
value: 'Joe Doe',
|
22
56
|
storage: 'VOLATILE'
|
23
57
|
}]
|
24
|
-
aliases = @
|
58
|
+
aliases = @api.redact data
|
25
59
|
expect(aliases.length).to eq 2
|
26
60
|
data.each_with_index do |item, index|
|
27
61
|
expect(aliases[index].value).to eq item[:value]
|
@@ -46,14 +80,14 @@ describe 'AliasesApiSpec' do
|
|
46
80
|
value: 'Joe Doe',
|
47
81
|
storage: 'VOLATILE'
|
48
82
|
}]
|
49
|
-
aliases = @
|
83
|
+
aliases = @api.redact(data).map { |item| item.aliases[0]._alias }
|
50
84
|
|
51
|
-
response = @
|
85
|
+
response = @api.reveal aliases
|
52
86
|
|
53
87
|
expect(response.length).to eq 2
|
54
88
|
original_values = data.map { |i| i[:value] }
|
55
89
|
revealed_values = response.values.map { |i| i.value }
|
56
|
-
expect(Set.new
|
90
|
+
expect(Set.new original_values).to eq Set.new revealed_values
|
57
91
|
end
|
58
92
|
end
|
59
93
|
|
@@ -63,11 +97,11 @@ describe 'AliasesApiSpec' do
|
|
63
97
|
format: 'UUID',
|
64
98
|
value: SecureRandom.alphanumeric(10)
|
65
99
|
}]
|
66
|
-
_alias = @
|
100
|
+
_alias = @api.redact(data).map { |item| item.aliases[0]._alias }[0]
|
67
101
|
|
68
|
-
@
|
102
|
+
@api.update _alias, classifiers: %w[secure]
|
69
103
|
|
70
|
-
response = @
|
104
|
+
response = @api.reveal _alias
|
71
105
|
expect(response[_alias].classifiers).to eq %w[secure]
|
72
106
|
end
|
73
107
|
end
|
@@ -78,11 +112,11 @@ describe 'AliasesApiSpec' do
|
|
78
112
|
format: 'UUID',
|
79
113
|
value: '5201784564572092'
|
80
114
|
}]
|
81
|
-
_alias = @
|
115
|
+
_alias = @api.redact(data).map { |item| item.aliases[0]._alias }[0]
|
82
116
|
|
83
|
-
@
|
117
|
+
@api.delete _alias
|
84
118
|
|
85
|
-
expect { @
|
119
|
+
expect { @api.reveal _alias }.to raise_error(VGS::VgsApiError)
|
86
120
|
end
|
87
121
|
end
|
88
122
|
|