StandardCredentialsProvider - Scoped, Global
The StandardCredentialsProvider API provides methods to retrieve credential information.
You can use this API in scoped applications or within the global scope. In scoped scripts, use the sn_cc namespace identifier.
This API provides methods to retrieve credential information by sys_id and by specified credential attributes.
//Get a single credential
var provider = new sn_cc.StandardCredentialsProvider();
var credential = provider.getCredentialByID("f43c6d40a0a0b5700c77f9bf387afe3");
var userName = credential.getAttribute("user_name");
var password = credential.getAttribute("password");
//using getAttribute for new keys in extended tables, for example
//cloud management credential has the "user_public_key" attribute
var userPublicKey = credential.getAttribute("user_public_key");
//Get a list of SSH credentials
var provider = new sn_cc.StandardCredentialsProvider();
var credentials = provider.getCredentials(["ssh"]);
for (var i = 0; i < credentials.length; i++) {
var credential = credentials[i];
gs.info(credential.getAttribute("name"));
}
Parent Topic:Server API reference
StandardCredentialsProvider - StandardCredentialsProvider()
Instantiates a credentials provider object.
| Name | Type | Description |
|---|---|---|
| None |
var provider = new sn_cc.StandardCredentialsProvider();
var credentials = provider.getCredentialByID("ef43c6d40a0a0b5700c77f9bf387afe3");
StandardCredentialsProvider - getCredentials(String types, String tags)
Returns an array of all credentials that match the specified types and tags.
| Name | Type | Description | |||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| tags | String | Optional. Comma-separated list of tag names. For example, "ssh, jdbc".Examples of valid calls: - `var credentials = provider.getCredentials(null, null);` - `var credentials = provider.getCredentials(["ssh"], "");` - `var credentials = provider.getCredentials(new ArrayList| types | Array | Optional. Credential type names. For example, ["ssh", "windows"]Note: If types is null or empty, any match returns a credential. If types is specified, the credentials whose type matches one of the types is returned. |
This code example shows how to get the provider credentials for "ssh" credential types. This code example shows how to get the provider credentials for "ssh" and "windows" credential types that have tags of "admin". StandardCredentialsProvider - getCredentialByAliasID(String sys_id)Returns the credential record object through its credential alias (sys_alias). This method is specifically for use with credential types. For information, see Credential aliases for Discovery.
The following example retrieves a credential using the alias ID and displays the user name. Output for a credential record with a user name: StandardCredentialsProvider - getCredentialByID(String sys_id)Returns the credential record object identified by the specified sys_id.
The following example retrieves a credential and displays the user name. Output for a credential record with a user name: |