Class: Onetime::Resources::Secrets
- Inherits:
-
Object
- Object
- Onetime::Resources::Secrets
- Defined in:
- lib/onetime/resources/secrets.rb
Overview
Secret operations: conceal, generate, reveal, show, status.
The request/response contracts differ between API versions:
- v1 uses flat form-encoded params and legacy endpoint names
(/share, /generate, POST /secret/:key for reveal).
- v2 nests create params under a `secret` object, uses JSON bodies,
and exposes richer REST endpoints (/secret/conceal, /secret/:id, ...).
The version-specific branches are kept side by side in each method so the differences are easy to audit.
Instance Method Summary collapse
-
#conceal(secret:, ttl: nil, passphrase: nil, recipient: nil, share_domain: nil, guest: false) ⇒ Object
(also: #share)
Conceal (share) a secret value you already have.
-
#generate(ttl: nil, passphrase: nil, recipient: nil, share_domain: nil, guest: false) ⇒ Object
Generate a random secret value server-side.
-
#initialize(client) ⇒ Secrets
constructor
A new instance of Secrets.
-
#reveal(key, passphrase: nil, continue: true, guest: false) ⇒ Object
Reveal (consume) a secret by its key.
-
#show(key, guest: false) ⇒ Object
Show a secret's metadata without revealing its value.
-
#status(key) ⇒ Object
Check a single secret's status.
-
#status_list(keys) ⇒ Object
Check the status of multiple secrets in one call.
Constructor Details
#initialize(client) ⇒ Secrets
Returns a new instance of Secrets.
16 17 18 |
# File 'lib/onetime/resources/secrets.rb', line 16 def initialize(client) @client = client end |
Instance Method Details
#conceal(secret:, ttl: nil, passphrase: nil, recipient: nil, share_domain: nil, guest: false) ⇒ Object Also known as:
Conceal (share) a secret value you already have.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/onetime/resources/secrets.rb', line 28 def conceal(secret:, ttl: nil, passphrase: nil, recipient: nil, share_domain: nil, guest: false) case version when :v1 form = compact(secret: secret, ttl: ttl, passphrase: passphrase, recipient: recipient, share_domain: share_domain) @client.request(:post, "/share", form: form) when :v2 path = guest ? "/guest/secret/conceal" : "/secret/conceal" @client.request(:post, path, body: { secret: secret_payload( secret: secret, ttl: ttl, passphrase: passphrase, recipient: recipient, share_domain: share_domain ) }) end end |
#generate(ttl: nil, passphrase: nil, recipient: nil, share_domain: nil, guest: false) ⇒ Object
Generate a random secret value server-side.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/onetime/resources/secrets.rb', line 45 def generate(ttl: nil, passphrase: nil, recipient: nil, share_domain: nil, guest: false) case version when :v1 form = compact(ttl: ttl, passphrase: passphrase, recipient: recipient, share_domain: share_domain) @client.request(:post, "/generate", form: form) when :v2 path = guest ? "/guest/secret/generate" : "/secret/generate" @client.request(:post, path, body: { secret: secret_payload( ttl: ttl, passphrase: passphrase, recipient: recipient, share_domain: share_domain ) }) end end |
#reveal(key, passphrase: nil, continue: true, guest: false) ⇒ Object
Reveal (consume) a secret by its key. This is a one-time action.
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/onetime/resources/secrets.rb', line 65 def reveal(key, passphrase: nil, continue: true, guest: false) identifier = extract_secret_key(key) case version when :v1 form = compact(passphrase: passphrase, continue: continue) @client.request(:post, "/secret/#{identifier}", form: form) when :v2 path = guest ? "/guest/secret/#{identifier}/reveal" : "/secret/#{identifier}/reveal" @client.request(:post, path, body: compact(passphrase: passphrase, continue: continue)) end end |
#show(key, guest: false) ⇒ Object
Show a secret's metadata without revealing its value. (v2 only)
78 79 80 81 82 83 |
# File 'lib/onetime/resources/secrets.rb', line 78 def show(key, guest: false) require_version!(:v2, "secrets.show") identifier = extract_secret_key(key) path = guest ? "/guest/secret/#{identifier}" : "/secret/#{identifier}" @client.request(:get, path) end |
#status(key) ⇒ Object
Check a single secret's status. (v2 only)
86 87 88 89 |
# File 'lib/onetime/resources/secrets.rb', line 86 def status(key) require_version!(:v2, "secrets.status") @client.request(:get, "/secret/#{extract_secret_key(key)}/status") end |
#status_list(keys) ⇒ Object
Check the status of multiple secrets in one call. (v2 only)
94 95 96 97 98 |
# File 'lib/onetime/resources/secrets.rb', line 94 def status_list(keys) require_version!(:v2, "secrets.status_list") identifiers = keys.is_a?(Array) ? keys.join(",") : keys.to_s @client.request(:post, "/secret/status", body: { identifiers: identifiers }) end |