-
Notifications
You must be signed in to change notification settings - Fork 897
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
create configuration script sources #14006
create configuration script sources #14006
Conversation
config/api.yml
Outdated
@@ -537,12 +537,15 @@ | |||
:description: Configuration Script Source | |||
:options: | |||
- :collection | |||
:verbs: *g | |||
:verbs: *gp |
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.
should probably be *gpppd
so that you can also update and delete..
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.
@himdel will be added when we work on update and delete
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.
thanks, no pressure :) (except that UI work is waiting for this... :D)
@miq-bot remove_label wip |
@@ -4,4 +4,10 @@ class ConfigurationScriptSource < ApplicationRecord | |||
belongs_to :manager, :class_name => "ExtManagementSystem" | |||
|
|||
virtual_total :total_payloads, :configuration_script_payloads | |||
|
|||
def self.class_from_request_data(data) | |||
manager = ExtManagementSystem.find(data['manager_resource']) |
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.
data['manager_resource'] is API payload dependent. Let's send in the object instead, i.e. class_for_manager(manager)
parse_href(data['manager_resource']['href']).last | ||
elsif data['manager_resource'].key?('id') | ||
data['manager_resource']['id'] | ||
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.
if think this can simply be:
def validate_attrs(data)
raise 'must supply a manager resource' unless data['manager_resource']
end
def create_resource(_type, _id, data) | ||
attrs = validate_attrs(data) | ||
type = ConfigurationScriptSource.class_from_request_data(attrs) | ||
raise 'type not currently supported' unless type.respond_to?(:create_in_provider_queue) |
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.
with the change below, above can be something like:
validate_attrs(data)
manager_id = parse_id(data['manager_resource'], :providers)
manager = resource_search(manager_id, :providers, collection_class(:providers))
type = ConfigurationScriptSource.class_for_manager(manager)
...
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.
once the model supports other than ExtManagementSystem, we can provide an different variant of parse_id that supports a list of collections, where it returns the collection and id. This way we know for sure what href we are parsing (and the correct collection accessed in the following resource_search).
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.
as for the message, maybe something like "ConfigurationScriptSources cannot be added to #{manager_ident(manager)}"
This pull request is not mergeable. Please rebase and repush. |
@@ -18,10 +18,30 @@ def delete_resource(type, id, _data = {}) | |||
action_result(false, err.to_s) | |||
end | |||
|
|||
def create_resource(_type, _id, data) | |||
validate_attrs(data) | |||
manager_id = parse_id(data['manager_resource'], :providers) |
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.
Can you add a check here before we do a resource_search,
raise "Must specify a valid manager_resource href or id" unless manager_id
and add a test for that bad_request, maybe passing in a bogus /api/users/10 href. Thanks.
Checked commits jntullo/manageiq@4f30275~...f2e1e79 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
Thanks @jntullo for this last update. LGTM!! 👍 |
Create configuration script sources
cc: @h-kataria @ZitaNemeckova
@miq-bot add_label enhancement, api, wip
@miq-bot assign @abellotti
Depends on #14173