Class: Pgai::Encryption::Key
- Inherits:
-
Object
- Object
- Pgai::Encryption::Key
- Defined in:
- lib/pgai/encryption/key.rb
Constant Summary collapse
- ENV_VAR_NAME =
"PGAI_MASTER_KEY"
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(op_client: OnePasswordClient.new, reference_store: ReferenceStore.new, prompter: Prompter.new) ⇒ Key
constructor
A new instance of Key.
- #read ⇒ Object
- #save(key) ⇒ Object
Constructor Details
#initialize(op_client: OnePasswordClient.new, reference_store: ReferenceStore.new, prompter: Prompter.new) ⇒ Key
Returns a new instance of Key.
8 9 10 11 12 |
# File 'lib/pgai/encryption/key.rb', line 8 def initialize(op_client: OnePasswordClient.new, reference_store: ReferenceStore.new, prompter: Prompter.new) @op_client = op_client @reference_store = reference_store @prompter = prompter end |
Instance Method Details
#generate ⇒ Object
14 15 16 |
# File 'lib/pgai/encryption/key.rb', line 14 def generate Lockbox.generate_key end |
#read ⇒ Object
26 27 28 |
# File 'lib/pgai/encryption/key.rb', line 26 def read ENV.fetch(ENV_VAR_NAME) { read_from_one_password } end |
#save(key) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/pgai/encryption/key.rb', line 18 def save(key) config = @prompter.prompt_for_config reference = @op_client.create_item(key: key, **config) @reference_store.write(reference) reference end |