|
alias
|
String
|
Required. The secret alias to resolve. Must not be empty.Valid formats:
- Direct: `".."`. For example `"discovery_credentials.password."`.
- Group: `"."`. For example`"mid_creds.host1"`.
Default value \(or behavior if not provided\): throws rather than returning nothing.
|
Type
|
Description
|
|---|
|
Object
|
JSON string \(must be parsed by caller\) containing one of two shapes: - For a Password2 field:
```
{"alias": "String", "value": "String"}
```
- For a full credential \(value\_field="\*" alias groups\):
```
{"alias": "String", "fields": {"": "String", ...}}
```
On failure, the scripted wrapper returns null rather than throwing. Every failure mode \(bad alias, access denied, record not found\) collapses to the same null. This is intended behavior to prevent probing for configuration or secrets.
|
This example shows two variants: retrieving a plain secret \(Password2 field\) and retrieving a full credential record.
```
var api = new sn_usg_ns.SecretsAPI();
// Variant A — plain Secret (alias group's value_field is a specific field, e.g. "password")
var rawA = api.getSecret('discovery_credentials.password.' + credentialSysId);
if (rawA) {
var secretResult = JSON.parse(rawA);
gs.info('Fetched credential for alias: ' + secretResult.alias);
// secretResult.value — the decrypted password
}
// Variant B — Credential, full record (alias group's value_field is "*") — per KB0562777
var rawB = new sn_usg_ns.SecretsAPI().getSecret('mid_creds.host1');
if (rawB) {
var credentialResult = JSON.parse(rawB);
var password = credentialResult.fields['password'];
// credentialResult.fields — every decrypted field on the credential record
}
```
Output:
```
Fetched credential for alias: discovery_credentials.password.3f412b8a...
```
## SecretsAPI - getSecrets\(String groupName\)
Retrieves every secret belonging to a named alias group in one call, returning a pre-partitioned result with successes and per-alias failures so the caller does not have to loop and catch individually.
This is the bulk MID-credential-delivery shape. A MID agent can fetch every credential it is scoped to from one mid\_scoped group in a single round trip. The method returns a JSON string that must be parsed by the caller.
|
Name
|
Type
|
Description
|
|---|
|
groupName
|
String
|
Required. The alias group to fetch. Must not be empty. Valid values: any existing Alias Group Name. For example a MID-scoped credential group such as `"mid_credentials"`.
Table: Secret Alias Group \[sys\_secret\_alias\_group\], Field: Alias Group Name
Default value or behavior if not provided: throws rather than defaulting to any group.
|
|
Type
|
Description
|
|---|
|
Object
|
JSON string \(must be parsed by caller\) containing a successful array or two distinct failure levels.
Data type: Object
```
{"successful": [],
"failed": [{"alias": "String", "error": "String"}, ...]}
```
Possible values:
- Success: The `"successful"` array contains entries matching getSecret's Password2 or Credential shapes.
- Failure: The `"failed"` array contains entries for aliases that could not be fetched, identifying the alias and the reason \(for example, ACCESS\_DENIED, RECORD\_NOT\_FOUND\). A failure array contains two distinct levels:
- Group-level failure: If the named group does not exist, the entire call fails and the scripted wrapper returns null, exactly like getSecret\(\)'s failure case. Nothing is returned, not even a failed array.
- Per-alias failure: If the group exists but one or more members can't be fetched, the call still succeeds and returns a normal object. The failing aliases appear in the failed array instead of successful. A caller receives a usable response in this case and must check the failed array explicitly, since a non-null result does not indicate that every member succeeded.
|
This example shows batch retrieval of credentials from a named alias group. The result is checked for successful entries.
```
var json = new sn_usg_ns.SecretsAPI().getSecrets('mid_credentials');
var result = JSON.parse(json);
result.successful.forEach(function(secret) {
gs.log('Alias: ' + secret.alias);
});
```
Output:
```
Alias: mid_credentials.3f412b8a...
```
### Troubleshooting
|
Error
|
Likely cause / fix
|
|---|
|
ACCESS\_DENIED with no context
|
Enable `glide.usg.audit.trace=true` \(reloads live, no restart\) to see the denying gate in the audit log. Never exposed to the caller directly. Common causes:
- Missing Row ACL,
- Missing Consumer Grant \(external/MID callers\),
- MAP Policy denial,
- The alias group is in a LOCKDOWN state.
| |
RECORD\_NOT\_FOUND
|
The alias\_field value doesn't exist in the target table, or for `filter_mode=mid_scoped`, the record doesn't have `applies_to="all"` or the calling MID Server's ID in `mid_list`.
| |
INVALID\_FORMAT
|
Alias string doesn't match either addressing mode: - Tier 3 `"table.field.sys_id"`
- Tier 2 `"group_name.alias"`
|
|