Skip to content
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

Credential Mapping Form #8905

Merged
merged 1 commit into from
Sep 25, 2023

Conversation

DavidResende0
Copy link
Member

@DavidResende0 DavidResende0 commented Aug 29, 2023

Depends On: ManageIQ/manageiq#22685

Adds the new Credential Mapping form to the Embedded Workflows page.

Preview:
image

image

@DavidResende0 DavidResende0 requested a review from a team as a code owner August 29, 2023 21:03
@miq-bot miq-bot added the wip label Aug 29, 2023
@DavidResende0 DavidResende0 force-pushed the credential-mapping-form branch 4 times, most recently from fd52d11 to d9e1f0f Compare August 30, 2023 15:01
@DavidResende0 DavidResende0 changed the title [WIP] Credential Mapping Form Credential Mapping Form Aug 30, 2023
@miq-bot miq-bot removed the wip label Aug 30, 2023
@DavidResende0
Copy link
Member Author

@miq-bot cross-repo-tests ManageIQ/manageiq#22685

miq-bot pushed a commit to ManageIQ/manageiq-cross_repo-tests that referenced this pull request Aug 30, 2023
@DavidResende0 DavidResende0 force-pushed the credential-mapping-form branch 2 times, most recently from 5cd5286 to 628e9ba Compare August 30, 2023 20:43
@jeffibm
Copy link
Member

jeffibm commented Sep 5, 2023

Hey @DavidResende0 , could you please check the failing spec.

@agrare
Copy link
Member

agrare commented Sep 19, 2023

@DavidResende0 can you rebase this?

@DavidResende0 DavidResende0 force-pushed the credential-mapping-form branch 2 times, most recently from 7579d2b to 637658d Compare September 19, 2023 18:22
@DavidResende0
Copy link
Member Author

@miq-bot cross-repo-tests ManageIQ/manageiq#22685

miq-bot pushed a commit to ManageIQ/manageiq-cross_repo-tests that referenced this pull request Sep 19, 2023
@agrare
Copy link
Member

agrare commented Sep 19, 2023

Kicking after merge of ManageIQ/manageiq#22685

@agrare agrare closed this Sep 19, 2023
@agrare
Copy link
Member

agrare commented Sep 21, 2023

So for the record UX-wise it feels weird the way you select the credentials reference and do the mapping and it automatically gets set above as opposed to e.g. an explicit Set button it feels like you should have to hit something to "commit" the dropdown and then once you're done you would save the whole form.

@agrare
Copy link
Member

agrare commented Sep 21, 2023

@DavidResende0 can you try mapping credentials to the provision-vm.asl workflow from the workflows-examples repo? When I try I get the following error:

This happens whenever the credentials column is nil

image
image

@Fryguy
Copy link
Member

Fryguy commented Sep 22, 2023

Backend API PR is merged which fixes the "password" fields showing up.

@agrare
Copy link
Member

agrare commented Sep 22, 2023

I pushed a commit to use RBAC for looking up the workflow by params[:id]. This still has an issue if credentials => nil but we can fix that in a follow-up.

@Fryguy
Copy link
Member

Fryguy commented Sep 22, 2023

Do we have to solve the nested credentials keys first?

@agrare
Copy link
Member

agrare commented Sep 22, 2023

@Fryguy that was fixed by @DavidResende0 (at least the API sees the correct payload now)

[28, 37] in /home/grare/adam/src/manageiq/manageiq-api/app/controllers/api/configuration_script_payloads_controller.rb
   28:       # authentications_configuration_script_payloads join table.
   29:       unless data["credentials"].nil?
   30:         byebug
   31:         # Credentials can be a static string or a payload with an external
   32:         # Authentication record referenced by credential_ref and credential_field.
=> 33:         credential_refs = data["credentials"].values.select { |val| val.kind_of?(Hash) }.pluck("credential_ref")
   34:         # Lookup the Authentication record by ems_ref in the parent manager's
   35:         # list of authentications.
   36:         credentials     = resource.manager&.authentications&.where(:ems_ref => credential_refs) || []
   37:         # Filter the collection based on the current user's RBAC roles.
(byebug) data["credentials"]
{"api_user.$"=>{"credential_ref"=>"manageiq_api", "credential_field"=>"userid"}, "api_password.$"=>{"credential_ref"=>"manageiq_api", "credential_field"=>"userid"}}

@DavidResende0
Copy link
Member Author

@DavidResende0 can you try mapping credentials to the provision-vm.asl workflow from the workflows-examples repo? When I try I get the following error:

This happens whenever the credentials column is nil

image image

@agrare can you test this again, pretty sure I fixed it but want to make sure

@miq-bot
Copy link
Member

miq-bot commented Sep 22, 2023

Checked commit DavidResende0@363f677 with ruby 2.6.10, rubocop 1.28.2, haml-lint 0.35.0, and yamllint
5 files checked, 2 offenses detected

app/views/workflow/map_credentials.html.haml

  • ⚠️ - Line 1 - Layout/TrailingEmptyLines: Final newline missing.
  • ⚠️ - Line 1 - id attribute must be in lisp-case

Comment on lines +35 to +51
/*
Creates the list of credential references from the workflow payload by parsing each state and saving them to payloadCredentials.
Duplicate references get overridden.
*/
const jsonPayload = JSON.parse(payload).States;
let payloadCredentials = {};

Object.keys(jsonPayload).forEach((key1) => {
if (jsonPayload[key1].Credentials != null) {
Object.keys(jsonPayload[key1].Credentials).forEach((key2) => {
payloadCredentials = {
[key2]: jsonPayload[key1].Credentials[key2],
...payloadCredentials,
};
});
}
});
Copy link
Member

Choose a reason for hiding this comment

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

@agrare Discussed this with @DavidResende0 and while I'm ok with this for this PR, it seems weird to me that the UI would have to parse the payload since that's really the backend's job. I'm wondering if we should extract any credentials into a separate column, so they can be more easily accessed here. Thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

One way we could do this is pre-parse the payload and store those in the credentials column, but with a nil value. That way, this form would only show the keys and if those keys have non-nil values, then they must be mapped.

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 agree, this was actually something I discussed with @DavidResende0 a few weeks ago but I never got to implementing, I was thinking that when we load the payload and create the record we could pre-populate the credentials record with the keys that have to be filled in by the user

Copy link
Member

Choose a reason for hiding this comment

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

Ha just edged me out

@agrare
Copy link
Member

agrare commented Sep 22, 2023

@agrare can you test this again, pretty sure I fixed it but want to make sure

@DavidResende0 yes confirmed this is fixed now thanks

Copy link
Member

@Fryguy Fryguy left a comment

Choose a reason for hiding this comment

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

Overall LGTM

@agrare On the API side I think we need to ensure that the user can only set those 4 fields. i.e. we don't want them hacking in other fields.

@agrare
Copy link
Member

agrare commented Sep 25, 2023

I will put in a PR to return a Bad Request if any credential_fields are requested which don't match the credential class' API_ATTRIBUTES

@agrare agrare merged commit f91fdac into ManageIQ:master Sep 25, 2023
15 checks passed
@agrare
Copy link
Member

agrare commented Sep 25, 2023

@Fryguy
Copy link
Member

Fryguy commented Sep 27, 2023

Backported to quinteros in commit 71e1da4.

commit 71e1da4c09222b6c69d80645b5de0eac188fd27f
Author: Adam Grare <[email protected]>
Date:   Mon Sep 25 10:20:41 2023 -0400

    Merge pull request #8905 from DavidResende0/credential-mapping-form
    
    Credential Mapping Form
    
    (cherry picked from commit f91fdac52f0fab74b6a2b1f999bbd34cfa97c034)

Fryguy pushed a commit that referenced this pull request Sep 27, 2023
Credential Mapping Form

(cherry picked from commit f91fdac)
@Fryguy Fryguy mentioned this pull request Oct 10, 2023
22 tasks
@Fryguy Fryguy added this to the Quinteros milestone Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Quinteros
Development

Successfully merging this pull request may close these issues.

5 participants