@sasjs/core 4.18.17 → 4.20.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/base/mf_getuniquefileref.sas +5 -3
- package/base/mf_isint.sas +4 -1
- package/base/mp_chop.sas +194 -0
- package/base/mp_createwebservice.sas +13 -2
- package/base/mp_gsubfile.sas +1 -1
- package/base/mp_jsonout.sas +1 -1
- package/base/mp_replace.sas +4 -2
- package/base/mp_testservice.sas +24 -3
- package/lua/ml_gsubfile.sas +8 -0
- package/lua/ml_json.sas +8 -0
- package/meta/mm_createwebservice.sas +20 -20
- package/package.json +1 -1
- package/server/mfs_httpheader.sas +2 -1
- package/server/ms_createfile.sas +12 -5
- package/server/ms_createuser.sas +144 -0
- package/server/ms_createwebservice.sas +532 -0
- package/server/ms_deletefile.sas +14 -1
- package/server/ms_getfile.sas +14 -5
- package/server/ms_getusers.sas +107 -0
- package/server/ms_runstp.sas +130 -9
- package/server/ms_testservice.sas +152 -0
- package/server/ms_webout.sas +9 -8
- package/viya/mv_createwebservice.sas +20 -20
|
@@ -28,15 +28,17 @@
|
|
|
28
28
|
be 8 characters, so a 7 letter prefix would mean `maxtries` should be 10.
|
|
29
29
|
if using zero (0) as the prefix, a native assignment is used.
|
|
30
30
|
@param [in] maxtries= (1000) the last part of the libref. Must be an integer.
|
|
31
|
+
@param [in] lrecl= (32767) Provide a default lrecl with which to initialise
|
|
32
|
+
the generated fileref.
|
|
31
33
|
|
|
32
34
|
@version 9.2
|
|
33
35
|
@author Allan Bowe
|
|
34
36
|
**/
|
|
35
37
|
|
|
36
|
-
%macro mf_getuniquefileref(prefix=_,maxtries=1000);
|
|
38
|
+
%macro mf_getuniquefileref(prefix=_,maxtries=1000,lrecl=32767);
|
|
37
39
|
%local rc fname;
|
|
38
40
|
%if &prefix=0 %then %do;
|
|
39
|
-
%let rc=%sysfunc(filename(fname,,temp));
|
|
41
|
+
%let rc=%sysfunc(filename(fname,,temp,lrecl=&lrecl));
|
|
40
42
|
%if &rc %then %put %sysfunc(sysmsg());
|
|
41
43
|
&fname
|
|
42
44
|
%end;
|
|
@@ -47,7 +49,7 @@
|
|
|
47
49
|
%do x=0 %to &maxtries;
|
|
48
50
|
%let fname=&prefix%substr(%sysfunc(ranuni(0)),3,&len);
|
|
49
51
|
%if %sysfunc(fileref(&fname)) > 0 %then %do;
|
|
50
|
-
%let rc=%sysfunc(filename(fname,,temp));
|
|
52
|
+
%let rc=%sysfunc(filename(fname,,temp,lrecl=&lrecl));
|
|
51
53
|
%if &rc %then %put %sysfunc(sysmsg());
|
|
52
54
|
&fname
|
|
53
55
|
%return;
|
package/base/mf_isint.sas
CHANGED
|
@@ -20,8 +20,11 @@
|
|
|
20
20
|
|
|
21
21
|
%macro mf_isint(arg
|
|
22
22
|
)/*/STORE SOURCE*/;
|
|
23
|
-
/* remove minus sign if exists */
|
|
24
23
|
|
|
24
|
+
/* blank val is not an integer */
|
|
25
|
+
%if "&arg"="" %then %do;0%return;%end;
|
|
26
|
+
|
|
27
|
+
/* remove minus sign if exists */
|
|
25
28
|
%local val;
|
|
26
29
|
%if "%substr(%str(&arg),1,1)"="-" %then %let val=%substr(%str(&arg),2);
|
|
27
30
|
%else %let val=&arg;
|
package/base/mp_chop.sas
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file
|
|
3
|
+
@brief Splits a file of ANY SIZE by reference to a search string.
|
|
4
|
+
@details Provide a fileref and a search string to chop off part of a file.
|
|
5
|
+
|
|
6
|
+
Works by reading in the file byte by byte, then marking the beginning and end
|
|
7
|
+
of each matched string, before finally doing the chop.
|
|
8
|
+
|
|
9
|
+
Choose whether to keep the FIRST or the LAST section of the file. Optionally,
|
|
10
|
+
use an OFFSET to fix the precise chop point.
|
|
11
|
+
|
|
12
|
+
Usage:
|
|
13
|
+
|
|
14
|
+
%let src="%sysfunc(pathname(work))/file.txt";
|
|
15
|
+
%let str=Chop here!;
|
|
16
|
+
%let out1="%sysfunc(pathname(work))/file1.txt";
|
|
17
|
+
%let out2="%sysfunc(pathname(work))/file2.txt";
|
|
18
|
+
%let out3="%sysfunc(pathname(work))/file3.txt";
|
|
19
|
+
%let out4="%sysfunc(pathname(work))/file4.txt";
|
|
20
|
+
|
|
21
|
+
data _null_;
|
|
22
|
+
file &src;
|
|
23
|
+
put "startsection&str.endsection";
|
|
24
|
+
run;
|
|
25
|
+
|
|
26
|
+
%mp_chop(&src, matchvar=str, keep=FIRST, outfile=&out1)
|
|
27
|
+
%mp_chop(&src, matchvar=str, keep=LAST, outfile=&out2)
|
|
28
|
+
%mp_chop(&src, matchvar=str, keep=FIRST, matchpoint=END, outfile=&out3)
|
|
29
|
+
%mp_chop(&src, matchvar=str, keep=LAST, matchpoint=END, outfile=&out4)
|
|
30
|
+
|
|
31
|
+
filename results (&out1 &out2 &out3 &out4);
|
|
32
|
+
data _null_;
|
|
33
|
+
infile results;
|
|
34
|
+
input;
|
|
35
|
+
list;
|
|
36
|
+
run;
|
|
37
|
+
|
|
38
|
+
Results:
|
|
39
|
+
@li `startsection`
|
|
40
|
+
@li `Chop here!endsection`
|
|
41
|
+
@li `startsectionChop here!`
|
|
42
|
+
@li `endsection`
|
|
43
|
+
|
|
44
|
+
For more examples, see mp_chop.test.sas
|
|
45
|
+
|
|
46
|
+
@param [in] infile The QUOTED path to the file on which to perform the chop
|
|
47
|
+
@param [in] matchvar= Macro variable NAME containing the string to split by
|
|
48
|
+
@param [in] matchpoint= (START) Valid values:
|
|
49
|
+
@li START - chop at the beginning of the string in `matchvar`.
|
|
50
|
+
@li END - chop at the end of the string in `matchvar`.
|
|
51
|
+
@param [in] offset= (0) An adjustment to the precise chop location, by
|
|
52
|
+
by reference to the `matchpoint`. Should be a positive or negative integer.
|
|
53
|
+
@param [in] keep= (FIRST) Valid values:
|
|
54
|
+
@li FIRST - keep the section of the file before the chop
|
|
55
|
+
@li LAST - keep the section of the file after the chop
|
|
56
|
+
@param [in] mdebug= (0) Set to 1 to provide macro debugging
|
|
57
|
+
@param outfile= (0) Optional QUOTED path to the adjusted output file (avoids
|
|
58
|
+
overwriting the first file).
|
|
59
|
+
|
|
60
|
+
<h4> SAS Macros </h4>
|
|
61
|
+
@li mf_getuniquefileref.sas
|
|
62
|
+
@li mf_getuniquename.sas
|
|
63
|
+
|
|
64
|
+
<h4> Related Macros </h4>
|
|
65
|
+
@li mp_abort.sas
|
|
66
|
+
@li mp_gsubfile.sas
|
|
67
|
+
@li mp_replace.sas
|
|
68
|
+
@li mp_chop.test.sas
|
|
69
|
+
|
|
70
|
+
@version 9.4
|
|
71
|
+
@author Allan Bowe
|
|
72
|
+
|
|
73
|
+
**/
|
|
74
|
+
|
|
75
|
+
%macro mp_chop(infile,
|
|
76
|
+
matchvar=,
|
|
77
|
+
matchpoint=START,
|
|
78
|
+
keep=FIRST,
|
|
79
|
+
offset=0,
|
|
80
|
+
mdebug=0,
|
|
81
|
+
outfile=0
|
|
82
|
+
)/*/STORE SOURCE*/;
|
|
83
|
+
|
|
84
|
+
%local fref0 dttm ds1 outref;
|
|
85
|
+
%let fref0=%mf_getuniquefileref();
|
|
86
|
+
%let ds1=%mf_getuniquename(prefix=allchars);
|
|
87
|
+
%let ds2=%mf_getuniquename(prefix=startmark);
|
|
88
|
+
|
|
89
|
+
%if &outfile=0 %then %let outfile=&infile;
|
|
90
|
+
|
|
91
|
+
%mp_abort(iftrue= (%length(%superq(&matchvar))=0)
|
|
92
|
+
,mac=mp_chop.sas
|
|
93
|
+
,msg=%str(&matchvar is an empty variable)
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
/* START */
|
|
97
|
+
%let dttm=%sysfunc(datetime());
|
|
98
|
+
|
|
99
|
+
filename &fref0 &infile lrecl=1 recfm=n;
|
|
100
|
+
|
|
101
|
+
/* create dataset with one char per row */
|
|
102
|
+
data &ds1;
|
|
103
|
+
infile &fref0;
|
|
104
|
+
input sourcechar $char1. @@;
|
|
105
|
+
format sourcechar hex2.;
|
|
106
|
+
run;
|
|
107
|
+
|
|
108
|
+
/* get start & stop position of first matchvar string (one row, two vars) */
|
|
109
|
+
data &ds2;
|
|
110
|
+
/* set find string to length in bytes to cover trailing spaces */
|
|
111
|
+
length string $ %length(%superq(&matchvar));
|
|
112
|
+
string =symget("&matchvar");
|
|
113
|
+
drop string;
|
|
114
|
+
|
|
115
|
+
firstchar=char(string,1);
|
|
116
|
+
findlen=lengthm(string); /* <- for trailing bytes */
|
|
117
|
+
|
|
118
|
+
do _N_=1 to nobs;
|
|
119
|
+
set &ds1 nobs=nobs point=_N_;
|
|
120
|
+
if sourcechar=firstchar then do;
|
|
121
|
+
pos=1;
|
|
122
|
+
s=0;
|
|
123
|
+
do point=_N_ to min(_N_ + findlen -1,nobs);
|
|
124
|
+
set &ds1 point=point;
|
|
125
|
+
if sourcechar=char(string, pos) then s + 1;
|
|
126
|
+
else goto _leave_;
|
|
127
|
+
pos+1;
|
|
128
|
+
end;
|
|
129
|
+
_leave_:
|
|
130
|
+
if s=findlen then do;
|
|
131
|
+
START =_N_;
|
|
132
|
+
_N_ =_N_+ s - 1;
|
|
133
|
+
STOP =_N_;
|
|
134
|
+
output;
|
|
135
|
+
/* matched! */
|
|
136
|
+
stop;
|
|
137
|
+
end;
|
|
138
|
+
end;
|
|
139
|
+
end;
|
|
140
|
+
stop;
|
|
141
|
+
keep START STOP;
|
|
142
|
+
run;
|
|
143
|
+
|
|
144
|
+
%local split;
|
|
145
|
+
%let split=0;
|
|
146
|
+
data _null_;
|
|
147
|
+
set &ds2;
|
|
148
|
+
if "&matchpoint"='START' then do;
|
|
149
|
+
if "&keep"='FIRST' then mp=start;
|
|
150
|
+
else if "&keep"='LAST' then mp=start-1;
|
|
151
|
+
end;
|
|
152
|
+
else if "&matchpoint"='END' then do;
|
|
153
|
+
if "&keep"='FIRST' then mp=stop+1;
|
|
154
|
+
else if "&keep"='LAST' then mp=stop;
|
|
155
|
+
end;
|
|
156
|
+
split=mp+&offset;
|
|
157
|
+
call symputx('split',split,'l');
|
|
158
|
+
%if &mdebug=1 %then %do;
|
|
159
|
+
put (_all_)(=);
|
|
160
|
+
%put &=offset;
|
|
161
|
+
%end;
|
|
162
|
+
run;
|
|
163
|
+
%if &split=0 %then %do;
|
|
164
|
+
%put &sysmacroname: No match found in &infile for string %superq(&matchvar);
|
|
165
|
+
%return;
|
|
166
|
+
%end;
|
|
167
|
+
|
|
168
|
+
data _null_;
|
|
169
|
+
file &outfile recfm=n;
|
|
170
|
+
set &ds1;
|
|
171
|
+
%if &keep=FIRST %then %do;
|
|
172
|
+
if _n_ ge &split then stop;
|
|
173
|
+
%end;
|
|
174
|
+
%else %do;
|
|
175
|
+
if _n_ gt &split;
|
|
176
|
+
%end;
|
|
177
|
+
put sourcechar char1.;
|
|
178
|
+
run;
|
|
179
|
+
|
|
180
|
+
%if &mdebug=0 %then %do;
|
|
181
|
+
filename &fref0 clear;
|
|
182
|
+
%end;
|
|
183
|
+
%else %do;
|
|
184
|
+
data _null_;
|
|
185
|
+
infile &outfile lrecl=32767;
|
|
186
|
+
input;
|
|
187
|
+
list;
|
|
188
|
+
if _n_>50 then stop;
|
|
189
|
+
run;
|
|
190
|
+
%end;
|
|
191
|
+
/* END */
|
|
192
|
+
%put &sysmacroname took %sysevalf(%sysfunc(datetime())-&dttm) seconds to run;
|
|
193
|
+
|
|
194
|
+
%mend mp_chop;
|
|
@@ -29,6 +29,7 @@ Usage:
|
|
|
29
29
|
<h4> SAS Macros </h4>
|
|
30
30
|
@li mf_getplatform.sas
|
|
31
31
|
@li mm_createwebservice.sas
|
|
32
|
+
@li ms_createwebservice.sas
|
|
32
33
|
@li mv_createwebservice.sas
|
|
33
34
|
|
|
34
35
|
@param [in,out] path= The full folder path where the service will be created
|
|
@@ -40,7 +41,7 @@ Usage:
|
|
|
40
41
|
be added
|
|
41
42
|
@param [in] replace= (YES) Select YES to replace any existing service in that
|
|
42
43
|
location
|
|
43
|
-
|
|
44
|
+
@param [in] mDebug= (0) set to 1 to show debug messages in the log
|
|
44
45
|
|
|
45
46
|
@version 9.2
|
|
46
47
|
@author Allan Bowe
|
|
@@ -53,6 +54,7 @@ Usage:
|
|
|
53
54
|
,code=ft15f001
|
|
54
55
|
,desc=This service was created by the mp_createwebservice macro
|
|
55
56
|
,replace=YES
|
|
57
|
+
,mdebug=0
|
|
56
58
|
)/*/STORE SOURCE*/;
|
|
57
59
|
|
|
58
60
|
%if &syscc ge 4 %then %do;
|
|
@@ -71,8 +73,17 @@ Usage:
|
|
|
71
73
|
,replace=&replace
|
|
72
74
|
)
|
|
73
75
|
%end;
|
|
76
|
+
%else %if &platform=SASJS %then %do;
|
|
77
|
+
%if "&path"="HOME" %then %let path=/Users/&_sasjs_username/My Folder;
|
|
78
|
+
%ms_createwebservice(path=&path
|
|
79
|
+
,name=&name
|
|
80
|
+
,code=&code
|
|
81
|
+
,precode=&precode
|
|
82
|
+
,mdebug=&mdebug
|
|
83
|
+
)
|
|
84
|
+
%end;
|
|
74
85
|
%else %do;
|
|
75
|
-
%if "&path"="HOME" %then %let path=/User Folders/&
|
|
86
|
+
%if "&path"="HOME" %then %let path=/User Folders/&_METAPERSON/My Folder;
|
|
76
87
|
%mm_createwebservice(path=&path
|
|
77
88
|
,name=&name
|
|
78
89
|
,code=&code
|
package/base/mp_gsubfile.sas
CHANGED
package/base/mp_jsonout.sas
CHANGED
package/base/mp_replace.sas
CHANGED
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
@param infile The QUOTED path to the file on which to perform the substitution
|
|
36
36
|
@param findvar= Macro variable NAME containing the string to search for
|
|
37
37
|
@param replacevar= Macro variable NAME containing the replacement string
|
|
38
|
-
@param outfile= (0) Optional QUOTED path to
|
|
38
|
+
@param outfile= (0) Optional QUOTED path to the adjusted output file (to
|
|
39
39
|
avoid overwriting the first file).
|
|
40
40
|
|
|
41
41
|
<h4> SAS Macros </h4>
|
|
@@ -43,7 +43,9 @@
|
|
|
43
43
|
@li mf_getuniquename.sas
|
|
44
44
|
|
|
45
45
|
<h4> Related Macros </h4>
|
|
46
|
-
@li
|
|
46
|
+
@li mp_chop.sas
|
|
47
|
+
@li mp_gsubfile.sas
|
|
48
|
+
@li mp_replace.test.sas
|
|
47
49
|
|
|
48
50
|
@version 9.4
|
|
49
51
|
@author Bartosz Jabłoński
|
package/base/mp_testservice.sas
CHANGED
|
@@ -40,7 +40,9 @@
|
|
|
40
40
|
@li mf_getuniquename.sas
|
|
41
41
|
@li mp_abort.sas
|
|
42
42
|
@li mp_binarycopy.sas
|
|
43
|
+
@li mp_chop.sas
|
|
43
44
|
@li mp_ds2csv.sas
|
|
45
|
+
@li ms_testservice.sas
|
|
44
46
|
@li mv_getjobresult.sas
|
|
45
47
|
@li mv_jobflow.sas
|
|
46
48
|
|
|
@@ -63,7 +65,7 @@
|
|
|
63
65
|
viyaresult=WEBOUT_JSON,
|
|
64
66
|
viyacontext=SAS Job Execution compute context
|
|
65
67
|
)/*/STORE SOURCE*/;
|
|
66
|
-
%local dbg pcnt fref1 webref i webcount var platform;
|
|
68
|
+
%local dbg pcnt fref1 fref2 webref webrefpath i webcount var platform;
|
|
67
69
|
%if &mdebug=1 %then %do;
|
|
68
70
|
%put &sysmacroname entry vars:;
|
|
69
71
|
%put _local_;
|
|
@@ -104,10 +106,14 @@
|
|
|
104
106
|
%end;
|
|
105
107
|
%end;
|
|
106
108
|
|
|
107
|
-
|
|
109
|
+
%let platform=%mf_getplatform();
|
|
108
110
|
%let fref1=%mf_getuniquefileref();
|
|
111
|
+
%let fref2=%mf_getuniquefileref();
|
|
109
112
|
%let webref=%mf_getuniquefileref();
|
|
110
|
-
%let
|
|
113
|
+
%let webrefpath=%sysfunc(pathname(work))/%mf_getuniquename();
|
|
114
|
+
/* mp_chop requires a physical path as input */
|
|
115
|
+
filename &webref "&webrefpath";
|
|
116
|
+
|
|
111
117
|
%if &platform=SASMETA %then %do;
|
|
112
118
|
|
|
113
119
|
/* parse the input files */
|
|
@@ -262,6 +268,19 @@
|
|
|
262
268
|
mdebug=&mdebug
|
|
263
269
|
)
|
|
264
270
|
|
|
271
|
+
%end;
|
|
272
|
+
%else %if &platform=SASJS %then %do;
|
|
273
|
+
|
|
274
|
+
%ms_testservice(&program
|
|
275
|
+
,inputfiles=&inputfiles
|
|
276
|
+
,inputdatasets=&inputdatasets
|
|
277
|
+
,inputparams=&inputparams
|
|
278
|
+
,debug=&debug
|
|
279
|
+
,mdebug=&mdebug
|
|
280
|
+
,outlib=&outlib
|
|
281
|
+
,outref=&outref
|
|
282
|
+
)
|
|
283
|
+
|
|
265
284
|
%end;
|
|
266
285
|
%else %do;
|
|
267
286
|
%put %str(ERR)OR: Unrecognised platform: &platform;
|
|
@@ -269,6 +288,8 @@
|
|
|
269
288
|
|
|
270
289
|
%if &mdebug=0 %then %do;
|
|
271
290
|
filename &webref clear;
|
|
291
|
+
filename &fref1 clear;
|
|
292
|
+
filename &fref2 clear;
|
|
272
293
|
%end;
|
|
273
294
|
%else %do;
|
|
274
295
|
%put &sysmacroname exit vars:;
|
package/lua/ml_gsubfile.sas
CHANGED
|
@@ -39,6 +39,14 @@ data _null_;
|
|
|
39
39
|
put 'io.close(file) ';
|
|
40
40
|
run;
|
|
41
41
|
|
|
42
|
+
/* ensure big enough lrecl to avoid lua compilation issues */
|
|
43
|
+
%local optval;
|
|
44
|
+
%let optval=%sysfunc(getoption(lrecl));
|
|
45
|
+
options lrecl=1024;
|
|
46
|
+
|
|
47
|
+
/* execute the lua code by using a .lua extension */
|
|
42
48
|
%inc "%sysfunc(pathname(work))/ml_gsubfile.lua" /source2;
|
|
43
49
|
|
|
50
|
+
options lrecl=&optval;
|
|
51
|
+
|
|
44
52
|
%mend ml_gsubfile;
|
package/lua/ml_json.sas
CHANGED
|
@@ -389,6 +389,14 @@ data _null_;
|
|
|
389
389
|
put '-- JSON.LUA ENDS HERE ';
|
|
390
390
|
run;
|
|
391
391
|
|
|
392
|
+
/* ensure big enough lrecl to avoid lua compilation issues */
|
|
393
|
+
%local optval;
|
|
394
|
+
%let optval=%sysfunc(getoption(lrecl));
|
|
395
|
+
options lrecl=1024;
|
|
396
|
+
|
|
397
|
+
/* execute the lua code by using a .lua extension */
|
|
392
398
|
%inc "%sysfunc(pathname(work))/ml_json.lua" /source2;
|
|
393
399
|
|
|
400
|
+
options lrecl=&optval;
|
|
401
|
+
|
|
394
402
|
%mend ml_json;
|
|
@@ -103,7 +103,7 @@ data _null_;
|
|
|
103
103
|
put ' ';
|
|
104
104
|
put '%if &action=OPEN %then %do; ';
|
|
105
105
|
put ' options nobomfile; ';
|
|
106
|
-
put ' data _null_;file &jref encoding=''utf-8'' ; ';
|
|
106
|
+
put ' data _null_;file &jref encoding=''utf-8'' lrecl=200; ';
|
|
107
107
|
put ' put ''{"PROCESSED_DTTM" : "'' "%sysfunc(datetime(),E8601DT26.6)" ''"''; ';
|
|
108
108
|
put ' run; ';
|
|
109
109
|
put '%end; ';
|
|
@@ -314,6 +314,25 @@ data _null_;
|
|
|
314
314
|
put ' run; ';
|
|
315
315
|
put '%end; ';
|
|
316
316
|
put '%mend mp_jsonout; ';
|
|
317
|
+
put ' ';
|
|
318
|
+
put '%macro mf_getuser(type=META ';
|
|
319
|
+
put ')/*/STORE SOURCE*/; ';
|
|
320
|
+
put ' %local user metavar; ';
|
|
321
|
+
put ' %if &type=OS %then %let metavar=_secureusername; ';
|
|
322
|
+
put ' %else %let metavar=_metaperson; ';
|
|
323
|
+
put ' ';
|
|
324
|
+
put ' %if %symexist(SYS_COMPUTE_SESSION_OWNER) %then %let user=&SYS_COMPUTE_SESSION_OWNER; ';
|
|
325
|
+
put ' %else %if %symexist(&metavar) %then %do; ';
|
|
326
|
+
put ' %if %length(&&&metavar)=0 %then %let user=&sysuserid; ';
|
|
327
|
+
put ' /* sometimes SAS will add @domain extension - remove for consistency */ ';
|
|
328
|
+
put ' /* but be sure to quote in case of usernames with commas */ ';
|
|
329
|
+
put ' %else %let user=%unquote(%scan(%quote(&&&metavar),1,@)); ';
|
|
330
|
+
put ' %end; ';
|
|
331
|
+
put ' %else %let user=&sysuserid; ';
|
|
332
|
+
put ' ';
|
|
333
|
+
put ' %quote(&user) ';
|
|
334
|
+
put ' ';
|
|
335
|
+
put '%mend mf_getuser; ';
|
|
317
336
|
put '%macro mm_webout(action,ds,dslabel=,fref=_webout,fmt=Y,missing=NULL ';
|
|
318
337
|
put ' ,showmeta=NO ';
|
|
319
338
|
put '); ';
|
|
@@ -455,25 +474,6 @@ data _null_;
|
|
|
455
474
|
put '%end; ';
|
|
456
475
|
put ' ';
|
|
457
476
|
put '%mend mm_webout; ';
|
|
458
|
-
put ' ';
|
|
459
|
-
put '%macro mf_getuser(type=META ';
|
|
460
|
-
put ')/*/STORE SOURCE*/; ';
|
|
461
|
-
put ' %local user metavar; ';
|
|
462
|
-
put ' %if &type=OS %then %let metavar=_secureusername; ';
|
|
463
|
-
put ' %else %let metavar=_metaperson; ';
|
|
464
|
-
put ' ';
|
|
465
|
-
put ' %if %symexist(SYS_COMPUTE_SESSION_OWNER) %then %let user=&SYS_COMPUTE_SESSION_OWNER; ';
|
|
466
|
-
put ' %else %if %symexist(&metavar) %then %do; ';
|
|
467
|
-
put ' %if %length(&&&metavar)=0 %then %let user=&sysuserid; ';
|
|
468
|
-
put ' /* sometimes SAS will add @domain extension - remove for consistency */ ';
|
|
469
|
-
put ' /* but be sure to quote in case of usernames with commas */ ';
|
|
470
|
-
put ' %else %let user=%unquote(%scan(%quote(&&&metavar),1,@)); ';
|
|
471
|
-
put ' %end; ';
|
|
472
|
-
put ' %else %let user=&sysuserid; ';
|
|
473
|
-
put ' ';
|
|
474
|
-
put ' %quote(&user) ';
|
|
475
|
-
put ' ';
|
|
476
|
-
put '%mend mf_getuser; ';
|
|
477
477
|
/* WEBOUT END */
|
|
478
478
|
put '%macro webout(action,ds,dslabel=,fmt=,missing=NULL,showmeta=NO);';
|
|
479
479
|
put ' %mm_webout(&action,ds=&ds,dslabel=&dslabel,fmt=&fmt,missing=&missing';
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
Usage:
|
|
14
14
|
|
|
15
|
-
%mfs_httpheader(Content-
|
|
15
|
+
%mfs_httpheader(Content-Type,application/csv)
|
|
16
16
|
|
|
17
17
|
@param [in] header_name Name of the http header to set
|
|
18
18
|
@param [in] header_value Value of the http header to set
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
%macro mfs_httpheader(header_name
|
|
29
29
|
,header_value
|
|
30
30
|
)/*/STORE SOURCE*/;
|
|
31
|
+
%global sasjs_stpsrv_header_loc;
|
|
31
32
|
%local fref fid i;
|
|
32
33
|
|
|
33
34
|
%if %sysfunc(filename(fref,&sasjs_stpsrv_header_loc)) ne 0 %then %do;
|
package/server/ms_createfile.sas
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
@li mf_getuniquefileref.sas
|
|
22
22
|
@li mf_getuniquename.sas
|
|
23
23
|
@li mp_abort.sas
|
|
24
|
+
@li ms_deletefile.sas
|
|
24
25
|
|
|
25
26
|
**/
|
|
26
27
|
|
|
@@ -29,6 +30,9 @@
|
|
|
29
30
|
,mdebug=0
|
|
30
31
|
);
|
|
31
32
|
|
|
33
|
+
/* first, delete in case it exists */
|
|
34
|
+
%ms_deletefile(&driveloc,mdebug=&mdebug)
|
|
35
|
+
|
|
32
36
|
%local fname0 fname1 fname2 boundary fname statcd msg optval;
|
|
33
37
|
%let fname0=%mf_getuniquefileref();
|
|
34
38
|
%let fname1=%mf_getuniquefileref();
|
|
@@ -40,8 +44,8 @@
|
|
|
40
44
|
options nobomfile;
|
|
41
45
|
|
|
42
46
|
data _null_;
|
|
43
|
-
file &fname0 termstr=crlf;
|
|
44
|
-
infile &inref end=eof;
|
|
47
|
+
file &fname0 termstr=crlf lrecl=32767;
|
|
48
|
+
infile &inref end=eof lrecl=32767;
|
|
45
49
|
if _n_ = 1 then do;
|
|
46
50
|
put "--&boundary.";
|
|
47
51
|
put 'Content-Disposition: form-data; name="filePath"';
|
|
@@ -61,17 +65,20 @@ data _null_;
|
|
|
61
65
|
run;
|
|
62
66
|
|
|
63
67
|
data _null_;
|
|
64
|
-
file &fname1;
|
|
68
|
+
file &fname1 lrecl=1000;
|
|
69
|
+
infile "&_sasjs_tokenfile" lrecl=1000;
|
|
70
|
+
input;
|
|
65
71
|
put "Content-Type: multipart/form-data; boundary=&boundary";
|
|
72
|
+
put "Authorization: Bearer " _infile_;
|
|
66
73
|
run;
|
|
67
74
|
|
|
68
75
|
%if &mdebug=1 %then %do;
|
|
69
76
|
data _null_;
|
|
70
|
-
infile &fname0;
|
|
77
|
+
infile &fname0 lrecl=32767;
|
|
71
78
|
input;
|
|
72
79
|
put _infile_;
|
|
73
80
|
data _null_;
|
|
74
|
-
infile &fname1;
|
|
81
|
+
infile &fname1 lrecl=32767;
|
|
75
82
|
input;
|
|
76
83
|
put _infile_;
|
|
77
84
|
run;
|
|
@@ -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;
|