-
Notifications
You must be signed in to change notification settings - Fork 11
Split ibm cloud credentials from ibm classic infra credentials #23
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
Merged
agrare
merged 2 commits into
ManageIQ:master
from
jrafanie:split_ibm_cloud_into_cloud_and_classic_infra_credentials
May 20, 2024
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
.../providers/embedded_terraform/automation_manager/ibm_classic_infrastructure_credential.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| class ManageIQ::Providers::EmbeddedTerraform::AutomationManager::IbmClassicInfrastructureCredential < ManageIQ::Providers::EmbeddedTerraform::AutomationManager::TemplateCredential | ||
| COMMON_ATTRIBUTES = [].freeze | ||
|
|
||
| EXTRA_ATTRIBUTES = [ | ||
| { | ||
| :component => 'text-field', | ||
| :label => N_('IBM Cloud Classic Infrastructure User Name'), | ||
| :helperText => N_('The User Name for IBM Cloud Classic Infrastructure.'), | ||
| :name => 'userid', | ||
| :id => 'userid', | ||
| :maxLength => 100, | ||
| :isRequired => true, | ||
| :validate => [{:type => 'required'}], | ||
| }, | ||
| { | ||
| :component => 'password-field', | ||
| :label => N_('IBM Cloud Classic Infrastructure API Key'), | ||
| :helperText => N_('The API key for IBM Cloud Classic Infrastructure.'), | ||
| :name => 'password', | ||
| :id => 'password', | ||
| :type => 'password', | ||
| :isRequired => true, | ||
| :validate => [{:type => 'required'}], | ||
| }, | ||
| ].freeze | ||
|
|
||
| API_ATTRIBUTES = (COMMON_ATTRIBUTES + EXTRA_ATTRIBUTES).freeze | ||
|
|
||
| API_OPTIONS = { | ||
| :type => 'cloud', | ||
| :label => N_('IBM Cloud Classic Infrastructure'), | ||
| :attributes => API_ATTRIBUTES | ||
| }.freeze | ||
|
|
||
| def self.display_name(number = 1) | ||
| n_('Credential (IBM Cloud Classic Infrastructure)', 'Credentials (IBM Cloud Classic Infrastructure)', number) | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| class ManageIQ::Providers::EmbeddedTerraform::AutomationManager::IbmCloudCredential < ManageIQ::Providers::EmbeddedTerraform::AutomationManager::TemplateCredential | ||
| COMMON_ATTRIBUTES = [ | ||
| COMMON_ATTRIBUTES = [].freeze | ||
|
|
||
| EXTRA_ATTRIBUTES = [ | ||
| { | ||
| :component => 'password-field', | ||
| :label => N_('IBM Cloud API Key'), | ||
| :helperText => N_('The API key for IBM Cloud. A value for this field is required if classic user name and classic API key are not provided. A valid connection must have value for IBM Cloud API Key or, IBM Cloud Classic Infrastructure User Name and IBM Cloud Classic Infrastructure API Key.'), | ||
| :helperText => N_('The API key for IBM Cloud.'), | ||
| :name => 'auth_key', | ||
| :id => 'auth_key', | ||
| :type => 'password', | ||
|
|
@@ -12,25 +14,6 @@ class ManageIQ::Providers::EmbeddedTerraform::AutomationManager::IbmCloudCredent | |
| }, | ||
| ].freeze | ||
|
|
||
| EXTRA_ATTRIBUTES = [ | ||
| { | ||
| :component => 'text-field', | ||
| :label => N_('IBM Cloud Classic Infrastructure User Name'), | ||
| :helperText => N_('The User Name for IBM Cloud Classic Infrastructure. A value for this field is required when using classic IBM Cloud resources. A valid connection must have value for IBM Cloud API Key or, IBM Cloud Classic Infrastructure User Name and IBM Cloud Classic Infrastructure API Key.'), | ||
| :name => 'classic_user', | ||
| :id => 'classic_user', | ||
| :maxLength => 100, | ||
| }, | ||
| { | ||
| :component => 'password-field', | ||
| :label => N_('IBM Cloud Classic Infrastructure API Key'), | ||
| :helperText => N_('The API key for IBM Cloud Classic Infrastructure A value for this field is required when using classic IBM Cloud resources. A valid connection must have value for IBM Cloud API Key or, IBM Cloud Classic Infrastructure User Name and IBM Cloud Classic Infrastructure API Key.'), | ||
| :name => 'classic_key', | ||
| :id => 'classic_key', | ||
| :type => 'password', | ||
| }, | ||
| ].freeze | ||
|
|
||
| API_ATTRIBUTES = (COMMON_ATTRIBUTES + EXTRA_ATTRIBUTES).freeze | ||
|
|
||
| API_OPTIONS = { | ||
|
|
@@ -42,17 +25,4 @@ class ManageIQ::Providers::EmbeddedTerraform::AutomationManager::IbmCloudCredent | |
| def self.display_name(number = 1) | ||
| n_('Credential (IBM Cloud)', 'Credentials (IBM Cloud)', number) | ||
| end | ||
|
|
||
| def self.params_to_attributes(params) | ||
| attrs = super.dup | ||
|
|
||
| attrs[:auth_key] = attrs.delete(:auth_key) if attrs.key?(:auth_key) | ||
|
|
||
| if %i[classic_user classic_key].any? { |opt| attrs.key?(opt) } | ||
| attrs[:userid] = attrs.delete(:classic_user) if attrs.key?(:classic_user) | ||
| attrs[:password] = attrs.delete(:classic_key) if attrs.key?(:classic_key) | ||
| end | ||
|
Member
Author
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. I think this just goes away if classic user/key are moved to the other class as auth_key is required, right?
Member
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. Not sure - @agrare ? |
||
|
|
||
| attrs | ||
| end | ||
| end | ||
24 changes: 24 additions & 0 deletions
24
lib/terraform/runner/ibm_classic_infrastructure_credential.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| module Terraform | ||
| class Runner | ||
| class IbmClassicInfrastructureCredential < Credential | ||
| def self.auth_type | ||
| "ManageIQ::Providers::EmbeddedTerraform::AutomationManager::IbmClassicInfrastructureCredential" | ||
| end | ||
|
|
||
| # Modeled off of IBM Cloud provider for terraform: | ||
| # | ||
| # https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs#environment-variables | ||
| # | ||
| # Return connection_parameters as required for terraform_runner | ||
| # | ||
| def connection_parameters | ||
| conn_params = [] | ||
|
|
||
| ApiParams.add_param_if_present(conn_params, auth.userid, 'IAAS_CLASSIC_USERNAME') | ||
| ApiParams.add_param_if_present(conn_params, auth.password, 'IAAS_CLASSIC_API_KEY') | ||
|
|
||
| conn_params | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
spec/lib/terraform/runner/ibm_classic_infrastructure_credential_spec.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| require 'terraform/runner' | ||
|
|
||
| RSpec.describe(Terraform::Runner::IbmClassicInfrastructureCredential) do | ||
| it ".auth_type is the correct Authentication sub-class" do | ||
| expect(described_class.auth_type).to(eq("ManageIQ::Providers::EmbeddedTerraform::AutomationManager::IbmClassicInfrastructureCredential")) | ||
| end | ||
|
|
||
| context "with a credential object" do | ||
| let(:auth) { FactoryBot.create(:embedded_terraform_ibm_classic_infrastructure_credential, auth_attributes) } | ||
| let(:auth_attributes) do | ||
| { | ||
| :userid => 'iaas-classic-username', | ||
| :password => 'iaas-classic-api-key', | ||
| } | ||
| end | ||
|
|
||
| let(:cred) { described_class.new(auth.id) } | ||
|
|
||
| # Modeled off of IBM Cloud provider for terraform: | ||
| # | ||
| # https://registry.terraform.io/providers/IBM-Cloud/ibm/latest/docs#environment-variables | ||
| # | ||
| describe "#connection_parameters" do | ||
| it "adds IAAS_CLASSIC_USERNAME, IAAS_CLASSIC_USERNAME if present" do | ||
| auth.update!(:auth_key => '') | ||
| expected = [ | ||
| { | ||
| 'name' => 'IAAS_CLASSIC_USERNAME', | ||
| 'value' => 'iaas-classic-username', | ||
| 'secured' => 'false', | ||
| }, | ||
| { | ||
| 'name' => 'IAAS_CLASSIC_API_KEY', | ||
| 'value' => 'iaas-classic-api-key', | ||
| 'secured' => 'false', | ||
| }, | ||
| ] | ||
| expect(cred.connection_parameters).to(eq(expected)) | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 renamed these to userid and password so we don't need to define
params_to_attributeshere.