From a53609ddfff483e53a0a42d5bc8b48545f2917de Mon Sep 17 00:00:00 2001 From: Nick Carboni Date: Tue, 23 Jul 2019 18:09:06 -0400 Subject: [PATCH] Remove the AnsibleAuthentications mixin This was created to store the AWX installation metadata as authentication rows referencing some other AR object. While the secret key value will be referenced to migrate the credentials from the AWX database [1], we don't need to keep these helper methods around [1] https://github.com/ManageIQ/manageiq-schema/blob/c7155843816b690fcddae274d45da0e60da487d4/db/migrate/20190617191109_move_awx_credentials_to_authentications.rb#L146-L153 --- app/models/miq_database.rb | 1 - app/models/mixins/ansible_authentications.rb | 79 -------------------- 2 files changed, 80 deletions(-) delete mode 100644 app/models/mixins/ansible_authentications.rb diff --git a/app/models/miq_database.rb b/app/models/miq_database.rb index 9b8918e3af9..fda94b8cfae 100644 --- a/app/models/miq_database.rb +++ b/app/models/miq_database.rb @@ -8,7 +8,6 @@ class MiqDatabase < ApplicationRecord include AuthenticationMixin include PasswordMixin - include AnsibleAuthentications virtual_has_many :vmdb_tables diff --git a/app/models/mixins/ansible_authentications.rb b/app/models/mixins/ansible_authentications.rb deleted file mode 100644 index 6dab4aa76a3..00000000000 --- a/app/models/mixins/ansible_authentications.rb +++ /dev/null @@ -1,79 +0,0 @@ -module AnsibleAuthentications - ANSIBLE_SECRET_KEY_TYPE = "ansible_secret_key".freeze - ANSIBLE_RABBITMQ_TYPE = "ansible_rabbitmq_auth".freeze - ANSIBLE_ADMIN_TYPE = "ansible_admin_password".freeze - ANSIBLE_DATABASE_TYPE = "ansible_database_password".freeze - - AUTHENTICATION_CLASS_BY_TYPE = { - ANSIBLE_SECRET_KEY_TYPE => AuthToken, - ANSIBLE_RABBITMQ_TYPE => AuthUseridPassword, - ANSIBLE_ADMIN_TYPE => AuthUseridPassword, - ANSIBLE_DATABASE_TYPE => AuthUseridPassword - }.freeze - - def self.included(base) - base.class_eval do - include AuthenticationMixin - end - end - - def ansible_secret_key - auth = authentication_type(ANSIBLE_SECRET_KEY_TYPE) - auth.try(:auth_key) - end - - def ansible_secret_key=(key) - auth = authentication_for_type(ANSIBLE_SECRET_KEY_TYPE, "Ansible Secret Key") - update_ansible_authentication(auth, :auth_key => key) - end - - def ansible_rabbitmq_authentication - authentication_type(ANSIBLE_RABBITMQ_TYPE) - end - - def set_ansible_rabbitmq_authentication(userid: "tower", password:) - auth = authentication_for_type(ANSIBLE_RABBITMQ_TYPE, "Ansible Rabbitmq Authentication") - update_ansible_authentication(auth, :userid => userid, :password => password) - auth - end - - def ansible_admin_authentication - authentication_type(ANSIBLE_ADMIN_TYPE) - end - - def set_ansible_admin_authentication(userid: "admin", password:) - auth = authentication_for_type(ANSIBLE_ADMIN_TYPE, "Ansible Admin Authentication") - update_ansible_authentication(auth, :userid => userid, :password => password) - auth - end - - def ansible_database_authentication - authentication_type(ANSIBLE_DATABASE_TYPE) - end - - def set_ansible_database_authentication(userid: "awx", password:) - auth = authentication_for_type(ANSIBLE_DATABASE_TYPE, "Ansible Database Authentication") - update_ansible_authentication(auth, :userid => userid, :password => password) - auth - end - - private - - def authentication_for_type(auth_type, name) - auth = authentication_type(auth_type) - return auth if auth - - auth = AUTHENTICATION_CLASS_BY_TYPE[auth_type].new - auth.name = name - auth.resource = self - auth.authtype = auth_type - auth - end - - def update_ansible_authentication(auth, auth_fields) - auth_fields.each do |field, value| - auth.public_send("#{field}=", value) - end - auth.save! - end -end