The token in a stored record; null for anything this version cannot read.
(secret)
| 42 | |
| 43 | /** The token in a stored record; null for anything this version cannot read. */ |
| 44 | function tokenFromSecret(secret) { |
| 45 | try { |
| 46 | const record = JSON.parse(secret); |
| 47 | if (record?.v === SECRET_VERSION && typeof record.token === "string") { |
| 48 | return record.token; |
| 49 | } |
| 50 | } catch { |
| 51 | // Not a record this code wrote. |
| 52 | } |
| 53 | return null; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Shape check matching the one `doctl` performs before storing a token: 64 |