Task Name | Get User Rest API Key. |
Description | - Gets the REST API Key from a given user name.
|
Prerequisites | - Tested on 5.3
|
Category | Custom Task |
Components | |
User Inputs | - userName: The user name to get the Rest API KEY --> Generic Text Input
|
User Outputs | - OUTPUT_REST_API_KEY: The rest api Key from the given user --> Generic Text Input
|
Instructions for Regular Workflow Use:
- Download the attached .ZIP file below to your computer. *Remember the location of the saved file on your computer.
- Unzip the file on your computer. Should end up with a .WFDX file.
- Log in to UCS Director as a user that has "system-admin" privileges.
- Navigate to "Policies-->Orchestration" and click on "Import".
- Click "Browse" and navigate to the location on your computer where the .WFDX file resides. Choose the .WFDX file and click "Open".
- Click "Upload" and then "OK" once the file upload is completed. Then click "Next".
- Click the "Select" button next to "Import Workflows". Click the "Check All" button to check all checkboxes and then the "Select" button.
- Click "Submit".
- A new task should appear in "Policies-->Orchestration--> Custom Workflow tasks" that contains the imported Custom Tasks. Now you can drag and drop the new custom task on the Workflows.
The Custom Task:
The task Input:
The task Output:
The Code:
/*
Name: getUserRestAPIKey.js
Author: Alex Madurga (almadurg@cisco.com)
Date: 26th July 2015
Version: 1
UCSD Version: 5.3
Description: Gets the REST API Key from a given user name.
//INPUTS:
userName: The user name to get the Rest API KEY --> Generic Text Input
//OUTPUTS:
OUTPUT_REST_API_KEY: The rest api Key from the given user --> Generic Text Input
*/
//IMPORTS
importPackage(com.cloupia.service.cIM.inframgr);
//FUNCTIONS
//Function Name:
//Inputs:
//Outputs:
//MAIN CODE
//Input Clean UP - check the Inputs and adapt those to correct types to avoid errors.
var userName = String(input.userName);
output.OUTPUT_REST_API_KEY = "";
//Get the USER Profile and the REST API KEY
userMgr = UserAccessProfileManagerImpl();
try{
var userProfiles = userMgr.getAllUserAccessProfile(userName);
}
catch(e){
ctxt.setFailed("User " + userName + " not found.");
ctxt.exit();
}
//REGISTER OUPUTS
//Seems that there is a user here...
output.OUTPUT_REST_API_KEY = userProfiles[0].getRestKey();
logger.addInfo("User " + userName + " found, REST API Key retrieved.");