ParseFormattedSecret parses a formatted secret like "coder_ _<secret"
(formatted string)
| 43 | |
| 44 | // ParseFormattedSecret parses a formatted secret like "coder_<prefix>_<secret" |
| 45 | func ParseFormattedSecret(formatted string) (AppSecret, error) { |
| 46 | parts := strings.Split(formatted, "_") |
| 47 | if len(parts) != 3 { |
| 48 | return AppSecret{}, xerrors.Errorf("incorrect number of parts: %d", len(parts)) |
| 49 | } |
| 50 | if parts[0] != SecretIdentifier { |
| 51 | return AppSecret{}, xerrors.Errorf("incorrect scheme: %s", parts[0]) |
| 52 | } |
| 53 | return AppSecret{ |
| 54 | Formatted: formatted, |
| 55 | Prefix: parts[1], |
| 56 | Secret: parts[2], |
| 57 | }, nil |
| 58 | } |
| 59 | |
| 60 | // GenerateSecret generates a secret to be used as a client secret, refresh |
| 61 | // token, or authorization code. |
no test coverage detected