vgs_api_client 0.0.1.alpha202205041401 → 0.0.1.alpha202205061657

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4aca2a7276532fd047363d6709fb86ad758b98c377799f74eb31ccc41898659f
4
- data.tar.gz: 5426a43aea34516ccf91abb8e258f8d33936f98a89dcda48c51e7291ce2d6a08
3
+ metadata.gz: 123134048a65ef511bc67624fafed31288e6976eee580153b83a05595525758b
4
+ data.tar.gz: 8c424e099764200fb6b90e7278f1f73b377c9aead2a18d3f8aa0bd8cc71413cd
5
5
  SHA512:
6
- metadata.gz: '088118fca1debb13b98f7940fbeae6e6da2976eadea5848e251766a3b56e7319f7a274b9159f3c3ef5ae6fe2fac8e3dd19c37b4c944c48b8551e63894521944f'
7
- data.tar.gz: 49bad418da5df2d3f1471e8bf776fe48afc4e0d5b695ecd4af0fa0172f3e2b2b8a48e9a2914d68a77b952beab9e52000a00a255c24e780f89ad9170d347b6dda
6
+ metadata.gz: cdd8095625820809fb3cdebd1c4952b227d3d839709a902e9ff9ec75691d60a43f19f02b6f7de79816dea3e10ddfd40ca1c53398042a4a1c366a776ddbfeca79
7
+ data.tar.gz: d322b0b5f3ca7325018a6b52086ae1eaa64fcda5d459b407de89cc0a932a22fd489084017f2c2ed43e8f3ef2533e3c2b9663b36f11c6cb17abe12970237c603e
data/README.md CHANGED
@@ -16,11 +16,11 @@ gem install vgs-api-client
16
16
 
17
17
  ### Development
18
18
 
19
- Follow [DEVELOPMENT](https://github.com/verygoodsecurity/vgs-api-client-ruby/blob/master/DEVELOPMENT.md) instruction.
19
+ Follow [DEVELOPMENT](DEVELOPMENT.md) instruction.
20
20
 
21
21
  ### Release
22
22
 
23
- Follow [RELEASE](https://github.com/verygoodsecurity/vgs-api-client-ruby/blob/master/RELEASE.md) instruction.
23
+ Follow [RELEASE](RELEASE.md) instruction.
24
24
 
25
25
  ### Documentation
26
26
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1.alpha202205041401
1
+ 0.0.1.alpha202205061657
@@ -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.alpha202205041401/ruby"
34
+ @user_agent = "vgs-api-client/0.0.1.alpha202205061657/ruby"
35
35
  @default_headers = {
36
36
  'Content-Type' => 'application/json',
37
37
  'User-Agent' => @user_agent
@@ -11,5 +11,5 @@ OpenAPI Generator version: 5.4.0
11
11
  =end
12
12
 
13
13
  module VgsApiClient
14
- VERSION = '0.0.1.alpha202205041401'
14
+ VERSION = '0.0.1.alpha202205061657'
15
15
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module VGS
2
- VERSION = '0.0.1.alpha202205041401'
2
+ VERSION = '0.0.1.alpha202205061657'
3
3
  end
@@ -1,19 +1,48 @@
1
1
  require 'openapi_client'
2
2
 
3
3
  module VGS
4
- class VgsApiException < StandardError
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|
15
44
  VgsApiClient::CreateAliasesRequestNew.new(attributes = {
16
- :format => VgsApiClient::AliasFormat.build_from_hash(item[:format] || "UUID"),
45
+ :format => VgsApiClient::AliasFormat.build_from_hash(item[:format]),
17
46
  :classifiers => item[:classifiers],
18
47
  :value => item[:value],
19
48
  :storage => item[:storage]
@@ -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
- rescue
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 VgsApiException, "Failed to reveal aliases #{ aliases }"
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 VgsApiException, "Failed to delete alias #{ _alias }"
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 VgsApiException, "Failed to update alias #{ _alias }"
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
@@ -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.alpha202205041401 . | xargs sed -i "s/0.0.1.alpha202205041401/${LIB_VERSION}/g"
6
+ grep -rl 0.0.1.alpha202205061657 . | xargs sed -i "s/0.0.1.alpha202205061657/${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.alpha202205041401 . | xargs sed -i "s/0.0.1.alpha202205041401/$VERSION/g"
8
+ grep -rl 0.0.1.alpha202205061657 . | xargs sed -i "s/0.0.1.alpha202205061657/$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(:all) do
6
+ before(:each) do
7
7
  config = VGS.config(username = ENV['VAULT_API_USERNAME'], password = ENV['VAULT_API_PASSWORD'])
8
- @aliases_api = VGS::Aliases.new config
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 = @aliases_api.redact data
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 = @aliases_api.redact(data).map { |item| item.aliases[0]._alias }
83
+ aliases = @api.redact(data).map { |item| item.aliases[0]._alias }
50
84
 
51
- response = @aliases_api.reveal aliases
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(original_values)).to eq Set.new(revealed_values)
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 = @aliases_api.redact(data).map { |item| item.aliases[0]._alias }[0]
100
+ _alias = @api.redact(data).map { |item| item.aliases[0]._alias }[0]
67
101
 
68
- @aliases_api.update _alias, classifiers: %w[secure]
102
+ @api.update _alias, classifiers: %w[secure]
69
103
 
70
- response = @aliases_api.reveal(_alias)
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 = @aliases_api.redact(data).map { |item| item.aliases[0]._alias }[0]
115
+ _alias = @api.redact(data).map { |item| item.aliases[0]._alias }[0]
82
116
 
83
- @aliases_api.delete _alias
117
+ @api.delete _alias
84
118
 
85
- expect { @aliases_api.reveal(_alias) }.to raise_error(VGS::VgsApiException)
119
+ expect { @api.reveal _alias }.to raise_error(VGS::VgsApiError)
86
120
  end
87
121
  end
88
122
 
@@ -9,8 +9,8 @@ Gem::Specification.new do |s|
9
9
  s.authors = ["Very Good Security"]
10
10
  s.email = ["support@verygoodsecurity.com"]
11
11
  s.homepage = "https://github.com/verygoodsecurity/vgs-api-client-ruby"
12
- s.summary = "Very Good Security API Client"
13
- s.description = "Very Good Security API Client library. More details on https://www.verygoodsecurity.com/"
12
+ s.summary = "VGS API Client"
13
+ s.description = "This gem maps to VGS Vault API"
14
14
  s.license = "BSD-3-Clause"
15
15
  s.required_ruby_version = ">= 2.6"
16
16
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vgs_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.alpha202205041401
4
+ version: 0.0.1.alpha202205061657
5
5
  platform: ruby
6
6
  authors:
7
7
  - Very Good Security
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-04 00:00:00.000000000 Z
11
+ date: 2022-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: typhoeus
@@ -50,7 +50,7 @@ dependencies:
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
52
  version: 3.6.0
53
- description: Very Good Security API Client library. More details on https://www.verygoodsecurity.com/
53
+ description: This gem maps to VGS Vault API
54
54
  email:
55
55
  - support@verygoodsecurity.com
56
56
  executables: []
@@ -132,7 +132,7 @@ requirements: []
132
132
  rubygems_version: 3.3.7
133
133
  signing_key:
134
134
  specification_version: 4
135
- summary: Very Good Security API Client
135
+ summary: VGS API Client
136
136
  test_files:
137
137
  - spec/api_client_spec.rb
138
138
  - spec/configuration_spec.rb