-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Use rails credentials instead of secrets #928
base: master
Are you sure you want to change the base?
Changes from 2 commits
be14f86
62137fd
78d79f4
b89bf7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,24 +14,41 @@ | |
end | ||
end | ||
|
||
TEST_CREDENTIALS_DEFAULTS = { | ||
:vmware_cloud_defaults => {:host => "vmwarecloudhost", :userid => "VMWARE_CLOUD_USERID", :password => "VMWARE_CLOUD_PASSWORD"}, | ||
:vmware_infra_defaults => {:hostname => "HOSTNAME"}, | ||
:vmware_tanzu_defaults => {:hostname => "vmware-tanzu-hostname", :userid => "VMWARE_TANZU_USERID", :password => "VMWARE_TANZU_PASSWORD"} | ||
}.freeze | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @agrare I'm thinking this constant ☝️ would live in each plugin... The two methods below could live in core spec/shared: |
||
|
||
def test_credentials(*args) | ||
Rails.application.credentials.dig(*args) || test_credentials_defaults(*args) | ||
end | ||
|
||
def test_credentials_defaults(*args) | ||
args[0] = "#{args[0]}_defaults".to_sym | ||
TEST_CREDENTIALS_DEFAULTS.dig(*args) | ||
end | ||
|
||
VCR.configure do |config| | ||
# config.default_cassette_options = { :record => :all } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. placeholder to verify cassette recording uses the correct values from local rails credentials and falls back to the defaults. |
||
|
||
config.ignore_hosts 'codeclimate.com' if ENV['CI'] | ||
config.cassette_library_dir = File.join(ManageIQ::Providers::Vmware::Engine.root, 'spec/vcr_cassettes') | ||
|
||
secrets = Rails.application.secrets | ||
config.define_cassette_placeholder(Rails.application.secrets.vmware_infra_defaults[:hostname]) do | ||
Rails.application.secrets.vmware_infra[:hostname] | ||
config.define_cassette_placeholder(test_credentials_defaults(:vmware_infra_defaults, :hostname)) do | ||
test_credentials(:vmware_infra, :hostname) | ||
end | ||
config.define_cassette_placeholder(Rails.application.secrets.vmware_cloud_defaults[:host]) do | ||
Rails.application.secrets.vmware_cloud[:host] | ||
config.define_cassette_placeholder(test_credentials_defaults(:vmware_cloud, :host)) do | ||
test_credentials(:vmware_cloud, :host) | ||
end | ||
config.define_cassette_placeholder("VMWARE_CLOUD_AUTHORIZATION") do | ||
Base64.encode64("#{Rails.application.secrets.vmware_cloud[:userid]}:#{Rails.application.secrets.vmware_cloud[:password]}").chomp | ||
Base64.encode64("#{test_credentials(:vmware_cloud, :userid)}:#{test_credentials(:vmware_cloud, :password)}").chomp | ||
end | ||
config.define_cassette_placeholder("VMWARE_CLOUD_INVALIDAUTHORIZATION") do | ||
Base64.encode64("#{Rails.application.secrets.vmware_cloud[:userid]}:invalid").chomp | ||
end | ||
secrets.vmware_tanzu.each do |key, val| | ||
config.define_cassette_placeholder(secrets.vmware_tanzu_defaults[key]) { val } | ||
Base64.encode64("#{test_credentials(:vmware_cloud, :userid)}:invalid").chomp | ||
end | ||
|
||
config.define_cassette_placeholder(test_credentials_defaults(:vmware_tanzu, :hostname)) { test_credentials(:vmware_tanzu, :hostname) } | ||
config.define_cassette_placeholder(test_credentials_defaults(:vmware_tanzu, :userid)) { test_credentials(:vmware_tanzu, :userid) } | ||
config.define_cassette_placeholder(test_credentials_defaults(:vmware_tanzu, :password)) { test_credentials(:vmware_tanzu, :password) } | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm open to make the constant have the
DEFAULTS
name an simplify the keys to no longer have defaults in the name to avoid redundancy. Let me know your thoughts.