@sasjs/core 4.18.18 → 4.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/server/ms_createuser.sas +144 -0
- package/server/ms_getusers.sas +107 -0
package/package.json
CHANGED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief Creates a user on SASjs Server
|
|
4
|
+
@details Creates a user on SASjs Server with the following attributes:
|
|
5
|
+
|
|
6
|
+
@li UserName
|
|
7
|
+
@li Password
|
|
8
|
+
@li isAdmin
|
|
9
|
+
@li displayName
|
|
10
|
+
|
|
11
|
+
The userid is created by sasjs/server. All users are created with `isActive`
|
|
12
|
+
set to `true`.
|
|
13
|
+
|
|
14
|
+
Example:
|
|
15
|
+
|
|
16
|
+
%ms_createuser(newuser,secretpass,displayname=New User!)
|
|
17
|
+
|
|
18
|
+
@param [in] username The username to apply. No spaces or special characters.
|
|
19
|
+
@param [in] password The initial password to set.
|
|
20
|
+
@param [in] isadmin= (false) Set to true to give the user admin rights
|
|
21
|
+
@param [in] displayName= (0) Set a friendly name (spaces & special characters
|
|
22
|
+
are ok). If not provided, username will be used instead.
|
|
23
|
+
@param [in] mdebug= (0) Set to 1 to enable DEBUG messages
|
|
24
|
+
@param [out] outds= (work.ms_createuser) This output dataset will contain the
|
|
25
|
+
values from the JSON response (such as the id of the new user)
|
|
26
|
+
|ID:best.|DISPLAYNAME:$8.|USERNAME:$8.|ISACTIVE:best.|ISADMIN:best.|
|
|
27
|
+
|---|---|---|---|---|
|
|
28
|
+
|`6 `|`New User `|`newuser `|`1 `|`0 `|
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
<h4> SAS Macros </h4>
|
|
33
|
+
@li mf_getuniquefileref.sas
|
|
34
|
+
@li mf_getuniquelibref.sas
|
|
35
|
+
@li mp_abort.sas
|
|
36
|
+
|
|
37
|
+
<h4> Related Files </h4>
|
|
38
|
+
@li ms_createuser.test.sas
|
|
39
|
+
@li ms_getusers.sas
|
|
40
|
+
|
|
41
|
+
**/
|
|
42
|
+
|
|
43
|
+
%macro ms_createuser(username,password
|
|
44
|
+
,isadmin=false
|
|
45
|
+
,displayname=0
|
|
46
|
+
,outds=work.ms_createuser
|
|
47
|
+
,mdebug=0
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
%mp_abort(
|
|
51
|
+
iftrue=(&syscc ne 0)
|
|
52
|
+
,mac=ms_createuser.sas
|
|
53
|
+
,msg=%str(syscc=&syscc on macro entry)
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
%local fref0 fref1 fref2 libref optval rc msg;
|
|
57
|
+
%let fref0=%mf_getuniquefileref();
|
|
58
|
+
%let fref1=%mf_getuniquefileref();
|
|
59
|
+
%let fref2=%mf_getuniquefileref();
|
|
60
|
+
%let libref=%mf_getuniquelibref();
|
|
61
|
+
|
|
62
|
+
/* avoid sending bom marker to API */
|
|
63
|
+
%let optval=%sysfunc(getoption(bomfile));
|
|
64
|
+
options nobomfile;
|
|
65
|
+
|
|
66
|
+
data _null_;
|
|
67
|
+
file &fref0 termstr=crlf;
|
|
68
|
+
username=quote(cats(symget('username')));
|
|
69
|
+
password=quote(cats(symget('password')));
|
|
70
|
+
isadmin=symget('isadmin');
|
|
71
|
+
displayname=quote(cats(symget('displayname')));
|
|
72
|
+
if displayname='"0"' then displayname=username;
|
|
73
|
+
|
|
74
|
+
%if &mdebug=1 %then %do;
|
|
75
|
+
putlog _all_;
|
|
76
|
+
%end;
|
|
77
|
+
|
|
78
|
+
put '{'@;
|
|
79
|
+
put '"displayName":' displayname @;
|
|
80
|
+
put ',"username":' username @;
|
|
81
|
+
put ',"password":' password @;
|
|
82
|
+
put ',"isAdmin":' isadmin @;
|
|
83
|
+
put ',"isActive": true }';
|
|
84
|
+
run;
|
|
85
|
+
|
|
86
|
+
data _null_;
|
|
87
|
+
file &fref1 lrecl=1000;
|
|
88
|
+
infile "&_sasjs_tokenfile" lrecl=1000;
|
|
89
|
+
input;
|
|
90
|
+
put "Authorization: Bearer " _infile_;
|
|
91
|
+
put "Content-Type: application/json";
|
|
92
|
+
put "accept: application/json";
|
|
93
|
+
run;
|
|
94
|
+
|
|
95
|
+
%if &mdebug=1 %then %do;
|
|
96
|
+
data _null_;
|
|
97
|
+
infile &fref0;
|
|
98
|
+
input;
|
|
99
|
+
put _infile_;
|
|
100
|
+
data _null_;
|
|
101
|
+
infile &fref1;
|
|
102
|
+
input;
|
|
103
|
+
put _infile_;
|
|
104
|
+
run;
|
|
105
|
+
%end;
|
|
106
|
+
|
|
107
|
+
proc http method='POST' in=&fref0 headerin=&fref1 out=&fref2
|
|
108
|
+
url="&_sasjs_apiserverurl/SASjsApi/user";
|
|
109
|
+
%if &mdebug=1 %then %do;
|
|
110
|
+
debug level=1;
|
|
111
|
+
%end;
|
|
112
|
+
run;
|
|
113
|
+
|
|
114
|
+
%mp_abort(
|
|
115
|
+
iftrue=(&syscc ne 0)
|
|
116
|
+
,mac=ms_createuser.sas
|
|
117
|
+
,msg=%str(Issue submitting query to SASjsApi/user)
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
libname &libref JSON fileref=&fref2;
|
|
121
|
+
|
|
122
|
+
data &outds;
|
|
123
|
+
set &libref..root;
|
|
124
|
+
drop ordinal_root;
|
|
125
|
+
run;
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
%mp_abort(
|
|
129
|
+
iftrue=(&syscc ne 0)
|
|
130
|
+
,mac=ms_createuser.sas
|
|
131
|
+
,msg=%str(Issue reading response JSON)
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
/* reset options */
|
|
135
|
+
options &optval;
|
|
136
|
+
|
|
137
|
+
%if &mdebug=1 %then %do;
|
|
138
|
+
filename &fref0 clear;
|
|
139
|
+
filename &fref1 clear;
|
|
140
|
+
filename &fref2 clear;
|
|
141
|
+
libname &libref clear;
|
|
142
|
+
%end;
|
|
143
|
+
|
|
144
|
+
%mend ms_createuser;
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief Fetches the list of users from SASjs Server
|
|
4
|
+
@details Fetches the list of users from SASjs Server and writes them to an
|
|
5
|
+
output dataset.
|
|
6
|
+
|
|
7
|
+
Example:
|
|
8
|
+
|
|
9
|
+
%ms_getusers(outds=userlist)
|
|
10
|
+
|
|
11
|
+
@param [in] mdebug= (0) Set to 1 to enable DEBUG messages
|
|
12
|
+
@param [out] outds= (work.ms_getusers) This output dataset will contain the
|
|
13
|
+
list of user accounts. Format:
|
|
14
|
+
|DISPLAYNAME:$18.|USERNAME:$10.|ID:best.|
|
|
15
|
+
|---|---|---|
|
|
16
|
+
|`Super Admin `|`secretuser `|`1`|
|
|
17
|
+
|`Sabir Hassan`|`sabir`|`2`|
|
|
18
|
+
|`Mihajlo Medjedovic `|`mihajlo `|`3`|
|
|
19
|
+
|`Ivor Townsend `|`ivor `|`4`|
|
|
20
|
+
|`New User `|`newuser `|`5`|
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
<h4> SAS Macros </h4>
|
|
25
|
+
@li mf_getuniquefileref.sas
|
|
26
|
+
@li mf_getuniquelibref.sas
|
|
27
|
+
@li mp_abort.sas
|
|
28
|
+
|
|
29
|
+
<h4> Related Files </h4>
|
|
30
|
+
@li ms_createuser.sas
|
|
31
|
+
@li ms_getusers.test.sas
|
|
32
|
+
|
|
33
|
+
**/
|
|
34
|
+
|
|
35
|
+
%macro ms_getusers(
|
|
36
|
+
outds=work.ms_getusers
|
|
37
|
+
,mdebug=0
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
%mp_abort(
|
|
41
|
+
iftrue=(&syscc ne 0)
|
|
42
|
+
,mac=ms_getusers.sas
|
|
43
|
+
,msg=%str(syscc=&syscc on macro entry)
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
%local fref0 fref1 libref optval rc msg;
|
|
47
|
+
%let fref0=%mf_getuniquefileref();
|
|
48
|
+
%let fref1=%mf_getuniquefileref();
|
|
49
|
+
%let libref=%mf_getuniquelibref();
|
|
50
|
+
|
|
51
|
+
/* avoid sending bom marker to API */
|
|
52
|
+
%let optval=%sysfunc(getoption(bomfile));
|
|
53
|
+
options nobomfile;
|
|
54
|
+
|
|
55
|
+
data _null_;
|
|
56
|
+
file &fref0 lrecl=1000;
|
|
57
|
+
infile "&_sasjs_tokenfile" lrecl=1000;
|
|
58
|
+
input;
|
|
59
|
+
put "Authorization: Bearer " _infile_;
|
|
60
|
+
put "accept: application/json";
|
|
61
|
+
run;
|
|
62
|
+
|
|
63
|
+
%if &mdebug=1 %then %do;
|
|
64
|
+
data _null_;
|
|
65
|
+
infile &fref0;
|
|
66
|
+
input;
|
|
67
|
+
put _infile_;
|
|
68
|
+
run;
|
|
69
|
+
%end;
|
|
70
|
+
|
|
71
|
+
proc http method='GET' headerin=&fref0 out=&fref1
|
|
72
|
+
url="&_sasjs_apiserverurl/SASjsApi/user";
|
|
73
|
+
%if &mdebug=1 %then %do;
|
|
74
|
+
debug level=1;
|
|
75
|
+
%end;
|
|
76
|
+
run;
|
|
77
|
+
|
|
78
|
+
%mp_abort(
|
|
79
|
+
iftrue=(&syscc ne 0)
|
|
80
|
+
,mac=ms_getusers.sas
|
|
81
|
+
,msg=%str(Issue submitting GET query to SASjsApi/user)
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
libname &libref JSON fileref=&fref1;
|
|
85
|
+
|
|
86
|
+
data &outds;
|
|
87
|
+
set &libref..root;
|
|
88
|
+
drop ordinal_root;
|
|
89
|
+
run;
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
%mp_abort(
|
|
93
|
+
iftrue=(&syscc ne 0)
|
|
94
|
+
,mac=ms_getusers.sas
|
|
95
|
+
,msg=%str(Issue reading response JSON)
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
/* reset options */
|
|
99
|
+
options &optval;
|
|
100
|
+
|
|
101
|
+
%if &mdebug=1 %then %do;
|
|
102
|
+
filename &fref0 clear;
|
|
103
|
+
filename &fref1 clear;
|
|
104
|
+
libname &libref clear;
|
|
105
|
+
%end;
|
|
106
|
+
|
|
107
|
+
%mend ms_getusers;
|