Sha256: 369e3b45ebcf7417dc9d08067d31aa157861058623b93b0b9f6df2ecd49c22dc

Contents?: true

Size: 1.17 KB

Versions: 8

Compression:

Stored size: 1.17 KB

Contents

require 'awesome_spawn'

module ManageIQ
module ApplianceConsole
  # Kerberos principal
  class Principal
    attr_accessor :ca_name
    attr_accessor :hostname
    attr_accessor :realm
    attr_accessor :service
    # kerberos principal name
    attr_accessor :name
    attr_accessor :service_principal

    def initialize(options = {})
      options.each { |n, v| public_send("#{n}=", v) }
      @ca_name ||= "ipa"
      @realm = @realm.upcase if @realm
      @service_principal ||= "#{service}/#{hostname}"
      @name ||= "#{service_principal}@#{realm}"
    end

    def register
      request if ipa? && !exist?
    end

    def subject_name
      "CN=#{hostname},OU=#{service},O=#{realm}"
    end

    def ipa?
      @ca_name == "ipa"
    end

    private

    def exist?
      AwesomeSpawn.run("/usr/bin/ipa", :params => ["-e", "skip_version_check=1", "service-find", "--principal", service_principal]).success?
    end

    def request
      # using --force because these services tend not to be in dns
      # this is like VERIFY_NONE
      AwesomeSpawn.run!("/usr/bin/ipa", :params => ["-e", "skip_version_check=1", "service-add", "--force", service_principal])
    end
  end
end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
manageiq-appliance_console-10.0.0 lib/manageiq/appliance_console/principal.rb
manageiq-appliance_console-9.1.1 lib/manageiq/appliance_console/principal.rb
manageiq-appliance_console-9.1.0 lib/manageiq/appliance_console/principal.rb
manageiq-appliance_console-9.0.2 lib/manageiq/appliance_console/principal.rb
manageiq-appliance_console-9.0.1 lib/manageiq/appliance_console/principal.rb
manageiq-appliance_console-9.0.0 lib/manageiq/appliance_console/principal.rb
manageiq-appliance_console-8.1.0 lib/manageiq/appliance_console/principal.rb
manageiq-appliance_console-7.2.2 lib/manageiq/appliance_console/principal.rb