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

Fixes #32081 - Add provider specific inputs #569

Merged
merged 3 commits into from
May 10, 2021

Conversation

xprazak2
Copy link
Contributor

Adds inputs that will be displayed for each template
of a specified provider.

@xprazak2
Copy link
Contributor Author

Not sure if mimicking template input is the best, I am open to suggestions.

@ezr-ondrej
Copy link
Member

Simpliest IMHO would be just render provider specific template and let providers define the fields. Then we probably could just have an hash of values on provider and no extra model.
Although this is bit more clean...

@xprazak2 xprazak2 force-pushed the provider-input branch 4 times, most recently from 71453ab to f5e66ed Compare March 17, 2021 12:35
@xprazak2
Copy link
Contributor Author

Provider inputs can now be submitted via API as regular template inputs.

@ares
Copy link
Member

ares commented Mar 22, 2021

Provider inputs can now be submitted via API as regular template inputs.

Is that a good thing? How do I as a user know which are job inputs and which are execution specific? If I understand this correctly, as a user I'd in hammer do something like inputs="command=mc,tags=a,b,c"?. Which also brings a question of how many levels of commas would actually work.

@xprazak2
Copy link
Contributor Author

xprazak2 commented Mar 22, 2021

I thought we wanted that so that user does not have to distinguish between what is template input and what is provider input.

I am not sure how hammer handles inputs now, buy I expect we would be able to take escaped values such as inputs="command=mc,tags='a,b,c'".

Or should I revert to having provider inputs separately?

@ares
Copy link
Member

ares commented Mar 23, 2021

I thought we wanted that so that user does not have to distinguish between what is template input and what is provider input.

Perhaps I wasn't clear much then. I think we should distinguish, since (template) inputs are inputs for the job while provider inputs modify the actual engine execution. They should be on the same level as other execution attributes, e.g. effective user, concurrency level. As discussed online, perhaps the best place would be in provider specific subset (we have ssh and ansible today) where we have the effective user right now.

Adds inputs that will be displayed for each template
of a specified provider.
@xprazak2
Copy link
Contributor Author

All green now.

@job_invocation_params = job_invocation_params
end

def permit_provider_inputs(invocation_params)
providers = RemoteExecutionProvider.providers.values.reject { |provider| !provider.respond_to?(:provider_input_namespace) || provider.provider_input_namespace.empty? }
providers.map { |provider| invocation_params.dig(*provider.provider_input_namespace)&.permit! }
Copy link
Contributor

Choose a reason for hiding this comment

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

permit! modifies the parameters in-place?

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, inspired by what job_invocation_params does. Do you have a different approach in mind?

Copy link
Contributor

Choose a reason for hiding this comment

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

If we just do this for the side effect then we could each instead of map since we discard the result anway

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replaced with each.

@@ -35,6 +35,10 @@ def humanized_name
self.name
end

def provider_input_namespace
[]
Copy link
Contributor

Choose a reason for hiding this comment

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

From the name of the method I'd expect a single value, such as a symbol or a string. Why is it an array? Are elements of the array components of the namespace or can a provider have multiple input namespaces?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe I am making it more complicated than it needs to be, changed.

Copy link
Member

@ezr-ondrej ezr-ondrej left a comment

Choose a reason for hiding this comment

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

Just some general questions.

@@ -0,0 +1,10 @@
class AddProviderInputs < ActiveRecord::Migration[6.0]
def change
create_table :template_invocation_provider_input_values do |t|
Copy link
Member

Choose a reason for hiding this comment

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

don't we want to simplify the table name? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any suggestions?

Copy link
Member

Choose a reason for hiding this comment

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

I think at least invocation_provider_input_values 🤔 but no hard feelings aganst this name.

class AddProviderInputs < ActiveRecord::Migration[6.0]
def change
create_table :template_invocation_provider_input_values do |t|
t.references :template_invocation, :null => false, :index => { :name => 'idx_templ_inv_provider_input_values_on_templ_inv_id' }
Copy link
Member

Choose a reason for hiding this comment

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

why are we naming the index? why not just index: true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because autogenerated index name is too long and it crashes the migration.

Copy link
Member

Choose a reason for hiding this comment

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

would simplier name of the table help ? 🤔

@@ -74,6 +74,14 @@
<% end %>

<div class="advanced hidden">
<%= job_template_fields.fields_for :provider_input_values do |provider_input_fields| %>
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be more straight forward if we would have the namespaces here as well?
Just an idea, I don't insist, but seems like it 🤷

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, it would add another level of nesting into the form so I am a bit hesitant to call it straightforward, but I can certainly add it if you prefer.

Copy link
Member

Choose a reason for hiding this comment

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

no, I'm ok both ways, I just don't like going totally different path API vs UI, but this is minor difference for a good reason, so I can live with that 👍

@xprazak2
Copy link
Contributor Author

xprazak2 commented May 5, 2021

I changed the table name, the generated index is still too long so I need to supply a shorter name.

@xprazak2 xprazak2 force-pushed the provider-input branch 2 times, most recently from 812be55 to fda4280 Compare May 6, 2021 15:31
Copy link
Member

@ezr-ondrej ezr-ondrej left a comment

Choose a reason for hiding this comment

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

I need to test with ansible, but code LGTM!

Copy link
Member

@ezr-ondrej ezr-ondrej left a comment

Choose a reason for hiding this comment

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

I'm unsure what black magic removes the namespace in hammer and makes it directly --tags but I guess it is ok and that's onlything I found 🤷
@adamruzicka anything against merging this?

@adamruzicka
Copy link
Contributor

Nope, I'm fine with it, let's get it in.

@adamruzicka adamruzicka merged commit cbe07c8 into theforeman:master May 10, 2021
@adamruzicka
Copy link
Contributor

Thank you @xprazak2 & @ezr-ondrej !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants