mirror of
https://github.com/sasjs/core.git
synced 2026-01-10 10:50:04 +00:00
feat: ms_getusers
This commit is contained in:
@@ -45,13 +45,13 @@
|
|||||||
%mp_abort(
|
%mp_abort(
|
||||||
iftrue=(&syscc ne 0)
|
iftrue=(&syscc ne 0)
|
||||||
,mac=ms_createuser.sas
|
,mac=ms_createuser.sas
|
||||||
,msg=%superq(syscc=&syscc on macro entry)
|
,msg=%str(syscc=&syscc on macro entry)
|
||||||
)
|
)
|
||||||
|
|
||||||
%local fname0 fname1 fname2 libref optval rc msg;
|
%local fref0 fref1 fref2 libref optval rc msg;
|
||||||
%let fname0=%mf_getuniquefileref();
|
%let fref0=%mf_getuniquefileref();
|
||||||
%let fname1=%mf_getuniquefileref();
|
%let fref1=%mf_getuniquefileref();
|
||||||
%let fname2=%mf_getuniquefileref();
|
%let fref2=%mf_getuniquefileref();
|
||||||
%let libref=%mf_getuniquelibref();
|
%let libref=%mf_getuniquelibref();
|
||||||
|
|
||||||
/* avoid sending bom marker to API */
|
/* avoid sending bom marker to API */
|
||||||
@@ -59,7 +59,7 @@
|
|||||||
options nobomfile;
|
options nobomfile;
|
||||||
|
|
||||||
data _null_;
|
data _null_;
|
||||||
file &fname0 termstr=crlf;
|
file &fref0 termstr=crlf;
|
||||||
username=quote(cats(symget('username')));
|
username=quote(cats(symget('username')));
|
||||||
password=quote(cats(symget('password')));
|
password=quote(cats(symget('password')));
|
||||||
isadmin=symget('isadmin');
|
isadmin=symget('isadmin');
|
||||||
@@ -79,7 +79,7 @@ data _null_;
|
|||||||
run;
|
run;
|
||||||
|
|
||||||
data _null_;
|
data _null_;
|
||||||
file &fname1 lrecl=1000;
|
file &fref1 lrecl=1000;
|
||||||
infile "&_sasjs_tokenfile" lrecl=1000;
|
infile "&_sasjs_tokenfile" lrecl=1000;
|
||||||
input;
|
input;
|
||||||
put "Authorization: Bearer " _infile_;
|
put "Authorization: Bearer " _infile_;
|
||||||
@@ -89,17 +89,17 @@ run;
|
|||||||
|
|
||||||
%if &mdebug=1 %then %do;
|
%if &mdebug=1 %then %do;
|
||||||
data _null_;
|
data _null_;
|
||||||
infile &fname0;
|
infile &fref0;
|
||||||
input;
|
input;
|
||||||
put _infile_;
|
put _infile_;
|
||||||
data _null_;
|
data _null_;
|
||||||
infile &fname1;
|
infile &fref1;
|
||||||
input;
|
input;
|
||||||
put _infile_;
|
put _infile_;
|
||||||
run;
|
run;
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
proc http method='POST' in=&fname0 headerin=&fname1 out=&fname2
|
proc http method='POST' in=&fref0 headerin=&fref1 out=&fref2
|
||||||
url="&_sasjs_apiserverurl/SASjsApi/user";
|
url="&_sasjs_apiserverurl/SASjsApi/user";
|
||||||
%if &mdebug=1 %then %do;
|
%if &mdebug=1 %then %do;
|
||||||
debug level=1;
|
debug level=1;
|
||||||
@@ -109,10 +109,10 @@ run;
|
|||||||
%mp_abort(
|
%mp_abort(
|
||||||
iftrue=(&syscc ne 0)
|
iftrue=(&syscc ne 0)
|
||||||
,mac=ms_createuser.sas
|
,mac=ms_createuser.sas
|
||||||
,msg=%superq(Issue submitting query to SASjsApi/user)
|
,msg=%str(Issue submitting query to SASjsApi/user)
|
||||||
)
|
)
|
||||||
|
|
||||||
libname &libref JSON fileref=&fname2;
|
libname &libref JSON fileref=&fref2;
|
||||||
|
|
||||||
data &outds;
|
data &outds;
|
||||||
set &libref..root;
|
set &libref..root;
|
||||||
@@ -123,7 +123,7 @@ run;
|
|||||||
%mp_abort(
|
%mp_abort(
|
||||||
iftrue=(&syscc ne 0)
|
iftrue=(&syscc ne 0)
|
||||||
,mac=ms_createuser.sas
|
,mac=ms_createuser.sas
|
||||||
,msg=%superq(Issue reading response JSON)
|
,msg=%str(Issue reading response JSON)
|
||||||
)
|
)
|
||||||
|
|
||||||
/* reset options */
|
/* reset options */
|
||||||
|
|||||||
101
server/ms_getusers.sas
Normal file
101
server/ms_getusers.sas
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
/**
|
||||||
|
@file
|
||||||
|
@brief Fetches the list of users from SASjs Server
|
||||||
|
@details Fetches the list of users from SASjs Server.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
%ms_getusers(outds=userlist)
|
||||||
|
|
||||||
|
@param [out] outds= (work.ms_getusers) This output dataset will contain the
|
||||||
|
list of user accounts. Format:
|
||||||
|
|DISPLAYNAME:$18.|USERNAME:$10.|ID:best.|
|
||||||
|
|---|---|---|
|
||||||
|
|`Super Admin `|`secretuser `|`1`|
|
||||||
|
|`Sabir Hassan`|`sabir`|`2`|
|
||||||
|
|`Mihajlo Medjedovic `|`mihajlo `|`3`|
|
||||||
|
|`Ivor Townsend `|`ivor `|`4`|
|
||||||
|
|`New User `|`newuser `|`5`|
|
||||||
|
|
||||||
|
@param [in] mdebug= (0) Set to 1 to enable DEBUG messages
|
||||||
|
|
||||||
|
<h4> SAS Macros </h4>
|
||||||
|
@li mf_getuniquefileref.sas
|
||||||
|
@li mf_getuniquelibref.sas
|
||||||
|
@li mp_abort.sas
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
%macro ms_getusers(
|
||||||
|
outds=work.ms_getusers
|
||||||
|
,mdebug=0
|
||||||
|
);
|
||||||
|
|
||||||
|
%mp_abort(
|
||||||
|
iftrue=(&syscc ne 0)
|
||||||
|
,mac=ms_getusers.sas
|
||||||
|
,msg=%str(syscc=&syscc on macro entry)
|
||||||
|
)
|
||||||
|
|
||||||
|
%local fref0 fref1 libref optval rc msg;
|
||||||
|
%let fref0=%mf_getuniquefileref();
|
||||||
|
%let fref1=%mf_getuniquefileref();
|
||||||
|
%let libref=%mf_getuniquelibref();
|
||||||
|
|
||||||
|
/* avoid sending bom marker to API */
|
||||||
|
%let optval=%sysfunc(getoption(bomfile));
|
||||||
|
options nobomfile;
|
||||||
|
|
||||||
|
data _null_;
|
||||||
|
file &fref0 lrecl=1000;
|
||||||
|
infile "&_sasjs_tokenfile" lrecl=1000;
|
||||||
|
input;
|
||||||
|
put "Authorization: Bearer " _infile_;
|
||||||
|
put "accept: application/json";
|
||||||
|
run;
|
||||||
|
|
||||||
|
%if &mdebug=1 %then %do;
|
||||||
|
data _null_;
|
||||||
|
infile &fref0;
|
||||||
|
input;
|
||||||
|
put _infile_;
|
||||||
|
run;
|
||||||
|
%end;
|
||||||
|
|
||||||
|
proc http method='GET' headerin=&fref0 out=&fref1
|
||||||
|
url="&_sasjs_apiserverurl/SASjsApi/user";
|
||||||
|
%if &mdebug=1 %then %do;
|
||||||
|
debug level=1;
|
||||||
|
%end;
|
||||||
|
run;
|
||||||
|
|
||||||
|
%mp_abort(
|
||||||
|
iftrue=(&syscc ne 0)
|
||||||
|
,mac=ms_getusers.sas
|
||||||
|
,msg=%str(Issue submitting GET query to SASjsApi/user)
|
||||||
|
)
|
||||||
|
|
||||||
|
libname &libref JSON fileref=&fref1;
|
||||||
|
|
||||||
|
data &outds;
|
||||||
|
set &libref..root;
|
||||||
|
drop ordinal_root;
|
||||||
|
run;
|
||||||
|
|
||||||
|
|
||||||
|
%mp_abort(
|
||||||
|
iftrue=(&syscc ne 0)
|
||||||
|
,mac=ms_getusers.sas
|
||||||
|
,msg=%str(Issue reading response JSON)
|
||||||
|
)
|
||||||
|
|
||||||
|
/* reset options */
|
||||||
|
options &optval;
|
||||||
|
|
||||||
|
%if &mdebug=1 %then %do;
|
||||||
|
filename &fref0 clear;
|
||||||
|
filename &fref1 clear;
|
||||||
|
libname &libref clear;
|
||||||
|
%end;
|
||||||
|
|
||||||
|
%mend ms_getusers;
|
||||||
Reference in New Issue
Block a user