Class: ForemanVault::VaultPolicy

Inherits:
Object
  • Object
show all
Defined in:
app/services/foreman_vault/vault_policy.rb

Constant Summary collapse

MAGIC_COMMENT_NAME_PREFIX =
'# NAME: '

Instance Method Summary collapse

Constructor Details

#initialize(host) ⇒ VaultPolicy

Returns a new instance of VaultPolicy.



7
8
9
# File 'app/services/foreman_vault/vault_policy.rb', line 7

def initialize(host)
  @host = host
end

Instance Method Details

#deleteObject



31
32
33
34
35
# File 'app/services/foreman_vault/vault_policy.rb', line 31

def delete
  return false unless valid?

  delete_policy(name)
end

#nameObject



15
16
17
# File 'app/services/foreman_vault/vault_policy.rb', line 15

def name
  magic_comment_name&.chomp&.remove(MAGIC_COMMENT_NAME_PREFIX)&.parameterize
end

#new?Boolean

Returns:

  • (Boolean)


19
20
21
22
23
# File 'app/services/foreman_vault/vault_policy.rb', line 19

def new?
  return unless name

  policies.index(name).nil?
end

#saveObject



25
26
27
28
29
# File 'app/services/foreman_vault/vault_policy.rb', line 25

def save
  return false unless valid?

  put_policy(name, rules)
end

#valid?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'app/services/foreman_vault/vault_policy.rb', line 11

def valid?
  name.present? && rules.present?
end