-
Notifications
You must be signed in to change notification settings - Fork 5
/
users.js
94 lines (80 loc) · 2.34 KB
/
users.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
* webMethods.io CLI
* Copyright 2022 Software AG
* Apache-2.0
* [users.js] Users APIs
*/
const request = require('./rest-fetch.js');
var domainName, username,password,timeout;
var prettyprint;
var url;
function checkForErrors(inBody)
{
//Error Codes
//Any error response
}
function debug(message){
logger.debug("<USERS> " + message);
}
function init(inDomainName, inUsername, inPassword,inTimeout,inPrettyprint){
domainName = inDomainName;
username = inUsername;
password = inPassword;
timeout = inTimeout;
prettyprint = inPrettyprint;
url = "https://" + domainName + "/apis/v1/rest";
//console.log("Username [" + username + "]");
//console.log("URL [" + url + "]");
//console.log("Timeout [" + timeout + "]");
}
/**
* Call back function to process REST response
* @param {return data from REST request} data
* @param {status} status
*/
function processResponse(restEndPointUrl, err, data, response) {
let status = response.status;
if(prettyprint==true){
console.log(JSON.stringify(data,null,4));
}
else{
console.log(JSON.stringify(data));
}
if(status!=0){
process.exit(status);
}
}
function list(userId){
url+="/users";
if(userId)url+="/" + userId
debug("USERS URL: " + url);
request.get(url,username,password,timeout,processResponse);
}
function parseRoleListInput(rolesList) {
var arr = rolesList.split(";");
var jsonStr = '[';
for (var rolesCount = 0; rolesCount < arr.length; rolesCount++) {
var roleDetail = arr[rolesCount].split(",");
jsonStr += '{"' + roleDetail[0] + '": [';
for (var permsCount = 1; permsCount < roleDetail.length; permsCount++) {
jsonStr += '"' + roleDetail[permsCount] + '"';
if (permsCount < roleDetail.length - 1)
jsonStr += ",";
}
jsonStr += "]}";
if (rolesCount < arr.length - 1)
jsonStr += ",";
}
jsonStr += "]";
var projects = JSON.parse(jsonStr);
return projects;
}
function assignRoles(userid, roles){
url += "/assign-roles";
debug("URL is [" + url + "]");
roles = roles.split(",");
data={"username":userid,roles};
//console.log(data);
request.put(url,username,password,timeout,data,processResponse);
}
module.exports = { init, list, assignRoles };