Class: Veil::Credential

Inherits:
Object
  • Object
show all
Defined in:
lib/veil/credential.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Credential

Returns a new instance of Credential.



14
15
16
17
18
19
20
21
22
# File 'lib/veil/credential.rb', line 14

def initialize(opts = {})
  validate_opts!(opts)
  @name = opts[:name]
  @version = opts[:version] || 0
  @group = opts[:group] || nil
  @length = opts[:length] || opts[:value].length
  @value = opts[:value][0...@length]
  @frozen = opts[:frozen] || false
end

Instance Attribute Details

#frozenObject (readonly)

Returns the value of attribute frozen.



11
12
13
# File 'lib/veil/credential.rb', line 11

def frozen
  @frozen
end

#groupObject (readonly)

Returns the value of attribute group.



11
12
13
# File 'lib/veil/credential.rb', line 11

def group
  @group
end

#lengthObject (readonly)

Returns the value of attribute length.



11
12
13
# File 'lib/veil/credential.rb', line 11

def length
  @length
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/veil/credential.rb', line 11

def name
  @name
end

#valueObject (readonly) Also known as: credential

Returns the value of attribute value.



11
12
13
# File 'lib/veil/credential.rb', line 11

def value
  @value
end

#versionObject (readonly)

Returns the value of attribute version.



11
12
13
# File 'lib/veil/credential.rb', line 11

def version
  @version
end

Class Method Details

.create(hash = {}) ⇒ Object



6
7
8
# File 'lib/veil/credential.rb', line 6

def create(hash = {})
  new(hash)
end

Instance Method Details

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
# File 'lib/veil/credential.rb', line 28

def eql?(other)
  (@name == other.name) &&
    (@group == other.group) &&
    (@value == other.value) &&
    (@version == other.version)
end

#hashObject



35
36
37
# File 'lib/veil/credential.rb', line 35

def hash
  [@name, @group, @value, @version].hash
end

#rotate(hasher) ⇒ Object



39
40
41
42
# File 'lib/veil/credential.rb', line 39

def rotate(hasher)
  return false unless !frozen && hasher.respond_to?(:encrypt)
  _rotate(hasher)
end

#rotate!(hasher) ⇒ Object

Raises:



44
45
46
47
48
# File 'lib/veil/credential.rb', line 44

def rotate!(hasher)
  raise "You cannot rotate a frozen credential" if frozen
  raise InvalidHasher.new("You must supply a valid hasher to rotate a credential") unless hasher.respond_to?(:encrypt)
  _rotate(hasher)
end

#to_hashObject Also known as: to_h



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/veil/credential.rb', line 50

def to_hash
  {
    type: self.class.name,
    name: name,
    group: group,
    value: value,
    version: version,
    length: length,
    frozen: frozen
  }
end