-
Notifications
You must be signed in to change notification settings - Fork 0
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
Your wish is my command... #6
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module AnsibleRunnerAuthTranslations | ||
AUTH_TYPES = %i[credential vault_credential cloud_credential network_credential] | ||
|
||
module_function | ||
|
||
# Translates options hash with credential_ids into auth | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Along the same lines with my comment about adding specs, the docs on this probably could be fleshed out a bit too. |
||
# | ||
# @param [Hash] options Hash containing the credential_ids | ||
# @param [Hash] other_hash (options) Data to be updated if differs from <options> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
#namingIsHard™ |
||
# @param [Boolean] mutate_options (false) If passed in option keys should be removed, set to true | ||
# | ||
def translate_credentials!(options, other_hash: nil, mutate_options: false) | ||
other_hash ||= options | ||
|
||
AUTH_TYPES.each do |credential| | ||
credential_sym = "#{credential}_id".to_sym | ||
credential_id = mutate_options ? options.delete(credential_sym) : options[credential_sym] | ||
other_hash[credential] = Authentication.find(credential_id).native_ref if credential_id.present? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I covered all of the corner cases with this by using Probably want to test this mixin directly and heavily just in case someone comes and changes this method and does something unexpected. |
||
end | ||
end | ||
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.
By making this method a
module_function
, this can be called in two ways:include
ing it, and calling it as we have done currently (as if it were a method in the class)module
directly as if it was a class method (similar toFileUtils
)The second form would look like:
Which has the advantage of not adding methods to the classes we are writing this for, though, when adding a module that has
module_function
s, it should add them into the private space (I think...).