Skip to content

Conversation

@putmanoj
Copy link
Contributor

  • Add cloud credentials classes for embedded-terraform with DDF configuration
  • Add cloud credentails classes with authentication connection parameters for terraform-runner


def self.params_to_attributes(params)
attrs = super.dup
attrs[:auth_key] = attrs.delete(:security_token) if attrs.key?(:security_token)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why call a property security_token if we're just going to store it in auth_key, could you use "auth_key" instead up here ☝️ https://github.com/ManageIQ/manageiq-providers-embedded_terraform/pull/16/files#diff-10eac92f3aa8adb511c059784672e62020e8e6172d8154c295c6a5678c75007fR29-R30

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. We also have an alias for security_token from auth_key so hopefully we can use auth_key everywhere to keep it consistent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I understand having the :label be something specific but wasn't sure what having the internal key being different from the column bought us

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, even better. Let's just use auth_key. I don't think it makes sense to translate one field to another unless we have a good reason.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be done in a follow-up

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, I'll do this in a follow up. no need to delay merging on this.

def self.params_to_attributes(params)
attrs = super.dup

attrs[:auth_key] = attrs.delete(:ssh_key_data) if attrs.key?(:ssh_key_data)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically the same question here as above (and looks like for a number of these). Maybe there is a good reason? IDK

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I don't think we should blindly copy&paste from other code without thinking about it first :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll get this for followup.

Comment on lines 103 to 117
if %i[host domain project region cacert clientcert clientkey insecure].any? { |opt| attrs.has_key?(opt) }
attrs[:options] ||= {}
attrs[:options][:host] = attrs.delete(:host) if attrs.key?(:host)
attrs[:options][:domain] = attrs.delete(:domain) if attrs.key?(:domain)
attrs[:options][:project] = attrs.delete(:project) if attrs.key?(:project)
attrs[:options][:region] = attrs.delete(:region) if attrs.key?(:region)

attrs[:options][:cacert] = attrs.delete(:cacert) if attrs.key?(:cacert)
attrs[:options][:clientcert] = attrs.delete(:clientcert) if attrs.key?(:clientcert)
attrs[:options][:clientkey] = attrs.delete(:clientkey) if attrs.key?(:clientkey)

attrs[:options][:insecure] = attrs.delete(:insecure) if attrs.key?(:insecure)
end

attrs
Copy link
Member

@jrafanie jrafanie Apr 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think something like this does what you're trying to do:

Suggested change
if %i[host domain project region cacert clientcert clientkey insecure].any? { |opt| attrs.has_key?(opt) }
attrs[:options] ||= {}
attrs[:options][:host] = attrs.delete(:host) if attrs.key?(:host)
attrs[:options][:domain] = attrs.delete(:domain) if attrs.key?(:domain)
attrs[:options][:project] = attrs.delete(:project) if attrs.key?(:project)
attrs[:options][:region] = attrs.delete(:region) if attrs.key?(:region)
attrs[:options][:cacert] = attrs.delete(:cacert) if attrs.key?(:cacert)
attrs[:options][:clientcert] = attrs.delete(:clientcert) if attrs.key?(:clientcert)
attrs[:options][:clientkey] = attrs.delete(:clientkey) if attrs.key?(:clientkey)
attrs[:options][:insecure] = attrs.delete(:insecure) if attrs.key?(:insecure)
end
attrs
unless (attrs.keys & %i[host domain project region cacert clientcert clientkey insecure]).empty?
attrs.slice!(:host, :domain, :project, :region, :cacert, :clientkey, :insecure)
end
{:options => attrs}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there other values you're concerned about retaining? The slice option will only remove all key/values that aren't in the list so if you have others that aren't in that list, they'll be lost.

Copy link
Member

@agrare agrare Apr 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think attrs will have more than just these keys like userid / password so we can't replace the top level hash with just {:options =>
What about something like

options = super.dup
attrs = options.slice!(:host, :domain, :project, :region, :cacert, :clientkey, :insecure)
attrs.merge!(:options => options) unless options.blank?
attrs

attrs will now have the rest of the keys that aren't in the slice! which should be the rest of the top level keys.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, we have this pattern in params_to_attributes to pull out specific keys from attrs and store them in the :options subkey instead. Perhaps extract a method move_keys_to_options from above.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or not... this one is the most complicated one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, we have this pattern in params_to_attributes to pull out specific keys from attrs and store them in the :options subkey instead. Perhaps extract a method move_keys_to_options from above.

Yeah I wonder if maybe defining accessors would help clean this up? Like

def clientkey
  options && options[:clientkey]
end

def clientkey=(val)
  options ||= {}
  options[:clientkey] = val
end

Then we probably don't need to override params_to_attributes at all. This would be a lot of change maybe something for a followup

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup, followup is good

{
:component => 'checkbox',
:label => N_('Trust self-signed SSL certificates ?'),
:helperText => N_('Trust self-signed SSL certificates ?'),
Copy link
Member

@jrafanie jrafanie Apr 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the same thing as VERIFY_NONE (when insecure true) vs. VERIFY_PEER (when insecure false)? We call that Verify SSL, SSL Verification or SSL Verify Mode elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can improve the label text ,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Though by default insecure is false by default, so is OFF or 'unchecked'.
https://registry.terraform.io/providers/terraform-provider-openstack/openstack/latest/docs#insecure

If we use Verify SSL as label, then meaning changes, ...
the checkbox needs to be 'ON' or 'checked' by default. Just don't know enough DDF yet, to know how to make checkbox 'checked' by default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrafanie , any other label suggestion ?

Copy link
Member

@jrafanie jrafanie Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, we should use positive terms "Verify SSL" with it checked/enabled by default. We can with check @GilbertCherrie if we're not seeing it "on" by default.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can merge as is and I'll work with @GilbertCherrie if I can't figure out how to correctly switch the logic. I like "verify ssl" true/false as insecure "false" is a double negative and hard to understand.

@jrafanie
Copy link
Member

jrafanie commented Apr 23, 2024

With #3 and ManageIQ/manageiq-ui-classic#9117 (rebased) locally and this PR... here are some screenshots of the credentials we're defining here:

amazon:
image

azure:
image

google:
image

ibm cloud (quite wordy)
image

openstack 1:
image

openstack 2:

image

scm:
image

vsphere:
image

@Fryguy Fryguy added the enhancement New feature or request label Apr 24, 2024
Copy link
Member

@jrafanie jrafanie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@putmanoj let ms know if there's any suggested changes you'd like me to work on... Some of these can be things we do in followup PRs. Anything resolved, we can mark resolved and any still remaining, we can choose to not resolve at all or leave them for followup work.

{
:component => 'checkbox',
:label => N_('Trust self-signed SSL certificates ?'),
:helperText => N_('Trust self-signed SSL certificates ?'),
Copy link
Member

@jrafanie jrafanie Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, we should use positive terms "Verify SSL" with it checked/enabled by default. We can with check @GilbertCherrie if we're not seeing it "on" by default.

@jrafanie jrafanie force-pushed the add-cloud-creds-support-for-terraform-runner branch from 3678f85 to 101cd17 Compare April 29, 2024 19:21
@miq-bot
Copy link
Member

miq-bot commented Apr 29, 2024

Checked commits putmanoj/manageiq-providers-embedded_terraform@816f9c8~...101cd17 with ruby 2.7.8, rubocop 1.56.3, haml-lint 0.51.0, and yamllint
32 files checked, 0 offenses detected
Everything looks fine. 👍

@agrare agrare merged commit 55bbd92 into ManageIQ:master Apr 29, 2024
@putmanoj putmanoj deleted the add-cloud-creds-support-for-terraform-runner branch April 30, 2024 02:21
agrare added a commit that referenced this pull request May 20, 2024
Simplify description from credentials PR #16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants