Get secret¶
Reads values of a secret by their path : common.encryptionAlgorithm, stripe.apiKey… One key gives its value, several give an array in the same order.
| Method | POST |
| URL | /api/system-api/admin/get-secret-by-name : admin is the user path of your account |
| Body | { keys } ; from code also fromSecretName |
| Answer | data : the value, or an array of values |
| From code | g.sys.system.getSecret |
The call¶
keysis the full path in the secret object, with dots. A path to an object gives the object.- Over HTTP the default secret of the account answers. From code,
fromSecretNamereads another secret of the account by its name ; over HTTP that key is ignored.
From code¶
key, err := g.Sys.System.GetSecret("stripe.apiKey")
if err != nil {
return nil, err
}
both, err := g.Sys.System.GetSecrets([]string{"stripe.apiKey", "common.connectionString.mysql_8"})
if err != nil {
return nil, err
}
key2, cs := both[0], both[1]
staging, err := g.Sys.System.GetSecret("stripe.apiKey", "staging") // from the secret named staging
if err != nil {
return nil, err
}
let key = g.sys.system.get_secret("stripe.apiKey", None)?;
let both = g.sys.system.get_secrets(&["stripe.apiKey", "common.connectionString.mysql_8"], None)?;
let (key2, cs) = (&both[0], &both[1]);
let staging = g.sys.system.get_secret("stripe.apiKey", Some("staging"))?; // from the secret named staging
Object key = g.sys.system.getSecret("stripe.apiKey");
List<Object> both = g.sys.system.getSecrets(List.of("stripe.apiKey", "common.connectionString.mysql_8"));
Object key2 = both.get(0), cs = both.get(1);
Object staging = g.sys.system.getSecret("stripe.apiKey", "staging"); // from the secret named staging
Good to know¶
- Secrets are never in Git and never in the answer of another API : this API is the way to read them, and it is a sensitive one. Grant it to the groups which need it, or read the secret from your code only (
NO_ACCESScustom APIs).
Access, headers and errors¶
- Over HTTP, a system API answers only once its settings open it :
TOKEN_ACCESS(the token of an API user whose group grants this system API) orIS_PUBLIC. Without settings it isNO_ACCESS: only your code (g.sys) and the admin panel reach it. - The settings can also keep the answer in the cache, or ask for the token of a person (
authProviders). Pre and post hooks run around it, as around any API. - It takes the request headers and answers the envelope.
401: no valid token, or the API isNO_ACCESS.403: no group grants it.400: the body is wrong, and the message names the key.
Related : All APIs · System API settings · System APIs from code