diff options
author | Marc A. Paradise <marc.paradise@gmail.com> | 2021-07-15 17:49:18 -0400 |
---|---|---|
committer | Marc A. Paradise <marc.paradise@gmail.com> | 2021-07-15 17:49:18 -0400 |
commit | 3362eef7cad1083d3ffecb55c17543510aac6ff3 (patch) | |
tree | bc81d2ed599e1749adcc76d98c0c5fb33d682f43 | |
parent | 0d04189350f483edfbc725d9d77aee9946e4f72c (diff) | |
download | chef-3362eef7cad1083d3ffecb55c17543510aac6ff3.tar.gz |
rubocop fixes
Signed-off-by: Marc A. Paradise <marc.paradise@gmail.com>
-rw-r--r-- | lib/chef/exceptions.rb | 1 | ||||
-rw-r--r-- | lib/chef/secret_fetcher/aws_secrets_manager.rb | 2 | ||||
-rw-r--r-- | lib/chef/secret_fetcher/azure_key_vault.rb | 6 | ||||
-rw-r--r-- | lib/chef/secret_fetcher/base.rb | 1 | ||||
-rw-r--r-- | spec/unit/secret_fetcher/azure_key_vault_spec.rb | 6 |
5 files changed, 9 insertions, 7 deletions
diff --git a/lib/chef/exceptions.rb b/lib/chef/exceptions.rb index dcb7146510..8e9bced8bb 100644 --- a/lib/chef/exceptions.rb +++ b/lib/chef/exceptions.rb @@ -296,6 +296,7 @@ class Chef class FetchFailed < RuntimeError; end class MissingSecretName < RuntimeError; end class InvalidSecretName < RuntimeError; end + class InvalidFetcherService < RuntimeError def initialize(given, fetcher_service_names) super("#{given} is not a supported secrets service. Supported services are: :#{fetcher_service_names.join(" :")}") diff --git a/lib/chef/secret_fetcher/aws_secrets_manager.rb b/lib/chef/secret_fetcher/aws_secrets_manager.rb index a04d90dcdf..954de943ef 100644 --- a/lib/chef/secret_fetcher/aws_secrets_manager.rb +++ b/lib/chef/secret_fetcher/aws_secrets_manager.rb @@ -43,7 +43,7 @@ class Chef # @param version [String] the secret version. Not usd at this time # @return Aws::SecretsManager::Types::GetSecretValueResponse def do_fetch(identifier, version) - client = Aws::SecretsManager::Client.new() + client = Aws::SecretsManager::Client.new result = client.get_secret_value(secret_id: identifier, version_stage: version) # These fields are mutually exclusive result.secret_string || result.secret_binary diff --git a/lib/chef/secret_fetcher/azure_key_vault.rb b/lib/chef/secret_fetcher/azure_key_vault.rb index 05452f0667..734bd94df1 100644 --- a/lib/chef/secret_fetcher/azure_key_vault.rb +++ b/lib/chef/secret_fetcher/azure_key_vault.rb @@ -28,8 +28,8 @@ class Chef http = Net::HTTP.new(secret_uri.host, secret_uri.port) http.use_ssl = true - response = http.get(secret_uri, { 'Authorization' => "Bearer #{token}", - 'Content-Type' => 'application/json' }) + response = http.get(secret_uri, { "Authorization" => "Bearer #{token}", + "Content-Type" => "application/json" }) # If an exception is not raised, we can be reasonably confident of the # shape of the result. @@ -44,7 +44,7 @@ class Chef def fetch_token token_uri = URI.parse("http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https%3A%2F%2Fvault.azure.net") http = Net::HTTP.new(token_uri.host, token_uri.port) - response = http.get(token_uri, { "Metadata" => "true"}) + response = http.get(token_uri, { "Metadata" => "true" }) body = JSON.parse(response.body) body["access_token"] end diff --git a/lib/chef/secret_fetcher/base.rb b/lib/chef/secret_fetcher/base.rb index bfc3a44e4c..36b63990c0 100644 --- a/lib/chef/secret_fetcher/base.rb +++ b/lib/chef/secret_fetcher/base.rb @@ -44,6 +44,7 @@ class Chef # @raise [Chef::Exceptions::Secret::FetchFailed] when the underlying attempt to fetch the secret fails. def fetch(name, version = nil) raise Chef::Exceptions::Secret::MissingSecretName.new if name.to_s == "" + do_fetch(name, version) end diff --git a/spec/unit/secret_fetcher/azure_key_vault_spec.rb b/spec/unit/secret_fetcher/azure_key_vault_spec.rb index 61af88caad..cf8c5733c9 100644 --- a/spec/unit/secret_fetcher/azure_key_vault_spec.rb +++ b/spec/unit/secret_fetcher/azure_key_vault_spec.rb @@ -27,9 +27,9 @@ describe Chef::SecretFetcher::AzureKeyVault do context "when validating configuration and configuration is missing :vault" do context "and configuration does not have a 'vault'" do - let(:config) { { } } + let(:config) { {} } it "raises a MissingVaultError error on validate!" do - expect{fetcher.validate!}.to raise_error(Chef::Exceptions::Secret::MissingVaultName) + expect { fetcher.validate! }.to raise_error(Chef::Exceptions::Secret::MissingVaultName) end end end @@ -54,7 +54,7 @@ describe Chef::SecretFetcher::AzureKeyVault do context "and an error response is received in the body" do let(:body) { '{ "error" : { "code" : 404, "message" : "secret not found" } }' } it "raises FetchFailed" do - expect{fetcher.fetch("value")}.to raise_error(Chef::Exceptions::Secret::FetchFailed) + expect { fetcher.fetch("value") }.to raise_error(Chef::Exceptions::Secret::FetchFailed) end end |