Skip to content

Commit

Permalink
Add a default params_to_attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
agrare committed Jun 17, 2023
1 parent 82ffeac commit 4696948
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 12 deletions.
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
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
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

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

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

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

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
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
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
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 = API_ATTRIBUTES.pluck(:id)
unpermitted_params = params.keys - 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

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

0 comments on commit 4696948

Please sign in to comment.