Class: Aspera::Secret::Store::Keeper
- Defined in:
- lib/aspera/secret/store/keeper.rb
Overview
Manage secrets in Keeper Secrets Manager (Keeper Vault), using the Ruby SDK https://docs.keeper.io/keeperpam/secrets-manager/overview
A secret is a record of the Keeper vault shared with the application: its label is its title (or its UID).
Reference: secret://<store>/<title or uid>#<field>, field password by default.
Fields are those of the record: standard fields by type (login, password, url...), custom fields by label, and notes.
username is an alias of login.
Constant Summary collapse
- PARAMETERS =
config: configuration of the client device (base64 or JSON), the value, or@file:<path>(Bootstrap)folder_uid: shared folder wheresetcreates records (not needed to read) %i[config folder_uid].freeze
Constants inherited from Base
Base::CONTENT_KEYS, Base::REFERENCE_OPTIONS
Class Method Summary collapse
Instance Method Summary collapse
- #all ⇒ Object
- #delete(label:, id: nil) ⇒ Object
- #get(label:, id: nil, exception: true) ⇒ Object
- #ids ⇒ Object
- #info ⇒ Object
-
#initialize(config:, folder_uid: nil) ⇒ Keeper
constructor
A new instance of Keeper.
- #read_fields(ref) ⇒ Object
-
#read_reference(ref) ⇒ Object
The record is found by title or UID, the field is
passwordby default. -
#set(options) ⇒ Object
Create a record of type
loginin the shared folderfolder_uid.
Methods inherited from Base
#assert_new_label, check_parameters, #check_reference, error_reason, #list_folder, #validate_set, #write_reference
Constructor Details
#initialize(config:, folder_uid: nil) ⇒ Keeper
Returns a new instance of Keeper.
39 40 41 42 43 44 45 46 |
# File 'lib/aspera/secret/store/keeper.rb', line 39 def initialize(config:, folder_uid: nil) super() Aspera.assert_type(folder_uid, String, type: ParameterError) { 'keeper folder_uid' } unless folder_uid.nil? config = Bootstrap.new('config', config) unless config.is_a?(Bootstrap) @folder_uid = folder_uid # The SDK logs on STDOUT by default: do not mix with results @client = ::KeeperSecretsManager.from_config(config.value, logger: ::Logger.new($stderr)) end |
Class Method Details
Instance Method Details
#all ⇒ Object
55 56 57 |
# File 'lib/aspera/secret/store/keeper.rb', line 55 def all @client.get_secrets.map { |record| secret(record) } end |
#delete(label:, id: nil) ⇒ Object
84 85 86 87 |
# File 'lib/aspera/secret/store/keeper.rb', line 84 def delete(label:, id: nil) @client.delete_secret(find(id || label).uid) nil end |
#get(label:, id: nil, exception: true) ⇒ Object
78 79 80 81 82 |
# File 'lib/aspera/secret/store/keeper.rb', line 78 def get(label:, id: nil, exception: true) record = find(id || label, exception: exception) return if record.nil? secret(record) end |
#ids ⇒ Object
59 60 61 |
# File 'lib/aspera/secret/store/keeper.rb', line 59 def ids @client.get_secrets.map { |record| {id: record.uid, label: record.title} } end |
#info ⇒ Object
48 49 50 51 52 53 |
# File 'lib/aspera/secret/store/keeper.rb', line 48 def info { hostname: @client.hostname, folder_uid: @folder_uid }.compact end |
#read_fields(ref) ⇒ Object
95 96 97 98 |
# File 'lib/aspera/secret/store/keeper.rb', line 95 def read_fields(ref) record = find(ref.path) {fields: field_names(record_values(record).except('title')), version: record.revision, updated_time: nil} end |
#read_reference(ref) ⇒ Object
The record is found by title or UID, the field is password by default
90 91 92 93 |
# File 'lib/aspera/secret/store/keeper.rb', line 90 def read_reference(ref) record = find(ref.path) {value: field_value(record_values(record), ref, default: DEFAULT_FIELD), version: record.revision, updated_time: nil} end |
#set(options) ⇒ Object
Create a record of type login in the shared folder folder_uid
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/aspera/secret/store/keeper.rb', line 65 def set() validate_set() Aspera.assert(!@folder_uid.nil?, type: ParameterError) { 'keeper: parameter folder_uid is required to create a secret' } assert_new_label([:label]) fields = {login: :username, password: :password, url: :url}.filter_map do |type, key| {type: type.to_s, value: [[key]]} if [key] end record = {type: 'login', title: [:label], fields: fields} record[:notes] = [:description] if [:description] @client.create_secret(record, ::KeeperSecretsManager::Dto::CreateOptions.new(folder_uid: @folder_uid)) nil end |