Class: KBSecret::Generator
- Inherits:
-
Object
- Object
- KBSecret::Generator
- Defined in:
- lib/kbsecret/generator.rb
Overview
Generates secret values (passwords, environment keys, etc) for storage by KBSecret.
Constant Summary collapse
- GENERATOR_TYPES =
All generator formats known by KBSecret::Generator.
i[hex base64].freeze
Instance Attribute Summary collapse
-
#format ⇒ Symbol
readonly
The format of the generator.
-
#length ⇒ Integer
readonly
The length, in bytes of secrets generated by the generator.
Instance Method Summary collapse
-
#initialize(profile = :default) ⇒ Generator
constructor
A new instance of Generator.
- #secret ⇒ String
Constructor Details
#initialize(profile = :default) ⇒ Generator
Returns a new instance of Generator.
20 21 22 23 24 25 26 |
# File 'lib/kbsecret/generator.rb', line 20 def initialize(profile = :default) @format = Config.generator(profile)[:format].to_sym @length = Config.generator(profile)[:length].to_i raise Exceptions::GeneratorLengthError, @length unless @length.positive? raise Exceptions::GeneratorFormatError, @format unless GENERATOR_TYPES.include?(@format) end |
Instance Attribute Details
#format ⇒ Symbol (readonly)
Returns the format of the generator.
12 13 14 |
# File 'lib/kbsecret/generator.rb', line 12 def format @format end |
#length ⇒ Integer (readonly)
Returns the length, in bytes of secrets generated by the generator.
15 16 17 |
# File 'lib/kbsecret/generator.rb', line 15 def length @length end |
Instance Method Details
#secret ⇒ String
Returns a new secret based on the #format and #length of the KBSecret::Generator.
32 33 34 |
# File 'lib/kbsecret/generator.rb', line 32 def secret SecureRandom.send(@format, @length) end |