From 11da53f1cb163d2ead87c4a5fc133ce895ad1d27 Mon Sep 17 00:00:00 2001 From: Allan Bowe Date: Wed, 20 Apr 2022 15:41:36 +0000 Subject: [PATCH 1/3] fix: adding authentication to server macros. Closes #221 --- all.sas | 46 ++++++++++++++++++++++++++++++---------- package-lock.json | 3 --- sasjs/sasjsconfig.json | 14 ++++++++++-- server/ms_createfile.sas | 5 ++++- server/ms_deletefile.sas | 15 ++++++++++++- server/ms_getfile.sas | 19 ++++++++++++----- server/ms_runstp.sas | 6 +++--- 7 files changed, 82 insertions(+), 26 deletions(-) diff --git a/all.sas b/all.sas index c41c7ed..ef3edac 100644 --- a/all.sas +++ b/all.sas @@ -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; @@ -19039,6 +19042,8 @@ 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 +

SAS Macros

+ @li mf_getuniquefileref.sas **/ @@ -19046,13 +19051,24 @@ options &optval; ,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; /** @@ -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. @@ -19080,13 +19096,21 @@ 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; @@ -19094,9 +19118,9 @@ proc http method='GET' out=&binaryfref 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 @@ -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; diff --git a/package-lock.json b/package-lock.json index bc102c1..38a0963 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,9 +6,6 @@ "": { "name": "@sasjs/core", "license": "MIT", - "dependencies": { - "@sasjs/core": "^4.18.13" - }, "devDependencies": { "@sasjs/cli": "3.13.0" } diff --git a/sasjs/sasjsconfig.json b/sasjs/sasjsconfig.json index 1930931..1adf200 100644 --- a/sasjs/sasjsconfig.json +++ b/sasjs/sasjsconfig.json @@ -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 @@ -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" } ] -} +} \ No newline at end of file diff --git a/server/ms_createfile.sas b/server/ms_createfile.sas index 02fa57b..aa13f50 100644 --- a/server/ms_createfile.sas +++ b/server/ms_createfile.sas @@ -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; diff --git a/server/ms_deletefile.sas b/server/ms_deletefile.sas index bf6f15c..20455c0 100644 --- a/server/ms_deletefile.sas +++ b/server/ms_deletefile.sas @@ -17,6 +17,8 @@ @param [in] driveloc The full path to the file in SASjs Drive @param [in] mdebug= (0) Set to 1 to enable DEBUG messages +

SAS Macros

+ @li mf_getuniquefileref.sas **/ @@ -24,12 +26,23 @@ ,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; diff --git a/server/ms_getfile.sas b/server/ms_getfile.sas index c0c6b88..09784be 100644 --- a/server/ms_getfile.sas +++ b/server/ms_getfile.sas @@ -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. @@ -23,13 +23,21 @@ ); /* 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; @@ -37,5 +45,6 @@ proc http method='GET' out=&binaryfref run; filename &binaryfref clear; +filename &headref clear; -%mend ms_getfile; +%mend ms_getfile; \ No newline at end of file diff --git a/server/ms_runstp.sas b/server/ms_runstp.sas index 0f7e76f..e8b2107 100644 --- a/server/ms_runstp.sas +++ b/server/ms_runstp.sas @@ -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; From bd3082d7e3f4f4cbe88cc9e9951cd2fd5c0c2026 Mon Sep 17 00:00:00 2001 From: Allan Bowe Date: Wed, 20 Apr 2022 15:45:37 +0000 Subject: [PATCH 2/3] chore: updating sasjsconfig --- sasjs/sasjsconfig.json | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/sasjs/sasjsconfig.json b/sasjs/sasjsconfig.json index 1adf200..cf3659f 100644 --- a/sasjs/sasjsconfig.json +++ b/sasjs/sasjsconfig.json @@ -65,7 +65,7 @@ }, { "name": "server", - "serverUrl": "https://sas.analytium.co.uk:5006", + "serverUrl": "https://sas.analytium.co.uk:5000", "serverType": "SASJS", "httpsAgentOptions": { "allowInsecureRequests": false @@ -108,16 +108,6 @@ "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" } ] } \ No newline at end of file From cebe119304b0537e0989f8733befd8a31cb7e290 Mon Sep 17 00:00:00 2001 From: Allan Bowe Date: Wed, 20 Apr 2022 15:53:44 +0000 Subject: [PATCH 3/3] fix: failing test (chagned response) --- tests/serveronly/ms_deletefile.test.sas | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/serveronly/ms_deletefile.test.sas b/tests/serveronly/ms_deletefile.test.sas index 3a1b2e9..aa0dd2a 100644 --- a/tests/serveronly/ms_deletefile.test.sas +++ b/tests/serveronly/ms_deletefile.test.sas @@ -53,7 +53,7 @@ data _null_; run; %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, outds=work.test_results )