1
1
import axios from "axios" ;
2
- import { getAccessToken } from ".. /auth.js" ;
2
+ import { getAccessToken } from "./auth.js" ;
3
3
4
4
const authorizationConfiguration = {
5
5
clientId : process . env . ZEEBE_CLIENT_ID ,
6
6
clientSecret : process . env . ZEEBE_CLIENT_SECRET ,
7
7
audience : process . env . ZEEBE_AUDIENCE
8
8
} ;
9
9
10
- // Retrieves the current authenticated user key.
11
- async function getUser ( ) {
12
- const accessToken = await getAccessToken ( authorizationConfiguration ) ;
13
-
14
- const camundaApiUrl = process . env . ZEEBE_BASE_URL ;
15
- // This is the API endpoint to retrieve the current authenticated user key.
16
- const url = `${ camundaApiUrl } /authentication/me` ;
17
-
18
- // Configure the API call.
19
- const options = {
20
- method : "GET" ,
21
- url,
22
- headers : {
23
- Accept : "application/json" ,
24
- Authorization : `Bearer ${ accessToken } `
25
- }
26
- } ;
27
-
28
- try {
29
- // Call the endpoint.
30
- const response = await axios ( options ) ;
31
-
32
- // Process the results from the API call.
33
- const userKey = response . data ;
34
-
35
- // Emit the user key to output.
36
- console . log ( "User key:" , userKey ) ;
37
- } catch ( error ) {
38
- // Emit an error from the server.
39
- console . error ( error . message ) ;
40
- }
41
- }
42
-
43
- // An action that creates a group.
44
- async function createGroup ( [ groupName ] ) {
10
+ // An action that lists all roles.
11
+ async function listRoles ( ) {
45
12
// Every request needs an access token.
46
13
const accessToken = await getAccessToken ( authorizationConfiguration ) ;
47
14
48
15
// These settings come from your .env file.
49
16
const camundaApiUrl = process . env . ZEEBE_BASE_URL ;
50
17
51
- // This is the API endpoint to add a new client to a cluster .
52
- const url = `${ camundaApiUrl } /groups ` ;
18
+ // This is the API endpoint to query roles .
19
+ const url = `${ camundaApiUrl } /roles/search ` ;
53
20
54
21
// Configure the API call.
55
22
const options = {
@@ -59,38 +26,37 @@ async function createGroup([groupName]) {
59
26
Accept : "application/json" ,
60
27
Authorization : `Bearer ${ accessToken } `
61
28
} ,
62
- data : {
63
- // The body contains information about the new group.
64
- groupName : groupName
65
- }
29
+ // No filtering/paging/sorting, we want all roles.
30
+ data : { }
66
31
} ;
67
32
68
33
try {
34
+ // Call the endpoint.
69
35
const response = await axios ( options ) ;
70
36
71
37
// Process the results from the API call.
72
- const newGroup = response . data ;
38
+ const results = response . data ;
73
39
74
- // Emit new group to output.
75
- console . log (
76
- `Group added! Name: ${ newGroup . name } . Key : ${ newGroup . groupKey } .`
40
+ // Emit roles to output.
41
+ results . items . forEach ( x =>
42
+ console . log ( `Role Name: ${ x . name } ; key : ${ x . key } ` )
77
43
) ;
78
44
} catch ( error ) {
79
45
// Emit an error from the server.
80
46
console . error ( error . message ) ;
81
47
}
82
48
}
83
49
84
- // An action that assigns a user to a group by a key .
85
- async function assignUser ( [ groupKey , userKey ] ) {
50
+ // An action that creates a role .
51
+ async function createRole ( [ roleName ] ) {
86
52
// Every request needs an access token.
87
53
const accessToken = await getAccessToken ( authorizationConfiguration ) ;
88
54
89
55
// These settings come from your .env file.
90
56
const camundaApiUrl = process . env . ZEEBE_BASE_URL ;
91
57
92
- // This is the API endpoint to assign a user to a group .
93
- const url = `${ camundaApiUrl } /groups/ ${ groupKey } /users/ ${ userKey } ` ;
58
+ // This is the API endpoint to add a new client to a cluster .
59
+ const url = `${ camundaApiUrl } /roles ` ;
94
60
95
61
// Configure the API call.
96
62
const options = {
@@ -100,35 +66,36 @@ async function assignUser([groupKey, userKey]) {
100
66
Accept : "application/json" ,
101
67
Authorization : `Bearer ${ accessToken } `
102
68
} ,
69
+ data : {
70
+ // The body contains information about the new role.
71
+ name : roleName
72
+ }
103
73
} ;
104
74
105
75
try {
106
- // Call the add endpoint.
107
76
const response = await axios ( options ) ;
108
77
109
78
// Process the results from the API call.
110
- if ( response . status === 204 ) {
111
- console . log ( `Group assigned to ${ userKey } .` ) ;
112
- } else {
113
- // Emit an unexpected error message.
114
- console . error ( "Unable to assign this user!" ) ;
115
- }
79
+ const newRole = response . data ;
80
+
81
+ // Emit new role to output.
82
+ console . log ( `Role added! Name: ${ roleName } . Key: ${ newRole . roleKey } .` ) ;
116
83
} catch ( error ) {
117
84
// Emit an error from the server.
118
85
console . error ( error . message ) ;
119
86
}
120
87
}
121
88
122
- // An action that retrieves assigned member keys within a group .
123
- async function retrieveGroup ( [ groupKey ] ) {
89
+ // An action that retrieves a role .
90
+ async function getRole ( [ roleKey ] ) {
124
91
// Every request needs an access token.
125
92
const accessToken = await getAccessToken ( authorizationConfiguration ) ;
126
93
127
94
// These settings come from your .env file.
128
95
const camundaApiUrl = process . env . ZEEBE_BASE_URL ;
129
96
130
- // This is the API endpoint to list all assigned member keys within a group .
131
- const url = `${ camundaApiUrl } /groups /${ groupKey } ` ;
97
+ // This is the API endpoint to get a specific role .
98
+ const url = `${ camundaApiUrl } /roles /${ roleKey } ` ;
132
99
133
100
// Configure the API call.
134
101
const options = {
@@ -147,23 +114,25 @@ async function retrieveGroup([groupKey]) {
147
114
// Process the results from the API call.
148
115
const results = response . data ;
149
116
150
- // Emit clients to output.
151
- results . forEach ( x => console . log ( `Name: ${ x . name } ; ID: ${ x . assignedMemberKeys
152
- } `) ) ;
153
- // Not sure how to format the above -- is forEach needed??
117
+ // Emit role to output.
118
+ console . log (
119
+ `Role Name: ${ results . name } ; Key: ${
120
+ results . key
121
+ } ; Members: ${ JSON . stringify ( results . assignedMemberKeys ) } `
122
+ ) ;
154
123
} catch ( error ) {
155
124
// Emit an error from the server.
156
125
console . error ( error . message ) ;
157
126
}
158
127
}
159
128
160
- // An action to delete a group .
161
- async function deleteGroup ( [ groupKey ] ) {
129
+ // An action that deletes a role .
130
+ async function deleteRole ( [ roleKey ] ) {
162
131
const accessToken = await getAccessToken ( authorizationConfiguration ) ;
163
132
164
133
const camundaApiUrl = process . env . ZEEBE_BASE_URL ;
165
134
166
- const url = `${ camundaApiUrl } /groups /${ groupKey } ` ;
135
+ const url = `${ camundaApiUrl } /roles /${ roleKey } ` ;
167
136
168
137
// Configure the API call.
169
138
const options = {
@@ -181,10 +150,10 @@ async function deleteGroup([groupKey]) {
181
150
182
151
// Process the results from the API call.
183
152
if ( response . status === 204 ) {
184
- console . log ( "Group deleted!" ) ;
153
+ console . log ( "Role deleted!" ) ;
185
154
} else {
186
155
// Emit an unexpected error message.
187
- console . error ( "Unable to delete this group !" ) ;
156
+ console . error ( "Unable to delete this role !" ) ;
188
157
}
189
158
} catch ( error ) {
190
159
// Emit an error from the server.
@@ -197,9 +166,8 @@ async function deleteGroup([groupKey]) {
197
166
// e.g. if we export a function named `list`, you can run `npm run cli zeebe get`.
198
167
199
168
export default {
200
- get : getUser ,
201
- create : createGroup ,
202
- assign : assignUser ,
203
- retrieve : retrieveGroup ,
204
- delete : deleteGroup
169
+ list : listRoles ,
170
+ create : createRole ,
171
+ view : getRole ,
172
+ delete : deleteRole
205
173
} ;
0 commit comments