Sha256: 09393d94d35ed4e01199f6b6ebdd18fc5135f1307d9613fada87c7ba11215dbd

Contents?: true

Size: 887 Bytes

Versions: 38

Compression:

Stored size: 887 Bytes

Contents

# frozen_string_literal: true

module ForemanAnsible
  # Imports roles from smart proxy
  class RolesImporter
    include ::ForemanAnsible::ProxyAPI

    def initialize(proxy = nil)
      @ansible_proxy = proxy
    end

    def import_role_names
      import_roles remote_roles if @ansible_proxy.present?
    end

    def fetch_role_names
      remote_roles if ansible_proxy
    end

    def import_roles(roles)
      imported = roles.map do |role_name|
        ::AnsibleRole.find_or_initialize_by(:name => role_name)
      end
      detect_changes imported
    end

    def detect_changes(imported)
      changes = {}.with_indifferent_access
      old, changes[:new] = imported.partition { |role| role.id.present? }
      changes[:obsolete] = ::AnsibleRole.where.not(:id => old.map(&:id))
      changes
    end

    private

    def remote_roles
      proxy_api.roles
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
foreman_ansible-6.2.0 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-6.1.1 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-6.0.2 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-6.1.0 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-6.0.1 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-5.1.3 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-6.0.0 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-5.1.2 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-5.1.1 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-5.1.0 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-4.0.3.5 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-4.0.3.4 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-4.0.3.3 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-4.0.3.2 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-5.0.1 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-4.0.5 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-4.0.3.1 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-4.0.4 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-5.0.0 app/services/foreman_ansible/roles_importer.rb
foreman_ansible-4.0.3 app/services/foreman_ansible/roles_importer.rb