coi-gov-pl/puppet-jboss

View on GitHub
lib/puppet_x/coi/jboss/internal/logic_creator.rb

Summary

Maintainability
A
0 mins
Test Coverage
# Class that will decide what cammands should be send to cli to set up security domain
class PuppetX::Coi::Jboss::Internal::LogicCreator
  # @param [PuppetX::Coi::Jboss::Internal::JbossSecurityDomainState] state current state of
  # securitydomain configuration
  # @param [PuppetX::Coi::Jboss::Provider::SecurityDomain::Provider] provider that indicates if
  # we need to use diffrent paths to setup securitydomain
  def initialize(auditor, resource, provider, compilator)
    @auditor = auditor
    @resource = resource
    @provider = provider
    @compilator = compilator
  end

  # Method that will return list of commands based on current state
  # @param {PuppetX::Coi::Jboss::Provider::SecurityDomain::PreWildFlyProvider|
  # PuppetX::Coi::Jboss::Provider::SecurityDomain::PostWildFlyProvider}
  # @return [Hash] commands Hash with commands that will be executed, key is message that will
  # be displayed and value is command
  def decide
    state = @auditor.state
    commands = []
    unless state.cache_default?
      command = @compilator.compile(
        @resource[:runasdomain],
        @resource[:profile],
        "/subsystem=security/security-domain=#{@resource[:name]}:add(cache-type=default)"
      )

      commands.push(['Security Domain Cache Type', command])
    end
    provided_commands = @provider.get_commands(state, @resource)
    provided_commands = [] if provided_commands.nil?
    commands + provided_commands
  end

end