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

Add a default params_to_attributes for EmbeddedAutomationManager Authentications #22570

Merged
merged 4 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def self.display_name(number = 1)
end

def self.params_to_attributes(params)
attrs = params.dup
attrs = super.dup
attrs[:auth_key] = attrs.delete(:security_token) if attrs.key?(:security_token)
attrs
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def self.display_name(number = 1)
end

def self.params_to_attributes(params)
attrs = params.dup
attrs = super.dup
attrs[:auth_key] = attrs.delete(:secret) if attrs.key?(:secret)

if %i[client tenant subscription].any? {|opt| attrs.has_key? opt }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def self.display_name(number = 1)
end

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

attrs[:auth_key] = attrs.delete(:ssh_key_data) if attrs.key?(:ssh_key_data)
attrs[:options] = { :project => attrs.delete(:project) } if attrs[:project]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def self.display_name(number = 1)
end

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

attrs[:auth_key] = attrs.delete(:ssh_key_data) if attrs.key?(:ssh_key_data)
attrs[:auth_key_password] = attrs.delete(:ssh_key_unlock) if attrs.key?(:ssh_key_unlock)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def self.display_name(number = 1)
end

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

attrs[:auth_key] = attrs.delete(:ssh_key_data) if attrs.key?(:ssh_key_data)
attrs[:auth_key_password] = attrs.delete(:ssh_key_unlock) if attrs.key?(:ssh_key_unlock)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def self.display_name(number = 1)
end

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

if %i[host domain project].any? {|opt| attrs.has_key? opt }
attrs[:options] ||= {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def self.display_name(number = 1)
end

def self.params_to_attributes(params)
attrs = params.dup
attrs = super.dup
attrs[:options] = { :host => attrs.delete(:host) } if attrs[:host]
attrs
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def self.display_name(number = 1)
alias vault_password password

def self.params_to_attributes(params)
attrs = params.dup
attrs = super.dup
attrs[:password] = attrs.delete(:vault_password) if attrs.key?(:vault_password)
attrs
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def self.display_name(number = 1)
end

def self.params_to_attributes(params)
attrs = params.dup
attrs = super.dup
attrs[:options] = { :host => attrs.delete(:host) } if attrs[:host]
attrs
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ def self.display_name(number = 1)

include ManageIQ::Providers::EmbeddedAutomationManager::CrudCommon

def self.params_to_attributes(_params)
raise NotImplementedError, "must be implemented in a subclass"
def self.params_to_attributes(params)
allowed_params = self::API_ATTRIBUTES.pluck(:id) + %w[name type options]
Copy link
Member

Choose a reason for hiding this comment

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

did you want to put name, type, options into COMMON_ATTRIBUTES?

Copy link
Member Author

Choose a reason for hiding this comment

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

No because API_ATTRIBUTES is used by ui-classic to build dynamic dialogs (https://github.com/ManageIQ/manageiq-ui-classic/blob/master/app/helpers/ansible_credential_helper/textual_summary.rb#L15) so if we add them there they will show up on the UI which we don't want.

unpermitted_params = params.keys.map(&:to_s) - allowed_params
raise ArgumentError, _("Invalid parameters: %{params}" % {:params => unpermitted_params.join(", ")}) if unpermitted_params.any?

params
end

def self.raw_create_in_provider(manager, params)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def self.display_name(number = 1)
end

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

attrs[:auth_key] = attrs.delete(:ssh_key_data) if attrs.key?(:ssh_key_data)
attrs[:auth_key_password] = attrs.delete(:ssh_key_unlock) if attrs.key?(:ssh_key_unlock)
Expand Down