class Veil::Credential

Attributes

credential[R]
frozen[R]
group[R]
length[R]
name[R]
value[R]
version[R]

Public Class Methods

create(hash = {}) click to toggle source
# File lib/veil/credential.rb, line 6
def create(hash = {})
  new(hash)
end
new(opts = {}) click to toggle source
# 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

Public Instance Methods

eql?(other) click to toggle source
# File lib/veil/credential.rb, line 28
def eql?(other)
  (@name == other.name) &&
    (@group == other.group) &&
    (@value == other.value) &&
    (@version == other.version)
end
hash() click to toggle source
# File lib/veil/credential.rb, line 35
def hash
  [@name, @group, @value, @version].hash
end
rotate(hasher) click to toggle source
# File lib/veil/credential.rb, line 39
def rotate(hasher)
  return false unless !frozen && hasher.respond_to?(:encrypt)
  _rotate(hasher)
end
rotate!(hasher) click to toggle source
# 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_h()
Alias for: to_hash
to_hash() click to toggle source
# 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
Also aliased as: to_h

Private Instance Methods

_rotate(hasher) click to toggle source
# File lib/veil/credential.rb, line 65
def _rotate(hasher)
  @version += 1
  @value = hasher.encrypt(group, name, version)[0...@length]
end
validate_opts!(opts) click to toggle source
# File lib/veil/credential.rb, line 70
def validate_opts!(opts)
  raise ArgumentError, "You must provide a credential name" unless opts[:name]
  raise ArgumentError, "You must provide a credential value" unless opts[:value]
end