Skip to content

Commit

Permalink
fix: adding authentication to server macros. Closes #221
Browse files Browse the repository at this point in the history
  • Loading branch information
Allan Bowe committed Apr 20, 2022
1 parent c4cb0b2 commit 11da53f
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 26 deletions.
46 changes: 35 additions & 11 deletions all.sas
Expand Up @@ -18978,8 +18978,11 @@ data _null_;
run;

data _null_;
file &fname1;
file &fname1 lrecl=1000;
infile "&_sasjs_tokenfile" lrecl=1000;
input;
put "Content-Type: multipart/form-data; boundary=&boundary";
put "Authorization: Bearer " _infile_;
run;

%if &mdebug=1 %then %do;
Expand Down Expand Up @@ -19039,20 +19042,33 @@ options &optval;
@param [in] driveloc The full path to the file in SASjs Drive
@param [in] mdebug= (0) Set to 1 to enable DEBUG messages

<h4> SAS Macros </h4>
@li mf_getuniquefileref.sas

**/

%macro ms_deletefile(driveloc
,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";
%if &mdebug=1 %then %do;
debug level=2;
%end;
run;

filename &headref clear;

%mend ms_deletefile;
/**
Expand All @@ -19062,7 +19078,7 @@ run;

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 [out] outref= (msgetfil) The fileref to contain the file.
Expand All @@ -19080,23 +19096,31 @@ run;
);

/* 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 headref=%mf_getuniquefileref();
%let floc=%sysfunc(pathname(work))/%mf_getuniquename().txt;
filename &outref "&floc";
filename &outref "&floc" lrecl=32767;
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";
%if &mdebug=1 %then %do;
debug level=2;
%end;
run;

filename &binaryfref clear;
filename &headref clear;

%mend ms_getfile;
/**
%mend ms_getfile;/**
@file
@brief Executes a SASjs Server Stored Program
@details Runs a Stored Program (using POST method) and extracts the webout and
Expand Down Expand Up @@ -19141,10 +19165,10 @@ filename &binaryfref clear;
)

data _null_;
file &fname1;
infile "&_sasjs_tokenfile";
file &fname1 lrecl=1000;
infile "&_sasjs_tokenfile" lrecl=1000;
input;
put 'Authorization: Bearer' _infile_;
put 'Authorization: Bearer ' _infile_;
run;

filename &outref temp;
Expand Down
3 changes: 0 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions sasjs/sasjsconfig.json
Expand Up @@ -65,7 +65,7 @@
},
{
"name": "server",
"serverUrl": "https://sas.analytium.co.uk:5000",
"serverUrl": "https://sas.analytium.co.uk:5006",
"serverType": "SASJS",
"httpsAgentOptions": {
"allowInsecureRequests": false
Expand Down Expand Up @@ -108,6 +108,16 @@
"deployServicePack": true
},
"contextName": "SAS Job Execution compute context"
},
{
"name": "4gl",
"serverUrl": "https://frs2.4gl.io",
"serverType": "SASJS",
"httpsAgentOptions": {
"rejectUnauthorized": false,
"allowInsecureRequests": true
},
"appLoc": "/Public/app/core"
}
]
}
}
5 changes: 4 additions & 1 deletion server/ms_createfile.sas
Expand Up @@ -61,8 +61,11 @@ data _null_;
run;

data _null_;
file &fname1;
file &fname1 lrecl=1000;
infile "&_sasjs_tokenfile" lrecl=1000;
input;
put "Content-Type: multipart/form-data; boundary=&boundary";
put "Authorization: Bearer " _infile_;
run;

%if &mdebug=1 %then %do;
Expand Down
15 changes: 14 additions & 1 deletion server/ms_deletefile.sas
Expand Up @@ -17,19 +17,32 @@
@param [in] driveloc The full path to the file in SASjs Drive
@param [in] mdebug= (0) Set to 1 to enable DEBUG messages
<h4> SAS Macros </h4>
@li mf_getuniquefileref.sas
**/

%macro ms_deletefile(driveloc
,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";
%if &mdebug=1 %then %do;
debug level=2;
%end;
run;

filename &headref clear;

%mend ms_deletefile;
19 changes: 14 additions & 5 deletions server/ms_getfile.sas
Expand Up @@ -5,7 +5,7 @@
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 [out] outref= (msgetfil) The fileref to contain the file.
Expand All @@ -23,19 +23,28 @@
);

/* 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 headref=%mf_getuniquefileref();
%let floc=%sysfunc(pathname(work))/%mf_getuniquename().txt;
filename &outref "&floc";
filename &outref "&floc" lrecl=32767;
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";
%if &mdebug=1 %then %do;
debug level=2;
%end;
run;

filename &binaryfref clear;
filename &headref clear;

%mend ms_getfile;
%mend ms_getfile;
6 changes: 3 additions & 3 deletions server/ms_runstp.sas
Expand Up @@ -43,10 +43,10 @@
)

data _null_;
file &fname1;
infile "&_sasjs_tokenfile";
file &fname1 lrecl=1000;
infile "&_sasjs_tokenfile" lrecl=1000;
input;
put 'Authorization: Bearer' _infile_;
put 'Authorization: Bearer ' _infile_;
run;

filename &outref temp;
Expand Down

0 comments on commit 11da53f

Please sign in to comment.