Class: SmPs::Parameter

Inherits:
Object
  • Object
show all
Defined in:
lib/smps/parameter.rb

Overview

SmPs Parameter management

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Parameter

Returns a new instance of Parameter.



8
9
10
11
12
13
14
15
16
17
# File 'lib/smps/parameter.rb', line 8

def initialize(options)
  @ssm = options[:ssm]
  @name = options[:name]
  @value = options[:value]
  @type = options[:type]
  @key_id = options[:key_id]
  @decrypt = options[:decrypt] || true
  fetch = options[:fetch] || true
  parameter if fetch
end

Instance Attribute Details

#decryptObject

Returns the value of attribute decrypt.



6
7
8
# File 'lib/smps/parameter.rb', line 6

def decrypt
  @decrypt
end

#descriptionObject

Returns the value of attribute description.



6
7
8
# File 'lib/smps/parameter.rb', line 6

def description
  @description
end

#key_idObject

Returns the value of attribute key_id.



6
7
8
# File 'lib/smps/parameter.rb', line 6

def key_id
  @key_id
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/smps/parameter.rb', line 6

def name
  @name
end

#typeObject

Returns the value of attribute type.



6
7
8
# File 'lib/smps/parameter.rb', line 6

def type
  @type
end

Instance Method Details

#exists?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/smps/parameter.rb', line 48

def exists?
  @exists
end

#historyObject

Not implemented yet.



65
66
67
# File 'lib/smps/parameter.rb', line 65

def history
  # get_parameter_history
end

#parameterObject

Gets a parameter from Aws SSM.



20
21
22
23
24
25
26
27
28
29
# File 'lib/smps/parameter.rb', line 20

def parameter
  resp = @ssm.get_parameter(
    name: @name, with_decryption: @decrypt
  )
  @type = resp.parameter.type
  @value = resp.parameter.value
  @exists = true
rescue Aws::SSM::Errors::ParameterNotFound
  @exists = false
end

#tagObject

Not implemented yet.



70
71
72
73
# File 'lib/smps/parameter.rb', line 70

def tag
  # add_tags_to_resource
  # remove_tags_from_resource
end

#to_sObject

Prints the current value.



32
33
34
# File 'lib/smps/parameter.rb', line 32

def to_s
  @value
end

#valueObject

Returns the value (String) or array if the ‘type` is StringList



37
38
39
40
# File 'lib/smps/parameter.rb', line 37

def value
  return @value.split(',') if @type == 'StringList'
  @value
end

#value=(value) ⇒ Object

Set the value and mark the parameter as changed.



43
44
45
46
# File 'lib/smps/parameter.rb', line 43

def value=(value)
  @changed = true if value != @value
  @value = value
end

#write!(value = nil) ⇒ Object

Updates the parameter in the parameter store (remote).



53
54
55
56
57
58
59
60
61
62
# File 'lib/smps/parameter.rb', line 53

def write!(value = nil)
  @changed = true if value != @value
  @value = value if value
  @ssm.put_parameter(
    name: @name, value: @value, type: @type,
    description: @description, key_id: @key_id, overwrite: @exists,
    # allowed_pattern: "AllowedPattern",
  )
  @value
end