Class: Veil::Credential
- Inherits:
-
Object
- Object
- Veil::Credential
- Defined in:
- lib/veil/credential.rb
Instance Attribute Summary collapse
-
#frozen ⇒ Object
readonly
Returns the value of attribute frozen.
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#value ⇒ Object
(also: #credential)
readonly
Returns the value of attribute value.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(opts = {}) ⇒ Credential
constructor
A new instance of Credential.
- #rotate(hasher) ⇒ Object
- #rotate!(hasher) ⇒ Object
- #to_hash ⇒ Object (also: #to_h)
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
#frozen ⇒ Object (readonly)
Returns the value of attribute frozen.
11 12 13 |
# File 'lib/veil/credential.rb', line 11 def frozen @frozen end |
#group ⇒ Object (readonly)
Returns the value of attribute group.
11 12 13 |
# File 'lib/veil/credential.rb', line 11 def group @group end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
11 12 13 |
# File 'lib/veil/credential.rb', line 11 def length @length end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
11 12 13 |
# File 'lib/veil/credential.rb', line 11 def name @name end |
#value ⇒ Object (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 |
#version ⇒ Object (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
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 |
#hash ⇒ Object
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
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_hash ⇒ Object 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 |