Module: KeeperSecretsManager::FieldTypes::Helpers

Defined in:
lib/keeper_secrets_manager/field_types.rb

Overview

Helper methods for creating common fields

Class Method Summary collapse

Class Method Details

.address(street1:, city:, state:, zip:, country: 'US', street2: nil, label: nil) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/keeper_secrets_manager/field_types.rb', line 65

def self.address(street1:, city:, state:, zip:, country: 'US', street2: nil, label: nil)
  value = {
    'street1' => street1,
    'city' => city,
    'state' => state,
    'zip' => zip,
    'country' => country
  }
  value['street2'] = street2 if street2
  Field.new(type: 'address', value: value, label: label)
end

.bank_account(account_type:, routing_number:, account_number:, label: nil) ⇒ Object



87
88
89
90
91
92
93
94
# File 'lib/keeper_secrets_manager/field_types.rb', line 87

def self.(account_type:, routing_number:, account_number:, label: nil)
  value = {
    'accountType' => ,
    'routingNumber' => routing_number,
    'accountNumber' => 
  }
  Field.new(type: 'bankAccount', value: value, label: label)
end

.birth_date(date, label: nil) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/keeper_secrets_manager/field_types.rb', line 96

def self.birth_date(date, label: nil)
  # Date should be in unix timestamp (milliseconds)
  timestamp = case date
              when Date, Time, DateTime
                (date.to_time.to_f * 1000).to_i
              when Integer
                date
              when String
                (Date.parse(date).to_time.to_f * 1000).to_i
              else
                raise ArgumentError, 'Invalid date format'
              end
  Field.new(type: 'birthDate', value: timestamp, label: label)
end

.custom(type:, value:, label: nil, required: false) ⇒ Object

Generic field for any type



147
148
149
# File 'lib/keeper_secrets_manager/field_types.rb', line 147

def self.custom(type:, value:, label: nil, required: false)
  Field.new(type: type, value: value, label: label, required: required)
end

.database_type(type, label: nil) ⇒ Object



127
128
129
# File 'lib/keeper_secrets_manager/field_types.rb', line 127

def self.database_type(type, label: nil)
  Field.new(type: 'databaseType', value: type, label: label)
end

.email(email, label: nil) ⇒ Object



61
62
63
# File 'lib/keeper_secrets_manager/field_types.rb', line 61

def self.email(email, label: nil)
  Field.new(type: 'email', value: email, label: label)
end

.file_ref(value, label: nil) ⇒ Object



40
41
42
# File 'lib/keeper_secrets_manager/field_types.rb', line 40

def self.file_ref(value, label: nil)
  Field.new(type: 'fileRef', value: value, label: label)
end

.host(hostname:, port: nil, label: nil) ⇒ Object



121
122
123
124
125
# File 'lib/keeper_secrets_manager/field_types.rb', line 121

def self.host(hostname:, port: nil, label: nil)
  value = { 'hostName' => hostname }
  value['port'] = port.to_s if port
  Field.new(type: 'host', value: value, label: label)
end

.login(value, label: nil) ⇒ Object



28
29
30
# File 'lib/keeper_secrets_manager/field_types.rb', line 28

def self.(value, label: nil)
  Field.new(type: 'login', value: value, label: label)
end

.name(first:, last:, middle: nil, label: nil) ⇒ Object



48
49
50
51
52
# File 'lib/keeper_secrets_manager/field_types.rb', line 48

def self.name(first:, last:, middle: nil, label: nil)
  value = { 'first' => first, 'last' => last }
  value['middle'] = middle if middle
  Field.new(type: 'name', value: value, label: label)
end

.one_time_code(value, label: nil) ⇒ Object



44
45
46
# File 'lib/keeper_secrets_manager/field_types.rb', line 44

def self.one_time_code(value, label: nil)
  Field.new(type: 'oneTimeCode', value: value, label: label)
end

.passkey(private_key:, credential_id:, rp_id:, user_id:, username:, label: nil) ⇒ Object



135
136
137
138
139
140
141
142
143
144
# File 'lib/keeper_secrets_manager/field_types.rb', line 135

def self.passkey(private_key:, credential_id:, rp_id:, user_id:, username:, label: nil)
  value = {
    'privateKey' => private_key,
    'credentialId' => credential_id,
    'relyingParty' => rp_id,
    'userId' => user_id,
    'username' => username
  }
  Field.new(type: 'passkey', value: value, label: label)
end

.password(value, label: nil) ⇒ Object



32
33
34
# File 'lib/keeper_secrets_manager/field_types.rb', line 32

def self.password(value, label: nil)
  Field.new(type: 'password', value: value, label: label)
end

.payment_card(number:, expiration_date:, security_code:, cardholder_name: nil, label: nil) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'lib/keeper_secrets_manager/field_types.rb', line 77

def self.payment_card(number:, expiration_date:, security_code:, cardholder_name: nil, label: nil)
  value = {
    'cardNumber' => number,
    'cardExpirationDate' => expiration_date,
    'cardSecurityCode' => security_code
  }
  value['cardholderName'] = cardholder_name if cardholder_name
  Field.new(type: 'paymentCard', value: value, label: label)
end

.phone(number:, region: 'US', type: nil, ext: nil, label: nil) ⇒ Object



54
55
56
57
58
59
# File 'lib/keeper_secrets_manager/field_types.rb', line 54

def self.phone(number:, region: 'US', type: nil, ext: nil, label: nil)
  value = { 'region' => region, 'number' => number }
  value['type'] = type if type
  value['ext'] = ext if ext
  Field.new(type: 'phone', value: value, label: label)
end

.script(script, label: nil) ⇒ Object



131
132
133
# File 'lib/keeper_secrets_manager/field_types.rb', line 131

def self.script(script, label: nil)
  Field.new(type: 'script', value: script, label: label)
end

.secure_note(note, label: nil) ⇒ Object



111
112
113
# File 'lib/keeper_secrets_manager/field_types.rb', line 111

def self.secure_note(note, label: nil)
  Field.new(type: 'secureNote', value: note, label: label)
end

.ssh_key(private_key:, public_key: nil, label: nil) ⇒ Object



115
116
117
118
119
# File 'lib/keeper_secrets_manager/field_types.rb', line 115

def self.ssh_key(private_key:, public_key: nil, label: nil)
  value = { 'privateKey' => private_key }
  value['publicKey'] = public_key if public_key
  Field.new(type: 'sshKey', value: value, label: label)
end

.url(value, label: nil) ⇒ Object



36
37
38
# File 'lib/keeper_secrets_manager/field_types.rb', line 36

def self.url(value, label: nil)
  Field.new(type: 'url', value: value, label: label)
end