Class: Pgai::Encryption::Key

Inherits:
Object
  • Object
show all
Defined in:
lib/pgai/encryption/key.rb

Constant Summary collapse

ENV_VAR_NAME =
"PGAI_MASTER_KEY"

Instance Method Summary collapse

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

#generateObject



14
15
16
# File 'lib/pgai/encryption/key.rb', line 14

def generate
  Lockbox.generate_key
end

#readObject



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