StandardCredentialsProvider : dans le champ d’application, global
L’API StandardCredentialsProvider fournit des méthodes pour récupérer les informations d’identification.
Vous pouvez utiliser cette API dans des applications incluses dans le périmètre ou dans le périmètre global. Dans les scripts inclus dans le périmètre, utilisez l’identificateur d’espace de noms sn_cc.
Cette API fournit des méthodes pour récupérer les informations d’identification par sys_id et par attributs d’informations d’identification spécifiés.
//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"));
}StandardCredentialsProvider : StandardCredentialsProvider()
Instancie un objet de fournisseur d’informations d’identification.
| Nom | Type | Description |
|---|---|---|
| Néant |
var provider = new sn_cc.StandardCredentialsProvider();
var credentials = provider.getCredentialByID("ef43c6d40a0a0b5700c77f9bf387afe3");
StandardCredentialsProvider : getCredentials(types de chaîne, balises de chaîne)
Renvoie un tableau de toutes les informations d’identification qui correspondent aux types et balises spécifiés.
| Nom | Type | Description |
|---|---|---|
| balises | Chaîne | Facultatif. Liste de noms de balises séparés par des virgules. Par exemple, « ssh, jdbc ». Exemples d’appels valides :
|
| types | Tableau | Facultatif. Noms de types d’informations d’identification. Par exemple, ["ssh », « windows"] Remarque : Si types la valeur est null ou vide, toute correspondance renvoie des informations d’identification. Si types cette option est spécifiée, les informations d’identification dont le type correspond à l’un des types sont renvoyées. |
| Type | Description |
|---|---|
| Informations d’identification standard | Objet d’enregistrement d’informations d’identification. |
Cet exemple de code montre comment obtenir les informations d’identification du fournisseur pour les types d’informations d’identification « ssh ».
var provider = new sn_cc.StandardCredentialsProvider();
var credentials = provider.getCredentials(["ssh"]);
Cet exemple de code montre comment obtenir les informations d’identification du fournisseur pour les types d’informations d’identification « ssh » et « windows » qui ont des balises « admin ».
var provider = new sn_cc.StandardCredentialsProvider();
ArrayList<String> types = new ArrayList<>();
types.add("ssh");
types.add("windows");
JSONArray jsonArray = provider.getCredentials(types, "admin");
StandardCredentialsProvider : getCredentialByAliasID(String sys_id)
Renvoie l’objet d’enregistrement d’informations d’identification via son alias d’informations d’identification (sys_alias).
Cette méthode est spécifiquement destinée à être utilisée avec les types d’informations d’identification. (pour en savoir plus, consultez Credential aliases for Discovery) ;
| Nom | Type | Description |
|---|---|---|
| sys_id | Chaîne | Sys_id de l’enregistrement d’alias d’informations d’identification dans la table Alias de connexion et d’informations d’identification [sys_alias]. |
| Type | Description |
|---|---|
| Informations d’identification standard | Objet d’enregistrement d’informations d’identification. |
L’exemple suivant récupère les informations d’identification à l’aide de l’ID d’alias et affiche le nom d’utilisateur.
var provider = new sn_cc.StandardCredentialsProvider();
var aliasCred = provider.getCredentialByAliasID("752a91887740001038e286a2681061fb");
gs.info("User name: " + aliasCred.getAttribute("user_name"));
Sortie pour un enregistrement d’informations d’identification avec un nom d’utilisateur :
User name: Dara Lee
StandardCredentialsProvider : getCredentialByID(String sys_id)
Renvoie l’objet d’enregistrement d’informations d’identification identifié par le sys_id spécifié.
| Nom | Type | Description |
|---|---|---|
| sys_id | Chaîne | Sys_id de l’enregistrement des informations d’identification. Table : Informations d’identification [discovery_credentials] |
| Type | Description |
|---|---|
| Informations d’identification standard | Objet d’enregistrement d’informations d’identification. |
L’exemple suivant récupère les informations d’identification et affiche le nom d’utilisateur.
var provider = new sn_cc.StandardCredentialsProvider();
var credentials = provider.getCredentialByID("ef43c6d40a0a0b5700c77f9bf387afe3");
gs.info("User name: " + credentials.getAttribute("user_name"));
Sortie pour un enregistrement d’informations d’identification avec un nom d’utilisateur :
User name: Dara Lee