mirror of
https://github.com/sasjs/core.git
synced 2026-01-11 02:50:06 +00:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7e9f10291 | ||
|
|
3edc3587b3 | ||
|
|
63bf00e28f | ||
|
|
6b2574947a | ||
|
|
eb9027ecb6 | ||
|
|
2ad931a566 | ||
|
|
cebe119304 | ||
|
|
bd3082d7e3 | ||
|
|
11da53f1cb | ||
|
|
c4cb0b2395 | ||
|
|
58614e9a3d | ||
|
|
c94c334c4b | ||
|
|
3bf44405f8 | ||
|
|
db68a256cb |
385
all.sas
385
all.sas
@@ -8441,19 +8441,23 @@ options
|
|||||||
format _numeric_ bart.;
|
format _numeric_ bart.;
|
||||||
%do i=1 %to &numcols;
|
%do i=1 %to &numcols;
|
||||||
%if &&typelong&i=char or &fmt=Y %then %do;
|
%if &&typelong&i=char or &fmt=Y %then %do;
|
||||||
&&name&i='"'!!trim(prxchange('s/"/\"/',-1,
|
if findc(&&name&i,'"\'!!'0A0D09000E0F01021011'x) then do;
|
||||||
prxchange('s/'!!'0A'x!!'/\n/',-1,
|
&&name&i='"'!!trim(
|
||||||
prxchange('s/'!!'0D'x!!'/\r/',-1,
|
prxchange('s/"/\\"/',-1, /* double quote */
|
||||||
prxchange('s/'!!'09'x!!'/\t/',-1,
|
prxchange('s/\x0A/\n/',-1, /* new line */
|
||||||
prxchange('s/\x00/\\u0000/',-1, /* NUL */
|
prxchange('s/\x0D/\r/',-1, /* carriage return */
|
||||||
prxchange('s/\x0E/\\u000E/',-1, /* SS */
|
prxchange('s/\x09/\\t/',-1, /* tab */
|
||||||
prxchange('s/\x0F/\\u000F/',-1, /* SF */
|
prxchange('s/\x00/\\u0000/',-1, /* NUL */
|
||||||
prxchange('s/\x01/\\u0001/',-1, /* SOH */
|
prxchange('s/\x0E/\\u000E/',-1, /* SS */
|
||||||
prxchange('s/\x02/\\u0002/',-1, /* STX */
|
prxchange('s/\x0F/\\u000F/',-1, /* SF */
|
||||||
prxchange('s/\x10/\\u0010/',-1, /* DLE */
|
prxchange('s/\x01/\\u0001/',-1, /* SOH */
|
||||||
prxchange('s/\x11/\\u0011/',-1, /* DC1 */
|
prxchange('s/\x02/\\u0002/',-1, /* STX */
|
||||||
prxchange('s/\\/\\\\/',-1,&&name&i)
|
prxchange('s/\x10/\\u0010/',-1, /* DLE */
|
||||||
))))))))))))!!'"';
|
prxchange('s/\x11/\\u0011/',-1, /* DC1 */
|
||||||
|
prxchange('s/\\/\\\\/',-1,&&name&i)
|
||||||
|
))))))))))))!!'"';
|
||||||
|
end;
|
||||||
|
else &&name&i=quote(cats(&&name&i));
|
||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
run;
|
run;
|
||||||
@@ -14966,19 +14970,23 @@ data _null_;
|
|||||||
put ' format _numeric_ bart.; ';
|
put ' format _numeric_ bart.; ';
|
||||||
put ' %do i=1 %to &numcols; ';
|
put ' %do i=1 %to &numcols; ';
|
||||||
put ' %if &&typelong&i=char or &fmt=Y %then %do; ';
|
put ' %if &&typelong&i=char or &fmt=Y %then %do; ';
|
||||||
put ' &&name&i=''"''!!trim(prxchange(''s/"/\"/'',-1, ';
|
put ' if findc(&&name&i,''"\''!!''0A0D09000E0F01021011''x) then do; ';
|
||||||
put ' prxchange(''s/''!!''0A''x!!''/\n/'',-1, ';
|
put ' &&name&i=''"''!!trim( ';
|
||||||
put ' prxchange(''s/''!!''0D''x!!''/\r/'',-1, ';
|
put ' prxchange(''s/"/\\"/'',-1, /* double quote */ ';
|
||||||
put ' prxchange(''s/''!!''09''x!!''/\t/'',-1, ';
|
put ' prxchange(''s/\x0A/\n/'',-1, /* new line */ ';
|
||||||
put ' prxchange(''s/\x00/\\u0000/'',-1, /* NUL */ ';
|
put ' prxchange(''s/\x0D/\r/'',-1, /* carriage return */ ';
|
||||||
put ' prxchange(''s/\x0E/\\u000E/'',-1, /* SS */ ';
|
put ' prxchange(''s/\x09/\\t/'',-1, /* tab */ ';
|
||||||
put ' prxchange(''s/\x0F/\\u000F/'',-1, /* SF */ ';
|
put ' prxchange(''s/\x00/\\u0000/'',-1, /* NUL */ ';
|
||||||
put ' prxchange(''s/\x01/\\u0001/'',-1, /* SOH */ ';
|
put ' prxchange(''s/\x0E/\\u000E/'',-1, /* SS */ ';
|
||||||
put ' prxchange(''s/\x02/\\u0002/'',-1, /* STX */ ';
|
put ' prxchange(''s/\x0F/\\u000F/'',-1, /* SF */ ';
|
||||||
put ' prxchange(''s/\x10/\\u0010/'',-1, /* DLE */ ';
|
put ' prxchange(''s/\x01/\\u0001/'',-1, /* SOH */ ';
|
||||||
put ' prxchange(''s/\x11/\\u0011/'',-1, /* DC1 */ ';
|
put ' prxchange(''s/\x02/\\u0002/'',-1, /* STX */ ';
|
||||||
put ' prxchange(''s/\\/\\\\/'',-1,&&name&i) ';
|
put ' prxchange(''s/\x10/\\u0010/'',-1, /* DLE */ ';
|
||||||
put ' ))))))))))))!!''"''; ';
|
put ' prxchange(''s/\x11/\\u0011/'',-1, /* DC1 */ ';
|
||||||
|
put ' prxchange(''s/\\/\\\\/'',-1,&&name&i) ';
|
||||||
|
put ' ))))))))))))!!''"''; ';
|
||||||
|
put ' end; ';
|
||||||
|
put ' else &&name&i=quote(cats(&&name&i)); ';
|
||||||
put ' %end; ';
|
put ' %end; ';
|
||||||
put ' %end; ';
|
put ' %end; ';
|
||||||
put ' run; ';
|
put ' run; ';
|
||||||
@@ -18970,8 +18978,11 @@ data _null_;
|
|||||||
run;
|
run;
|
||||||
|
|
||||||
data _null_;
|
data _null_;
|
||||||
file &fname1;
|
file &fname1 lrecl=1000;
|
||||||
|
infile "&_sasjs_tokenfile" lrecl=1000;
|
||||||
|
input;
|
||||||
put "Content-Type: multipart/form-data; boundary=&boundary";
|
put "Content-Type: multipart/form-data; boundary=&boundary";
|
||||||
|
put "Authorization: Bearer " _infile_;
|
||||||
run;
|
run;
|
||||||
|
|
||||||
%if &mdebug=1 %then %do;
|
%if &mdebug=1 %then %do;
|
||||||
@@ -19012,6 +19023,150 @@ run;
|
|||||||
options &optval;
|
options &optval;
|
||||||
|
|
||||||
%mend ms_createfile;
|
%mend ms_createfile;
|
||||||
|
/**
|
||||||
|
@file
|
||||||
|
@brief Creates a user on SASjs Server
|
||||||
|
@details Creates a user on SASjs Server with the following attributes:
|
||||||
|
|
||||||
|
@li UserName
|
||||||
|
@li Password
|
||||||
|
@li isAdmin
|
||||||
|
@li displayName
|
||||||
|
|
||||||
|
The userid is created by sasjs/server. All users are created with `isActive`
|
||||||
|
set to `true`.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
%ms_createuser(newuser,secretpass,displayname=New User!)
|
||||||
|
|
||||||
|
@param [in] username The username to apply. No spaces or special characters.
|
||||||
|
@param [in] password The initial password to set.
|
||||||
|
@param [in] isadmin= (false) Set to true to give the user admin rights
|
||||||
|
@param [in] displayName= (0) Set a friendly name (spaces & special characters
|
||||||
|
are ok). If not provided, username will be used instead.
|
||||||
|
@param [in] mdebug= (0) Set to 1 to enable DEBUG messages
|
||||||
|
@param [out] outds= (work.ms_createuser) This output dataset will contain the
|
||||||
|
values from the JSON response (such as the id of the new user)
|
||||||
|
|ID:best.|DISPLAYNAME:$8.|USERNAME:$8.|ISACTIVE:best.|ISADMIN:best.|
|
||||||
|
|---|---|---|---|---|
|
||||||
|
|`6 `|`New User `|`newuser `|`1 `|`0 `|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<h4> SAS Macros </h4>
|
||||||
|
@li mf_getuniquefileref.sas
|
||||||
|
@li mf_getuniquelibref.sas
|
||||||
|
@li mp_abort.sas
|
||||||
|
|
||||||
|
<h4> Related Files </h4>
|
||||||
|
@li ms_createuser.test.sas
|
||||||
|
@li ms_getusers.sas
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
%macro ms_createuser(username,password
|
||||||
|
,isadmin=false
|
||||||
|
,displayname=0
|
||||||
|
,outds=work.ms_createuser
|
||||||
|
,mdebug=0
|
||||||
|
);
|
||||||
|
|
||||||
|
%mp_abort(
|
||||||
|
iftrue=(&syscc ne 0)
|
||||||
|
,mac=ms_createuser.sas
|
||||||
|
,msg=%str(syscc=&syscc on macro entry)
|
||||||
|
)
|
||||||
|
|
||||||
|
%local fref0 fref1 fref2 libref optval rc msg;
|
||||||
|
%let fref0=%mf_getuniquefileref();
|
||||||
|
%let fref1=%mf_getuniquefileref();
|
||||||
|
%let fref2=%mf_getuniquefileref();
|
||||||
|
%let libref=%mf_getuniquelibref();
|
||||||
|
|
||||||
|
/* avoid sending bom marker to API */
|
||||||
|
%let optval=%sysfunc(getoption(bomfile));
|
||||||
|
options nobomfile;
|
||||||
|
|
||||||
|
data _null_;
|
||||||
|
file &fref0 termstr=crlf;
|
||||||
|
username=quote(cats(symget('username')));
|
||||||
|
password=quote(cats(symget('password')));
|
||||||
|
isadmin=symget('isadmin');
|
||||||
|
displayname=quote(cats(symget('displayname')));
|
||||||
|
if displayname='"0"' then displayname=username;
|
||||||
|
|
||||||
|
%if &mdebug=1 %then %do;
|
||||||
|
putlog _all_;
|
||||||
|
%end;
|
||||||
|
|
||||||
|
put '{'@;
|
||||||
|
put '"displayName":' displayname @;
|
||||||
|
put ',"username":' username @;
|
||||||
|
put ',"password":' password @;
|
||||||
|
put ',"isAdmin":' isadmin @;
|
||||||
|
put ',"isActive": true }';
|
||||||
|
run;
|
||||||
|
|
||||||
|
data _null_;
|
||||||
|
file &fref1 lrecl=1000;
|
||||||
|
infile "&_sasjs_tokenfile" lrecl=1000;
|
||||||
|
input;
|
||||||
|
put "Authorization: Bearer " _infile_;
|
||||||
|
put "Content-Type: application/json";
|
||||||
|
put "accept: application/json";
|
||||||
|
run;
|
||||||
|
|
||||||
|
%if &mdebug=1 %then %do;
|
||||||
|
data _null_;
|
||||||
|
infile &fref0;
|
||||||
|
input;
|
||||||
|
put _infile_;
|
||||||
|
data _null_;
|
||||||
|
infile &fref1;
|
||||||
|
input;
|
||||||
|
put _infile_;
|
||||||
|
run;
|
||||||
|
%end;
|
||||||
|
|
||||||
|
proc http method='POST' in=&fref0 headerin=&fref1 out=&fref2
|
||||||
|
url="&_sasjs_apiserverurl/SASjsApi/user";
|
||||||
|
%if &mdebug=1 %then %do;
|
||||||
|
debug level=1;
|
||||||
|
%end;
|
||||||
|
run;
|
||||||
|
|
||||||
|
%mp_abort(
|
||||||
|
iftrue=(&syscc ne 0)
|
||||||
|
,mac=ms_createuser.sas
|
||||||
|
,msg=%str(Issue submitting query to SASjsApi/user)
|
||||||
|
)
|
||||||
|
|
||||||
|
libname &libref JSON fileref=&fref2;
|
||||||
|
|
||||||
|
data &outds;
|
||||||
|
set &libref..root;
|
||||||
|
drop ordinal_root;
|
||||||
|
run;
|
||||||
|
|
||||||
|
|
||||||
|
%mp_abort(
|
||||||
|
iftrue=(&syscc ne 0)
|
||||||
|
,mac=ms_createuser.sas
|
||||||
|
,msg=%str(Issue reading response JSON)
|
||||||
|
)
|
||||||
|
|
||||||
|
/* reset options */
|
||||||
|
options &optval;
|
||||||
|
|
||||||
|
%if &mdebug=1 %then %do;
|
||||||
|
filename &fref0 clear;
|
||||||
|
filename &fref1 clear;
|
||||||
|
filename &fref2 clear;
|
||||||
|
libname &libref clear;
|
||||||
|
%end;
|
||||||
|
|
||||||
|
%mend ms_createuser;
|
||||||
/**
|
/**
|
||||||
@file
|
@file
|
||||||
@brief Deletes a file from SASjs Drive
|
@brief Deletes a file from SASjs Drive
|
||||||
@@ -19031,6 +19186,8 @@ options &optval;
|
|||||||
@param [in] driveloc The full path to the file in SASjs Drive
|
@param [in] driveloc The full path to the file in SASjs Drive
|
||||||
@param [in] mdebug= (0) Set to 1 to enable DEBUG messages
|
@param [in] mdebug= (0) Set to 1 to enable DEBUG messages
|
||||||
|
|
||||||
|
<h4> SAS Macros </h4>
|
||||||
|
@li mf_getuniquefileref.sas
|
||||||
|
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@@ -19038,13 +19195,24 @@ options &optval;
|
|||||||
,mdebug=0
|
,mdebug=0
|
||||||
);
|
);
|
||||||
|
|
||||||
proc http method='DELETE'
|
%local headref;
|
||||||
|
%let headref=%mf_getuniquefileref();
|
||||||
|
|
||||||
|
data _null_;
|
||||||
|
file &headref lrecl=1000;
|
||||||
|
infile "&_sasjs_tokenfile" lrecl=1000;
|
||||||
|
input;
|
||||||
|
put "Authorization: Bearer " _infile_;
|
||||||
|
run;
|
||||||
|
|
||||||
|
proc http method='DELETE' headerin=&headref
|
||||||
url="&_sasjs_apiserverurl/SASjsApi/drive/file?_filePath=&driveloc";
|
url="&_sasjs_apiserverurl/SASjsApi/drive/file?_filePath=&driveloc";
|
||||||
%if &mdebug=1 %then %do;
|
%if &mdebug=1 %then %do;
|
||||||
debug level=2;
|
debug level=2;
|
||||||
%end;
|
%end;
|
||||||
run;
|
run;
|
||||||
|
|
||||||
|
filename &headref clear;
|
||||||
|
|
||||||
%mend ms_deletefile;
|
%mend ms_deletefile;
|
||||||
/**
|
/**
|
||||||
@@ -19054,7 +19222,7 @@ run;
|
|||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
%ms_getfile(/some/stored/file.ext, outref=myfile)
|
%ms_getfile(/Public/app/dc/services/public/settings.sas, outref=myfile)
|
||||||
|
|
||||||
@param [in] driveloc The full path to the file in SASjs Drive
|
@param [in] driveloc The full path to the file in SASjs Drive
|
||||||
@param [out] outref= (msgetfil) The fileref to contain the file.
|
@param [out] outref= (msgetfil) The fileref to contain the file.
|
||||||
@@ -19072,13 +19240,21 @@ run;
|
|||||||
);
|
);
|
||||||
|
|
||||||
/* use the recfm in a separate fileref to avoid issues with subsequent reads */
|
/* use the recfm in a separate fileref to avoid issues with subsequent reads */
|
||||||
%local binaryfref floc;
|
%local binaryfref floc headref;
|
||||||
%let binaryfref=%mf_getuniquefileref();
|
%let binaryfref=%mf_getuniquefileref();
|
||||||
|
%let headref=%mf_getuniquefileref();
|
||||||
%let floc=%sysfunc(pathname(work))/%mf_getuniquename().txt;
|
%let floc=%sysfunc(pathname(work))/%mf_getuniquename().txt;
|
||||||
filename &outref "&floc";
|
filename &outref "&floc" lrecl=32767;
|
||||||
filename &binaryfref "&floc" recfm=n;
|
filename &binaryfref "&floc" recfm=n;
|
||||||
|
|
||||||
proc http method='GET' out=&binaryfref
|
data _null_;
|
||||||
|
file &headref lrecl=1000;
|
||||||
|
infile "&_sasjs_tokenfile" lrecl=1000;
|
||||||
|
input;
|
||||||
|
put "Authorization: Bearer " _infile_;
|
||||||
|
run;
|
||||||
|
|
||||||
|
proc http method='GET' out=&binaryfref headerin=&headref
|
||||||
url="&_sasjs_apiserverurl/SASjsApi/drive/file?_filePath=&driveloc";
|
url="&_sasjs_apiserverurl/SASjsApi/drive/file?_filePath=&driveloc";
|
||||||
%if &mdebug=1 %then %do;
|
%if &mdebug=1 %then %do;
|
||||||
debug level=2;
|
debug level=2;
|
||||||
@@ -19086,8 +19262,115 @@ proc http method='GET' out=&binaryfref
|
|||||||
run;
|
run;
|
||||||
|
|
||||||
filename &binaryfref clear;
|
filename &binaryfref clear;
|
||||||
|
filename &headref clear;
|
||||||
|
|
||||||
%mend ms_getfile;
|
%mend ms_getfile;/**
|
||||||
|
@file
|
||||||
|
@brief Fetches the list of users from SASjs Server
|
||||||
|
@details Fetches the list of users from SASjs Server and writes them to an
|
||||||
|
output dataset.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
%ms_getusers(outds=userlist)
|
||||||
|
|
||||||
|
@param [in] mdebug= (0) Set to 1 to enable DEBUG messages
|
||||||
|
@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`|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<h4> SAS Macros </h4>
|
||||||
|
@li mf_getuniquefileref.sas
|
||||||
|
@li mf_getuniquelibref.sas
|
||||||
|
@li mp_abort.sas
|
||||||
|
|
||||||
|
<h4> Related Files </h4>
|
||||||
|
@li ms_createuser.sas
|
||||||
|
@li ms_getusers.test.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;
|
||||||
/**
|
/**
|
||||||
@file
|
@file
|
||||||
@brief Executes a SASjs Server Stored Program
|
@brief Executes a SASjs Server Stored Program
|
||||||
@@ -19133,10 +19416,10 @@ filename &binaryfref clear;
|
|||||||
)
|
)
|
||||||
|
|
||||||
data _null_;
|
data _null_;
|
||||||
file &fname1;
|
file &fname1 lrecl=1000;
|
||||||
infile "&_sasjs_tokenfile";
|
infile "&_sasjs_tokenfile" lrecl=1000;
|
||||||
input;
|
input;
|
||||||
put 'Authorization: Bearer' _infile_;
|
put 'Authorization: Bearer ' _infile_;
|
||||||
run;
|
run;
|
||||||
|
|
||||||
filename &outref temp;
|
filename &outref temp;
|
||||||
@@ -20457,19 +20740,23 @@ data _null_;
|
|||||||
put ' format _numeric_ bart.; ';
|
put ' format _numeric_ bart.; ';
|
||||||
put ' %do i=1 %to &numcols; ';
|
put ' %do i=1 %to &numcols; ';
|
||||||
put ' %if &&typelong&i=char or &fmt=Y %then %do; ';
|
put ' %if &&typelong&i=char or &fmt=Y %then %do; ';
|
||||||
put ' &&name&i=''"''!!trim(prxchange(''s/"/\"/'',-1, ';
|
put ' if findc(&&name&i,''"\''!!''0A0D09000E0F01021011''x) then do; ';
|
||||||
put ' prxchange(''s/''!!''0A''x!!''/\n/'',-1, ';
|
put ' &&name&i=''"''!!trim( ';
|
||||||
put ' prxchange(''s/''!!''0D''x!!''/\r/'',-1, ';
|
put ' prxchange(''s/"/\\"/'',-1, /* double quote */ ';
|
||||||
put ' prxchange(''s/''!!''09''x!!''/\t/'',-1, ';
|
put ' prxchange(''s/\x0A/\n/'',-1, /* new line */ ';
|
||||||
put ' prxchange(''s/\x00/\\u0000/'',-1, /* NUL */ ';
|
put ' prxchange(''s/\x0D/\r/'',-1, /* carriage return */ ';
|
||||||
put ' prxchange(''s/\x0E/\\u000E/'',-1, /* SS */ ';
|
put ' prxchange(''s/\x09/\\t/'',-1, /* tab */ ';
|
||||||
put ' prxchange(''s/\x0F/\\u000F/'',-1, /* SF */ ';
|
put ' prxchange(''s/\x00/\\u0000/'',-1, /* NUL */ ';
|
||||||
put ' prxchange(''s/\x01/\\u0001/'',-1, /* SOH */ ';
|
put ' prxchange(''s/\x0E/\\u000E/'',-1, /* SS */ ';
|
||||||
put ' prxchange(''s/\x02/\\u0002/'',-1, /* STX */ ';
|
put ' prxchange(''s/\x0F/\\u000F/'',-1, /* SF */ ';
|
||||||
put ' prxchange(''s/\x10/\\u0010/'',-1, /* DLE */ ';
|
put ' prxchange(''s/\x01/\\u0001/'',-1, /* SOH */ ';
|
||||||
put ' prxchange(''s/\x11/\\u0011/'',-1, /* DC1 */ ';
|
put ' prxchange(''s/\x02/\\u0002/'',-1, /* STX */ ';
|
||||||
put ' prxchange(''s/\\/\\\\/'',-1,&&name&i) ';
|
put ' prxchange(''s/\x10/\\u0010/'',-1, /* DLE */ ';
|
||||||
put ' ))))))))))))!!''"''; ';
|
put ' prxchange(''s/\x11/\\u0011/'',-1, /* DC1 */ ';
|
||||||
|
put ' prxchange(''s/\\/\\\\/'',-1,&&name&i) ';
|
||||||
|
put ' ))))))))))))!!''"''; ';
|
||||||
|
put ' end; ';
|
||||||
|
put ' else &&name&i=quote(cats(&&name&i)); ';
|
||||||
put ' %end; ';
|
put ' %end; ';
|
||||||
put ' %end; ';
|
put ' %end; ';
|
||||||
put ' run; ';
|
put ' run; ';
|
||||||
|
|||||||
@@ -199,19 +199,23 @@
|
|||||||
format _numeric_ bart.;
|
format _numeric_ bart.;
|
||||||
%do i=1 %to &numcols;
|
%do i=1 %to &numcols;
|
||||||
%if &&typelong&i=char or &fmt=Y %then %do;
|
%if &&typelong&i=char or &fmt=Y %then %do;
|
||||||
&&name&i='"'!!trim(prxchange('s/"/\"/',-1,
|
if findc(&&name&i,'"\'!!'0A0D09000E0F01021011'x) then do;
|
||||||
prxchange('s/'!!'0A'x!!'/\n/',-1,
|
&&name&i='"'!!trim(
|
||||||
prxchange('s/'!!'0D'x!!'/\r/',-1,
|
prxchange('s/"/\\"/',-1, /* double quote */
|
||||||
prxchange('s/'!!'09'x!!'/\t/',-1,
|
prxchange('s/\x0A/\n/',-1, /* new line */
|
||||||
prxchange('s/\x00/\\u0000/',-1, /* NUL */
|
prxchange('s/\x0D/\r/',-1, /* carriage return */
|
||||||
prxchange('s/\x0E/\\u000E/',-1, /* SS */
|
prxchange('s/\x09/\\t/',-1, /* tab */
|
||||||
prxchange('s/\x0F/\\u000F/',-1, /* SF */
|
prxchange('s/\x00/\\u0000/',-1, /* NUL */
|
||||||
prxchange('s/\x01/\\u0001/',-1, /* SOH */
|
prxchange('s/\x0E/\\u000E/',-1, /* SS */
|
||||||
prxchange('s/\x02/\\u0002/',-1, /* STX */
|
prxchange('s/\x0F/\\u000F/',-1, /* SF */
|
||||||
prxchange('s/\x10/\\u0010/',-1, /* DLE */
|
prxchange('s/\x01/\\u0001/',-1, /* SOH */
|
||||||
prxchange('s/\x11/\\u0011/',-1, /* DC1 */
|
prxchange('s/\x02/\\u0002/',-1, /* STX */
|
||||||
prxchange('s/\\/\\\\/',-1,&&name&i)
|
prxchange('s/\x10/\\u0010/',-1, /* DLE */
|
||||||
))))))))))))!!'"';
|
prxchange('s/\x11/\\u0011/',-1, /* DC1 */
|
||||||
|
prxchange('s/\\/\\\\/',-1,&&name&i)
|
||||||
|
))))))))))))!!'"';
|
||||||
|
end;
|
||||||
|
else &&name&i=quote(cats(&&name&i));
|
||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
run;
|
run;
|
||||||
|
|||||||
@@ -232,19 +232,23 @@ data _null_;
|
|||||||
put ' format _numeric_ bart.; ';
|
put ' format _numeric_ bart.; ';
|
||||||
put ' %do i=1 %to &numcols; ';
|
put ' %do i=1 %to &numcols; ';
|
||||||
put ' %if &&typelong&i=char or &fmt=Y %then %do; ';
|
put ' %if &&typelong&i=char or &fmt=Y %then %do; ';
|
||||||
put ' &&name&i=''"''!!trim(prxchange(''s/"/\"/'',-1, ';
|
put ' if findc(&&name&i,''"\''!!''0A0D09000E0F01021011''x) then do; ';
|
||||||
put ' prxchange(''s/''!!''0A''x!!''/\n/'',-1, ';
|
put ' &&name&i=''"''!!trim( ';
|
||||||
put ' prxchange(''s/''!!''0D''x!!''/\r/'',-1, ';
|
put ' prxchange(''s/"/\\"/'',-1, /* double quote */ ';
|
||||||
put ' prxchange(''s/''!!''09''x!!''/\t/'',-1, ';
|
put ' prxchange(''s/\x0A/\n/'',-1, /* new line */ ';
|
||||||
put ' prxchange(''s/\x00/\\u0000/'',-1, /* NUL */ ';
|
put ' prxchange(''s/\x0D/\r/'',-1, /* carriage return */ ';
|
||||||
put ' prxchange(''s/\x0E/\\u000E/'',-1, /* SS */ ';
|
put ' prxchange(''s/\x09/\\t/'',-1, /* tab */ ';
|
||||||
put ' prxchange(''s/\x0F/\\u000F/'',-1, /* SF */ ';
|
put ' prxchange(''s/\x00/\\u0000/'',-1, /* NUL */ ';
|
||||||
put ' prxchange(''s/\x01/\\u0001/'',-1, /* SOH */ ';
|
put ' prxchange(''s/\x0E/\\u000E/'',-1, /* SS */ ';
|
||||||
put ' prxchange(''s/\x02/\\u0002/'',-1, /* STX */ ';
|
put ' prxchange(''s/\x0F/\\u000F/'',-1, /* SF */ ';
|
||||||
put ' prxchange(''s/\x10/\\u0010/'',-1, /* DLE */ ';
|
put ' prxchange(''s/\x01/\\u0001/'',-1, /* SOH */ ';
|
||||||
put ' prxchange(''s/\x11/\\u0011/'',-1, /* DC1 */ ';
|
put ' prxchange(''s/\x02/\\u0002/'',-1, /* STX */ ';
|
||||||
put ' prxchange(''s/\\/\\\\/'',-1,&&name&i) ';
|
put ' prxchange(''s/\x10/\\u0010/'',-1, /* DLE */ ';
|
||||||
put ' ))))))))))))!!''"''; ';
|
put ' prxchange(''s/\x11/\\u0011/'',-1, /* DC1 */ ';
|
||||||
|
put ' prxchange(''s/\\/\\\\/'',-1,&&name&i) ';
|
||||||
|
put ' ))))))))))))!!''"''; ';
|
||||||
|
put ' end; ';
|
||||||
|
put ' else &&name&i=quote(cats(&&name&i)); ';
|
||||||
put ' %end; ';
|
put ' %end; ';
|
||||||
put ' %end; ';
|
put ' %end; ';
|
||||||
put ' run; ';
|
put ' run; ';
|
||||||
|
|||||||
3
package-lock.json
generated
3
package-lock.json
generated
@@ -6,9 +6,6 @@
|
|||||||
"": {
|
"": {
|
||||||
"name": "@sasjs/core",
|
"name": "@sasjs/core",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
|
||||||
"@sasjs/core": "^4.18.13"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sasjs/cli": "3.13.0"
|
"@sasjs/cli": "3.13.0"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "server",
|
"name": "server",
|
||||||
"serverUrl": "https://sas.analytium.co.uk:5000",
|
"serverUrl": "https://sas.analytium.co.uk:5006",
|
||||||
"serverType": "SASJS",
|
"serverType": "SASJS",
|
||||||
"httpsAgentOptions": {
|
"httpsAgentOptions": {
|
||||||
"allowInsecureRequests": false
|
"allowInsecureRequests": false
|
||||||
@@ -74,13 +74,7 @@
|
|||||||
"macroFolders": [
|
"macroFolders": [
|
||||||
"server",
|
"server",
|
||||||
"tests/serveronly"
|
"tests/serveronly"
|
||||||
],
|
]
|
||||||
"programFolders": [],
|
|
||||||
"binaryFolders": [],
|
|
||||||
"deployConfig": {
|
|
||||||
"deployServicePack": true,
|
|
||||||
"deployScripts": []
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "docsonly",
|
"name": "docsonly",
|
||||||
@@ -110,4 +104,4 @@
|
|||||||
"contextName": "SAS Job Execution compute context"
|
"contextName": "SAS Job Execution compute context"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -61,8 +61,11 @@ data _null_;
|
|||||||
run;
|
run;
|
||||||
|
|
||||||
data _null_;
|
data _null_;
|
||||||
file &fname1;
|
file &fname1 lrecl=1000;
|
||||||
|
infile "&_sasjs_tokenfile" lrecl=1000;
|
||||||
|
input;
|
||||||
put "Content-Type: multipart/form-data; boundary=&boundary";
|
put "Content-Type: multipart/form-data; boundary=&boundary";
|
||||||
|
put "Authorization: Bearer " _infile_;
|
||||||
run;
|
run;
|
||||||
|
|
||||||
%if &mdebug=1 %then %do;
|
%if &mdebug=1 %then %do;
|
||||||
|
|||||||
144
server/ms_createuser.sas
Normal file
144
server/ms_createuser.sas
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
/**
|
||||||
|
@file
|
||||||
|
@brief Creates a user on SASjs Server
|
||||||
|
@details Creates a user on SASjs Server with the following attributes:
|
||||||
|
|
||||||
|
@li UserName
|
||||||
|
@li Password
|
||||||
|
@li isAdmin
|
||||||
|
@li displayName
|
||||||
|
|
||||||
|
The userid is created by sasjs/server. All users are created with `isActive`
|
||||||
|
set to `true`.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
%ms_createuser(newuser,secretpass,displayname=New User!)
|
||||||
|
|
||||||
|
@param [in] username The username to apply. No spaces or special characters.
|
||||||
|
@param [in] password The initial password to set.
|
||||||
|
@param [in] isadmin= (false) Set to true to give the user admin rights
|
||||||
|
@param [in] displayName= (0) Set a friendly name (spaces & special characters
|
||||||
|
are ok). If not provided, username will be used instead.
|
||||||
|
@param [in] mdebug= (0) Set to 1 to enable DEBUG messages
|
||||||
|
@param [out] outds= (work.ms_createuser) This output dataset will contain the
|
||||||
|
values from the JSON response (such as the id of the new user)
|
||||||
|
|ID:best.|DISPLAYNAME:$8.|USERNAME:$8.|ISACTIVE:best.|ISADMIN:best.|
|
||||||
|
|---|---|---|---|---|
|
||||||
|
|`6 `|`New User `|`newuser `|`1 `|`0 `|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<h4> SAS Macros </h4>
|
||||||
|
@li mf_getuniquefileref.sas
|
||||||
|
@li mf_getuniquelibref.sas
|
||||||
|
@li mp_abort.sas
|
||||||
|
|
||||||
|
<h4> Related Files </h4>
|
||||||
|
@li ms_createuser.test.sas
|
||||||
|
@li ms_getusers.sas
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
%macro ms_createuser(username,password
|
||||||
|
,isadmin=false
|
||||||
|
,displayname=0
|
||||||
|
,outds=work.ms_createuser
|
||||||
|
,mdebug=0
|
||||||
|
);
|
||||||
|
|
||||||
|
%mp_abort(
|
||||||
|
iftrue=(&syscc ne 0)
|
||||||
|
,mac=ms_createuser.sas
|
||||||
|
,msg=%str(syscc=&syscc on macro entry)
|
||||||
|
)
|
||||||
|
|
||||||
|
%local fref0 fref1 fref2 libref optval rc msg;
|
||||||
|
%let fref0=%mf_getuniquefileref();
|
||||||
|
%let fref1=%mf_getuniquefileref();
|
||||||
|
%let fref2=%mf_getuniquefileref();
|
||||||
|
%let libref=%mf_getuniquelibref();
|
||||||
|
|
||||||
|
/* avoid sending bom marker to API */
|
||||||
|
%let optval=%sysfunc(getoption(bomfile));
|
||||||
|
options nobomfile;
|
||||||
|
|
||||||
|
data _null_;
|
||||||
|
file &fref0 termstr=crlf;
|
||||||
|
username=quote(cats(symget('username')));
|
||||||
|
password=quote(cats(symget('password')));
|
||||||
|
isadmin=symget('isadmin');
|
||||||
|
displayname=quote(cats(symget('displayname')));
|
||||||
|
if displayname='"0"' then displayname=username;
|
||||||
|
|
||||||
|
%if &mdebug=1 %then %do;
|
||||||
|
putlog _all_;
|
||||||
|
%end;
|
||||||
|
|
||||||
|
put '{'@;
|
||||||
|
put '"displayName":' displayname @;
|
||||||
|
put ',"username":' username @;
|
||||||
|
put ',"password":' password @;
|
||||||
|
put ',"isAdmin":' isadmin @;
|
||||||
|
put ',"isActive": true }';
|
||||||
|
run;
|
||||||
|
|
||||||
|
data _null_;
|
||||||
|
file &fref1 lrecl=1000;
|
||||||
|
infile "&_sasjs_tokenfile" lrecl=1000;
|
||||||
|
input;
|
||||||
|
put "Authorization: Bearer " _infile_;
|
||||||
|
put "Content-Type: application/json";
|
||||||
|
put "accept: application/json";
|
||||||
|
run;
|
||||||
|
|
||||||
|
%if &mdebug=1 %then %do;
|
||||||
|
data _null_;
|
||||||
|
infile &fref0;
|
||||||
|
input;
|
||||||
|
put _infile_;
|
||||||
|
data _null_;
|
||||||
|
infile &fref1;
|
||||||
|
input;
|
||||||
|
put _infile_;
|
||||||
|
run;
|
||||||
|
%end;
|
||||||
|
|
||||||
|
proc http method='POST' in=&fref0 headerin=&fref1 out=&fref2
|
||||||
|
url="&_sasjs_apiserverurl/SASjsApi/user";
|
||||||
|
%if &mdebug=1 %then %do;
|
||||||
|
debug level=1;
|
||||||
|
%end;
|
||||||
|
run;
|
||||||
|
|
||||||
|
%mp_abort(
|
||||||
|
iftrue=(&syscc ne 0)
|
||||||
|
,mac=ms_createuser.sas
|
||||||
|
,msg=%str(Issue submitting query to SASjsApi/user)
|
||||||
|
)
|
||||||
|
|
||||||
|
libname &libref JSON fileref=&fref2;
|
||||||
|
|
||||||
|
data &outds;
|
||||||
|
set &libref..root;
|
||||||
|
drop ordinal_root;
|
||||||
|
run;
|
||||||
|
|
||||||
|
|
||||||
|
%mp_abort(
|
||||||
|
iftrue=(&syscc ne 0)
|
||||||
|
,mac=ms_createuser.sas
|
||||||
|
,msg=%str(Issue reading response JSON)
|
||||||
|
)
|
||||||
|
|
||||||
|
/* reset options */
|
||||||
|
options &optval;
|
||||||
|
|
||||||
|
%if &mdebug=1 %then %do;
|
||||||
|
filename &fref0 clear;
|
||||||
|
filename &fref1 clear;
|
||||||
|
filename &fref2 clear;
|
||||||
|
libname &libref clear;
|
||||||
|
%end;
|
||||||
|
|
||||||
|
%mend ms_createuser;
|
||||||
@@ -17,6 +17,8 @@
|
|||||||
@param [in] driveloc The full path to the file in SASjs Drive
|
@param [in] driveloc The full path to the file in SASjs Drive
|
||||||
@param [in] mdebug= (0) Set to 1 to enable DEBUG messages
|
@param [in] mdebug= (0) Set to 1 to enable DEBUG messages
|
||||||
|
|
||||||
|
<h4> SAS Macros </h4>
|
||||||
|
@li mf_getuniquefileref.sas
|
||||||
|
|
||||||
**/
|
**/
|
||||||
|
|
||||||
@@ -24,12 +26,23 @@
|
|||||||
,mdebug=0
|
,mdebug=0
|
||||||
);
|
);
|
||||||
|
|
||||||
proc http method='DELETE'
|
%local headref;
|
||||||
|
%let headref=%mf_getuniquefileref();
|
||||||
|
|
||||||
|
data _null_;
|
||||||
|
file &headref lrecl=1000;
|
||||||
|
infile "&_sasjs_tokenfile" lrecl=1000;
|
||||||
|
input;
|
||||||
|
put "Authorization: Bearer " _infile_;
|
||||||
|
run;
|
||||||
|
|
||||||
|
proc http method='DELETE' headerin=&headref
|
||||||
url="&_sasjs_apiserverurl/SASjsApi/drive/file?_filePath=&driveloc";
|
url="&_sasjs_apiserverurl/SASjsApi/drive/file?_filePath=&driveloc";
|
||||||
%if &mdebug=1 %then %do;
|
%if &mdebug=1 %then %do;
|
||||||
debug level=2;
|
debug level=2;
|
||||||
%end;
|
%end;
|
||||||
run;
|
run;
|
||||||
|
|
||||||
|
filename &headref clear;
|
||||||
|
|
||||||
%mend ms_deletefile;
|
%mend ms_deletefile;
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
Example:
|
Example:
|
||||||
|
|
||||||
%ms_getfile(/some/stored/file.ext, outref=myfile)
|
%ms_getfile(/Public/app/dc/services/public/settings.sas, outref=myfile)
|
||||||
|
|
||||||
@param [in] driveloc The full path to the file in SASjs Drive
|
@param [in] driveloc The full path to the file in SASjs Drive
|
||||||
@param [out] outref= (msgetfil) The fileref to contain the file.
|
@param [out] outref= (msgetfil) The fileref to contain the file.
|
||||||
@@ -23,13 +23,21 @@
|
|||||||
);
|
);
|
||||||
|
|
||||||
/* use the recfm in a separate fileref to avoid issues with subsequent reads */
|
/* use the recfm in a separate fileref to avoid issues with subsequent reads */
|
||||||
%local binaryfref floc;
|
%local binaryfref floc headref;
|
||||||
%let binaryfref=%mf_getuniquefileref();
|
%let binaryfref=%mf_getuniquefileref();
|
||||||
|
%let headref=%mf_getuniquefileref();
|
||||||
%let floc=%sysfunc(pathname(work))/%mf_getuniquename().txt;
|
%let floc=%sysfunc(pathname(work))/%mf_getuniquename().txt;
|
||||||
filename &outref "&floc";
|
filename &outref "&floc" lrecl=32767;
|
||||||
filename &binaryfref "&floc" recfm=n;
|
filename &binaryfref "&floc" recfm=n;
|
||||||
|
|
||||||
proc http method='GET' out=&binaryfref
|
data _null_;
|
||||||
|
file &headref lrecl=1000;
|
||||||
|
infile "&_sasjs_tokenfile" lrecl=1000;
|
||||||
|
input;
|
||||||
|
put "Authorization: Bearer " _infile_;
|
||||||
|
run;
|
||||||
|
|
||||||
|
proc http method='GET' out=&binaryfref headerin=&headref
|
||||||
url="&_sasjs_apiserverurl/SASjsApi/drive/file?_filePath=&driveloc";
|
url="&_sasjs_apiserverurl/SASjsApi/drive/file?_filePath=&driveloc";
|
||||||
%if &mdebug=1 %then %do;
|
%if &mdebug=1 %then %do;
|
||||||
debug level=2;
|
debug level=2;
|
||||||
@@ -37,5 +45,6 @@ proc http method='GET' out=&binaryfref
|
|||||||
run;
|
run;
|
||||||
|
|
||||||
filename &binaryfref clear;
|
filename &binaryfref clear;
|
||||||
|
filename &headref clear;
|
||||||
|
|
||||||
%mend ms_getfile;
|
%mend ms_getfile;
|
||||||
107
server/ms_getusers.sas
Normal file
107
server/ms_getusers.sas
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
/**
|
||||||
|
@file
|
||||||
|
@brief Fetches the list of users from SASjs Server
|
||||||
|
@details Fetches the list of users from SASjs Server and writes them to an
|
||||||
|
output dataset.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
%ms_getusers(outds=userlist)
|
||||||
|
|
||||||
|
@param [in] mdebug= (0) Set to 1 to enable DEBUG messages
|
||||||
|
@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`|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<h4> SAS Macros </h4>
|
||||||
|
@li mf_getuniquefileref.sas
|
||||||
|
@li mf_getuniquelibref.sas
|
||||||
|
@li mp_abort.sas
|
||||||
|
|
||||||
|
<h4> Related Files </h4>
|
||||||
|
@li ms_createuser.sas
|
||||||
|
@li ms_getusers.test.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;
|
||||||
@@ -43,10 +43,10 @@
|
|||||||
)
|
)
|
||||||
|
|
||||||
data _null_;
|
data _null_;
|
||||||
file &fname1;
|
file &fname1 lrecl=1000;
|
||||||
infile "&_sasjs_tokenfile";
|
infile "&_sasjs_tokenfile" lrecl=1000;
|
||||||
input;
|
input;
|
||||||
put 'Authorization: Bearer' _infile_;
|
put 'Authorization: Bearer ' _infile_;
|
||||||
run;
|
run;
|
||||||
|
|
||||||
filename &outref temp;
|
filename &outref temp;
|
||||||
|
|||||||
53
tests/crossplatform/mp_jsonout.test.3.sas
Normal file
53
tests/crossplatform/mp_jsonout.test.3.sas
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
/**
|
||||||
|
@file
|
||||||
|
@brief Testing mp_jsonout.sas macro with non-standard chars
|
||||||
|
|
||||||
|
<h4> SAS Macros </h4>
|
||||||
|
@li mp_jsonout.sas
|
||||||
|
@li mp_assert.sas
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
filename webref temp;
|
||||||
|
|
||||||
|
data demo;
|
||||||
|
do x='"','0A'x,'0D'x,'09'x,'00'x,'0E'x,'0F'x,'01'x,'02'x,'10'x,'11'x,'\';
|
||||||
|
output;
|
||||||
|
end;
|
||||||
|
run;
|
||||||
|
%mp_jsonout(OPEN,jref=webref)
|
||||||
|
%mp_jsonout(OBJ,demo,jref=webref)
|
||||||
|
%mp_jsonout(CLOSE,jref=webref)
|
||||||
|
|
||||||
|
data _null_;
|
||||||
|
infile webref;
|
||||||
|
input;
|
||||||
|
putlog _infile_;
|
||||||
|
run;
|
||||||
|
|
||||||
|
libname web JSON fileref=webref;
|
||||||
|
|
||||||
|
%mp_assert(
|
||||||
|
iftrue=(&syscc=0),
|
||||||
|
desc=Checking for error condition with special chars export,
|
||||||
|
outds=work.test_results
|
||||||
|
)
|
||||||
|
|
||||||
|
/*
|
||||||
|
data _null_;
|
||||||
|
set work.demo (in=start) web.demo (in=end);
|
||||||
|
put (_all_)(=);
|
||||||
|
run;
|
||||||
|
proc sql;
|
||||||
|
describe table work.demo;
|
||||||
|
describe table web.demo;
|
||||||
|
*/
|
||||||
|
|
||||||
|
proc compare base=work.demo compare=web.demo(keep=x);
|
||||||
|
quit;
|
||||||
|
|
||||||
|
%mp_assert(
|
||||||
|
iftrue=(&sysinfo=0),
|
||||||
|
desc=Returned json is identical to input table for all special chars,
|
||||||
|
outds=work.test_results
|
||||||
|
)
|
||||||
50
tests/serveronly/ms_createuser.test.sas
Normal file
50
tests/serveronly/ms_createuser.test.sas
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
/**
|
||||||
|
@file
|
||||||
|
@brief Testing ms_createuser.sas macro
|
||||||
|
|
||||||
|
<h4> SAS Macros </h4>
|
||||||
|
@li mf_getuniquename.sas
|
||||||
|
@li mp_assert.sas
|
||||||
|
@li mp_assertscope.sas
|
||||||
|
@li ms_createuser.sas
|
||||||
|
@li ms_getusers.sas
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
%let user=%substr(%mf_getuniquename(),1,8);
|
||||||
|
|
||||||
|
%mp_assertscope(SNAPSHOT)
|
||||||
|
%ms_createuser(&user,passwrd,outds=test1,mdebug=&sasjs_mdebug)
|
||||||
|
%mp_assertscope(COMPARE
|
||||||
|
,ignorelist=MCLIB0_JADP1LEN MCLIB0_JADPNUM MCLIB0_JADVLEN
|
||||||
|
)
|
||||||
|
|
||||||
|
%let id=0;
|
||||||
|
data _null_;
|
||||||
|
set work.test1;
|
||||||
|
call symputx('id',id);
|
||||||
|
run;
|
||||||
|
%mp_assert(
|
||||||
|
iftrue=(&id>0),
|
||||||
|
desc=Checking that user was created with an ID,
|
||||||
|
outds=work.test_results
|
||||||
|
)
|
||||||
|
|
||||||
|
/* double check by querying the list of users */
|
||||||
|
%ms_getusers(outds=work.test2)
|
||||||
|
%let checkid=0;
|
||||||
|
data _null_;
|
||||||
|
set work.test2;
|
||||||
|
where username="&user";
|
||||||
|
call symputx('checkid',id);
|
||||||
|
run;
|
||||||
|
%mp_assert(
|
||||||
|
iftrue=(&checkid=&id),
|
||||||
|
desc=Checking that fetched user exists and has the same ID,
|
||||||
|
outds=work.test_results
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ data _null_;
|
|||||||
run;
|
run;
|
||||||
|
|
||||||
%mp_assert(
|
%mp_assert(
|
||||||
iftrue=("&test2"="%str(Err)or: File does not exist."),
|
iftrue=("&test2"="%str(Err)or: File doesn't exist."),
|
||||||
desc=Make sure the file was deleted,
|
desc=Make sure the file was deleted,
|
||||||
outds=work.test_results
|
outds=work.test_results
|
||||||
)
|
)
|
||||||
|
|||||||
23
tests/serveronly/ms_getusers.test.sas
Normal file
23
tests/serveronly/ms_getusers.test.sas
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/**
|
||||||
|
@file
|
||||||
|
@brief Testing ms_getusers.sas macro
|
||||||
|
|
||||||
|
<h4> SAS Macros </h4>
|
||||||
|
@li ms_getusers.sas
|
||||||
|
@li mp_assertdsobs.sas
|
||||||
|
@li mp_assertscope.sas
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
%mp_assertscope(SNAPSHOT)
|
||||||
|
%ms_getusers(outds=work.test1,mdebug=&sasjs_mdebug)
|
||||||
|
%mp_assertscope(COMPARE
|
||||||
|
,ignorelist=MCLIB0_JADP1LEN MCLIB0_JADPNUM MCLIB0_JADVLEN
|
||||||
|
)
|
||||||
|
|
||||||
|
%mp_assertdsobs(work.test1,test=ATLEAST 1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -3,14 +3,31 @@
|
|||||||
@brief Testing ms_runstp.sas macro
|
@brief Testing ms_runstp.sas macro
|
||||||
|
|
||||||
<h4> SAS Macros </h4>
|
<h4> SAS Macros </h4>
|
||||||
@li ms_runstp.sas
|
@li mf_getuniquename.sas
|
||||||
@li mp_assert.sas
|
@li mp_assert.sas
|
||||||
@li mp_assertscope.sas
|
@li mp_assertscope.sas
|
||||||
|
@li ms_createfile.sas
|
||||||
|
@li ms_runstp.sas
|
||||||
|
|
||||||
**/
|
**/
|
||||||
|
|
||||||
|
/* first, create an STP to run */
|
||||||
|
filename stpcode temp;
|
||||||
|
data _null_;
|
||||||
|
file stpcode;
|
||||||
|
put '%put hello world;';
|
||||||
|
run;
|
||||||
|
|
||||||
|
options mprint;
|
||||||
|
%let fname=%mf_getuniquename();
|
||||||
|
|
||||||
|
%ms_createfile(/sasjs/tests/&fname..sas
|
||||||
|
,inref=stpcode
|
||||||
|
,mdebug=1
|
||||||
|
)
|
||||||
|
|
||||||
%mp_assertscope(SNAPSHOT)
|
%mp_assertscope(SNAPSHOT)
|
||||||
%ms_runstp(/Public/app/frs/allan/services/common/appinit
|
%ms_runstp(/sasjs/tests/&fname
|
||||||
,debug=131
|
,debug=131
|
||||||
,outref=weboot
|
,outref=weboot
|
||||||
)
|
)
|
||||||
@@ -24,20 +41,16 @@ data _null_;
|
|||||||
putlog _infile_;
|
putlog _infile_;
|
||||||
run;
|
run;
|
||||||
|
|
||||||
data work.httpheaders;
|
%let test1=0;
|
||||||
set webeen.httpheaders;
|
|
||||||
call symputx('test1',content_type);
|
|
||||||
run;
|
|
||||||
|
|
||||||
data work.log;
|
data work.log;
|
||||||
set webeen.log;
|
set webeen.log;
|
||||||
put (_all_)(=);
|
put (_all_)(=);
|
||||||
if _n_>10 then stop;
|
if _n_>10 then call symputx('test1',1);
|
||||||
run;
|
run;
|
||||||
|
|
||||||
%mp_assert(
|
%mp_assert(
|
||||||
iftrue=("&test1"="application/json"),
|
iftrue=("&test1"="1"),
|
||||||
desc=Checking line was created,
|
desc=Checking log was returned,
|
||||||
outds=work.test_results
|
outds=work.test_results
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -14,16 +14,19 @@
|
|||||||
/* set defaults */
|
/* set defaults */
|
||||||
%mp_init()
|
%mp_init()
|
||||||
|
|
||||||
%global _debug;
|
%global _debug sasjs_mdebug;
|
||||||
|
|
||||||
|
%let sasjs_mdebug=0;
|
||||||
|
|
||||||
%macro loglevel();
|
%macro loglevel();
|
||||||
%if "&_debug"="2477" or "&_debug"="fields,log,trace" %then %do;
|
%if "&_debug"="2477" or "&_debug"="fields,log,trace" %then %do;
|
||||||
%put debug mode activated;
|
%put debug mode activated;
|
||||||
options mprint mprintnest;
|
options mprint mprintnest;
|
||||||
|
%let sasjs_mdebug=1;
|
||||||
%end;
|
%end;
|
||||||
%mend loglevel;
|
%mend loglevel;
|
||||||
|
|
||||||
%loglevel()
|
%loglevel()
|
||||||
|
|
||||||
%put Initialised &_program;
|
%put Initialised &_program;
|
||||||
%put _all_;
|
%put _all_;
|
||||||
|
|||||||
@@ -376,19 +376,23 @@ data _null_;
|
|||||||
put ' format _numeric_ bart.; ';
|
put ' format _numeric_ bart.; ';
|
||||||
put ' %do i=1 %to &numcols; ';
|
put ' %do i=1 %to &numcols; ';
|
||||||
put ' %if &&typelong&i=char or &fmt=Y %then %do; ';
|
put ' %if &&typelong&i=char or &fmt=Y %then %do; ';
|
||||||
put ' &&name&i=''"''!!trim(prxchange(''s/"/\"/'',-1, ';
|
put ' if findc(&&name&i,''"\''!!''0A0D09000E0F01021011''x) then do; ';
|
||||||
put ' prxchange(''s/''!!''0A''x!!''/\n/'',-1, ';
|
put ' &&name&i=''"''!!trim( ';
|
||||||
put ' prxchange(''s/''!!''0D''x!!''/\r/'',-1, ';
|
put ' prxchange(''s/"/\\"/'',-1, /* double quote */ ';
|
||||||
put ' prxchange(''s/''!!''09''x!!''/\t/'',-1, ';
|
put ' prxchange(''s/\x0A/\n/'',-1, /* new line */ ';
|
||||||
put ' prxchange(''s/\x00/\\u0000/'',-1, /* NUL */ ';
|
put ' prxchange(''s/\x0D/\r/'',-1, /* carriage return */ ';
|
||||||
put ' prxchange(''s/\x0E/\\u000E/'',-1, /* SS */ ';
|
put ' prxchange(''s/\x09/\\t/'',-1, /* tab */ ';
|
||||||
put ' prxchange(''s/\x0F/\\u000F/'',-1, /* SF */ ';
|
put ' prxchange(''s/\x00/\\u0000/'',-1, /* NUL */ ';
|
||||||
put ' prxchange(''s/\x01/\\u0001/'',-1, /* SOH */ ';
|
put ' prxchange(''s/\x0E/\\u000E/'',-1, /* SS */ ';
|
||||||
put ' prxchange(''s/\x02/\\u0002/'',-1, /* STX */ ';
|
put ' prxchange(''s/\x0F/\\u000F/'',-1, /* SF */ ';
|
||||||
put ' prxchange(''s/\x10/\\u0010/'',-1, /* DLE */ ';
|
put ' prxchange(''s/\x01/\\u0001/'',-1, /* SOH */ ';
|
||||||
put ' prxchange(''s/\x11/\\u0011/'',-1, /* DC1 */ ';
|
put ' prxchange(''s/\x02/\\u0002/'',-1, /* STX */ ';
|
||||||
put ' prxchange(''s/\\/\\\\/'',-1,&&name&i) ';
|
put ' prxchange(''s/\x10/\\u0010/'',-1, /* DLE */ ';
|
||||||
put ' ))))))))))))!!''"''; ';
|
put ' prxchange(''s/\x11/\\u0011/'',-1, /* DC1 */ ';
|
||||||
|
put ' prxchange(''s/\\/\\\\/'',-1,&&name&i) ';
|
||||||
|
put ' ))))))))))))!!''"''; ';
|
||||||
|
put ' end; ';
|
||||||
|
put ' else &&name&i=quote(cats(&&name&i)); ';
|
||||||
put ' %end; ';
|
put ' %end; ';
|
||||||
put ' %end; ';
|
put ' %end; ';
|
||||||
put ' run; ';
|
put ' run; ';
|
||||||
|
|||||||
Reference in New Issue
Block a user