1
0
mirror of https://github.com/sasjs/core.git synced 2026-01-14 20:10:05 +00:00

fix: .sasjslint file and indentation issues

This commit is contained in:
Allan Bowe
2021-04-03 18:10:41 +00:00
parent 1b70205cab
commit 030c4a4fc1
13 changed files with 110 additions and 77 deletions

View File

@@ -5,4 +5,4 @@ image:
file: .gitpod.dockerfile file: .gitpod.dockerfile
vscode: vscode:
extensions: extensions:
- sasjs.sasjs-for-vscode@1.6.0:V4hJpMtbpekMcPRNhh4SXQ== - sasjs.sasjs-for-vscode@1.7.2:R6y1nzpFh2P99BZg5FgH5g==

10
.sasjslint Normal file
View File

@@ -0,0 +1,10 @@
{
"noTrailingSpaces": true,
"noEncodedPasswords": true,
"hasDoxygenHeader": true,
"noSpacesInFileNames": true,
"maxLineLength": 120,
"lowerCaseFileNames": true,
"noTabIndentation": true,
"indentationMultiple": 2
}

View File

@@ -118,7 +118,7 @@ All macros must be commented in the doxygen format, to enable the [online docume
### Dependencies ### Dependencies
SAS code can contain one of two types of dependency - SAS Macros, and SAS Programs. When compiling projects using the [SASjs CLI](https://cli.sasjs.io) the doxygen header is scanned for ` @li` items under the following headers: SAS code can contain one of two types of dependency - SAS Macros, and SAS Programs. When compiling projects using the [SASjs CLI](https://cli.sasjs.io) the doxygen header is scanned for ` @li` items under the following headers:
``` ```sas
<h4> SAS Macros </h4> <h4> SAS Macros </h4>
@li mf_nobs.sas @li mf_nobs.sas
@li mm_assignlib.sas @li mm_assignlib.sas

View File

@@ -10,7 +10,8 @@
First, compile the macros: First, compile the macros:
filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas"; filename mc url
"https://raw.githubusercontent.com/sasjs/core/main/all.sas";
%inc mc; %inc mc;
Next, create a job (in this case, a web service): Next, create a job (in this case, a web service):
@@ -174,7 +175,7 @@ data _null_;
outfile:write(logloc) outfile:write(logloc)
io.close(infile) io.close(infile)
io.close(outfile) io.close(outfile)
'; ';
run; run;
%inc "&fpath3..lua"; %inc "&fpath3..lua";
/* get log path*/ /* get log path*/
@@ -228,7 +229,7 @@ data _null_;
io.input(infile) io.input(infile)
local resp=json.decode(io.read()) local resp=json.decode(io.read())
for i, v in pairs(resp["items"]) do for i, v in pairs(resp["items"]) do
outfile:write(v.line,"\n") outfile:write(v.line,"\n")
end end
io.close(infile) io.close(infile)
io.close(outfile) io.close(outfile)

View File

@@ -1,24 +1,24 @@
/** /**
@file mv_getrefreshtoken.sas @file mv_getrefreshtoken.sas
@brief deprecated - replaced by mv_tokenauth.sas @brief deprecated - replaced by mv_tokenauth.sas
@version VIYA V.03.04 @version VIYA V.03.04
@author Allan Bowe, source: https://github.com/sasjs/core @author Allan Bowe, source: https://github.com/sasjs/core
<h4> SAS Macros </h4> <h4> SAS Macros </h4>
@li mv_tokenauth.sas @li mv_tokenauth.sas
**/ **/
%macro mv_getrefreshtoken(client_id=someclient %macro mv_getrefreshtoken(client_id=someclient
,client_secret=somesecret ,client_secret=somesecret
,grant_type=authorization_code ,grant_type=authorization_code
,code= ,code=
,user= ,user=
,pass= ,pass=
,access_token_var=ACCESS_TOKEN ,access_token_var=ACCESS_TOKEN
,refresh_token_var=REFRESH_TOKEN ,refresh_token_var=REFRESH_TOKEN
); );
%mv_tokenauth(client_id=&client_id %mv_tokenauth(client_id=&client_id
,client_secret=&client_secret ,client_secret=&client_secret

View File

@@ -65,7 +65,7 @@ proc http method='GET' out=&fname1 &oauth_bearer
url="&base_uri/identities/users/&user/memberships?limit=10000"; url="&base_uri/identities/users/&user/memberships?limit=10000";
headers headers
%if &grant_type=authorization_code %then %do; %if &grant_type=authorization_code %then %do;
"Authorization"="Bearer &&&access_token_var" "Authorization"="Bearer &&&access_token_var"
%end; %end;
"Accept"="application/json"; "Accept"="application/json";
run; run;

View File

@@ -37,11 +37,11 @@
@param access_token_var= The global macro variable to contain the access token @param access_token_var= The global macro variable to contain the access token
@param grant_type= valid values: @param grant_type= valid values:
* password * password
* authorization_code * authorization_code
* detect - will check if access_token exists, if not will use sas_services if * detect - will check if access_token exists, if not will use sas_services if
a SASStudioV session else authorization_code. Default option. a SASStudioV session else authorization_code. Default option.
* sas_services - will use oauth_bearer=sas_services * sas_services - will use oauth_bearer=sas_services
@param outds= The library.dataset to be created that contains the list of groups @param outds= The library.dataset to be created that contains the list of groups

View File

@@ -13,7 +13,7 @@
@li FLOW_ID - Numeric value, provides sequential ordering capability. Is @li FLOW_ID - Numeric value, provides sequential ordering capability. Is
optional, will default to 0 if not provided. optional, will default to 0 if not provided.
@li _CONTEXTNAME - Dictates which context should be used to run the job. If @li _CONTEXTNAME - Dictates which context should be used to run the job. If
blank (or not provided), will default to `SAS Job Execution compute context`. blank, or not provided, will default to `SAS Job Execution compute context`.
Any additional variables provided in this table are converted into macro Any additional variables provided in this table are converted into macro
variables and passed into the relevant job. variables and passed into the relevant job.
@@ -97,15 +97,17 @@
run; run;
@param [in] access_token_var= The global macro variable to contain the access token @param [in] access_token_var= The global macro variable to contain the access
token
@param [in] grant_type= valid values: @param [in] grant_type= valid values:
@li password @li password
@li authorization_code @li authorization_code
@li detect - will check if access_token exists, if not will use sas_services if @li detect - will check if access_token exists, if not will use
a SASStudioV session else authorization_code. Default option. sas_services if a SASStudioV session else authorization_code. Default
option.
@li sas_services - will use oauth_bearer=sas_services @li sas_services - will use oauth_bearer=sas_services
@param [in] inds= The input dataset containing a list of jobs and parameters @param [in] inds= The input dataset containing a list of jobs and parameters
@param [in] maxconcurrency= The max number of parallel jobs to run. Default=8. @param [in] maxconcurrency= The max number of parallel jobs to run. Default=8.
@param [in] raise_err=0 Set to 1 to raise SYSCC when a job does not complete @param [in] raise_err=0 Set to 1 to raise SYSCC when a job does not complete
succcessfully succcessfully
@param [in] mdebug= set to 1 to enable DEBUG messages @param [in] mdebug= set to 1 to enable DEBUG messages
@@ -185,7 +187,7 @@ select count(*) into: missings
where flow_id is null or _program is null; where flow_id is null or _program is null;
%mp_abort(iftrue=(&missings>0) %mp_abort(iftrue=(&missings>0)
,mac=&sysmacroname ,mac=&sysmacroname
,msg=%str(input dataset contains &missings missing values for FLOW_ID or _PROGRAM) ,msg=%str(input dataset has &missings missing values for FLOW_ID or _PROGRAM)
) )
%if %mf_nobs(&inds)=0 %then %do; %if %mf_nobs(&inds)=0 %then %do;
@@ -284,7 +286,8 @@ data;run;%let jdswaitfor=&syslast;
%if "&&jobuid&jid"="0" and &concurrency<&maxconcurrency %then %do; %if "&&jobuid&jid"="0" and &concurrency<&maxconcurrency %then %do;
%local jobname jobpath; %local jobname jobpath;
%let jobname=%scan(&&job&jid,-1,/); %let jobname=%scan(&&job&jid,-1,/);
%let jobpath=%substr(&&job&jid,1,%length(&&job&jid)-%length(&jobname)-1); %let jobpath=
%substr(&&job&jid,1,%length(&&job&jid)-%length(&jobname)-1);
%put executing &jobpath/&jobname with paramstring &&jparams&jid; %put executing &jobpath/&jobname with paramstring &&jparams&jid;
%mv_jobexecute(path=&jobpath %mv_jobexecute(path=&jobpath
,name=&jobname ,name=&jobname
@@ -334,7 +337,8 @@ data;run;%let jdswaitfor=&syslast;
/* loop again if jobs are left */ /* loop again if jobs are left */
%if &completed < &jcnt %then %do; %if &completed < &jcnt %then %do;
%let jid=0; %let jid=0;
%put looping flow &fid again - &completed of &jcnt jobs completed, &concurrency jobs running; %put looping flow &fid again - &completed of &jcnt jobs completed,
&concurrency jobs running;
%end; %end;
%end; %end;
%end; %end;

View File

@@ -4,15 +4,17 @@
@details When building apps on SAS Viya, an client id and secret is required. @details When building apps on SAS Viya, an client id and secret is required.
This macro will obtain the Consul Token and use that to call the Web Service. This macro will obtain the Consul Token and use that to call the Web Service.
more info: https://developer.sas.com/reference/auth/#register more info: https://developer.sas.com/reference/auth/#register
and: http://proc-x.com/2019/01/authentication-to-sas-viya-a-couple-of-approaches/ and:
http://proc-x.com/2019/01/authentication-to-sas-viya-a-couple-of-approaches
The default viyaroot location is /opt/sas/viya/config The default viyaroot location is /opt/sas/viya/config
Usage: Usage:
%* compile macros; %* compile macros;
filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas"; filename mc url
"https://raw.githubusercontent.com/sasjs/core/main/all.sas";
%inc mc; %inc mc;
%* specific client with just openid scope; %* specific client with just openid scope;
@@ -33,7 +35,8 @@
@param client_id= The client name. Auto generated if blank. @param client_id= The client name. Auto generated if blank.
@param client_secret= Client secret Auto generated if client is blank. @param client_secret= Client secret Auto generated if client is blank.
@param scopes= list of space-seperated unquoted scopes (default is openid) @param scopes= list of space-seperated unquoted scopes (default is openid)
@param grant_type= valid values are "password" or "authorization_code" (unquoted) @param grant_type= valid values are "password" or "authorization_code"
(unquoted)
@param outds= the dataset to contain the registered client id and secret @param outds= the dataset to contain the registered client id and secret
@param access_token_validity= The duration of validity of the access token @param access_token_validity= The duration of validity of the access token
in seconds. A value of DEFAULT will omit the entry (and use system default) in seconds. A value of DEFAULT will omit the entry (and use system default)
@@ -78,15 +81,16 @@
,refresh_token_validity=DEFAULT ,refresh_token_validity=DEFAULT
,outjson=_null_ ,outjson=_null_
); );
%local consul_token fname1 fname2 fname3 libref access_token url; %local consul_token fname1 fname2 fname3 libref access_token url tokloc;
%if client_name=DEFAULT %then %let client_name= %if client_name=DEFAULT %then %let client_name=
Generated by %mf_getuser() on %sysfunc(datetime(),datetime19.) using SASjs; Generated by %mf_getuser() on %sysfunc(datetime(),datetime19.) using SASjs;
options noquotelenmax; options noquotelenmax;
/* first, get consul token needed to get client id / secret */ /* first, get consul token needed to get client id / secret */
%let tokloc=/etc/SASSecurityCertificateFramework/tokens/consul/default;
data _null_; data _null_;
infile "%mf_loc(VIYACONFIG)/etc/SASSecurityCertificateFramework/tokens/consul/default/client.token"; infile "%mf_loc(VIYACONFIG)&tokloc/client.token";
input token:$64.; input token:$64.;
call symputx('consul_token',token); call symputx('consul_token',token);
run; run;
@@ -97,8 +101,9 @@ run;
/* request the client details */ /* request the client details */
%let fname1=%mf_getuniquefileref(); %let fname1=%mf_getuniquefileref();
proc http method='POST' out=&fname1 proc http method='POST' out=&fname1
url="&base_uri/SASLogon/oauth/clients/consul?callback=false%str(&)serviceId=app"; url="&base_uri/SASLogon/oauth/clients/consul?callback=false%str(&)%trim(
headers "X-Consul-Token"="&consul_token"; )serviceId=app";
headers "X-Consul-Token"="&consul_token";
run; run;
%let libref=%mf_getuniquelibref(); %let libref=%mf_getuniquelibref();
@@ -111,8 +116,8 @@ data _null_;
run; run;
/** /**
* register the new client * register the new client
*/ */
%let fname2=%mf_getuniquefileref(); %let fname2=%mf_getuniquefileref();
%if x&client_id.x=xx %then %do; %if x&client_id.x=xx %then %do;
%let client_id=client_%sysfunc(ranuni(0),hex16.); %let client_id=client_%sysfunc(ranuni(0),hex16.);
@@ -122,7 +127,8 @@ run;
%let scopes=%sysfunc(coalescec(&scopes,openid)); %let scopes=%sysfunc(coalescec(&scopes,openid));
%let scopes=%mf_getquotedstr(&scopes,QUOTE=D,indlm=|); %let scopes=%mf_getquotedstr(&scopes,QUOTE=D,indlm=|);
%let grant_type=%mf_getquotedstr(&grant_type,QUOTE=D,indlm=|); %let grant_type=%mf_getquotedstr(&grant_type,QUOTE=D,indlm=|);
%let required_user_groups=%mf_getquotedstr(&required_user_groups,QUOTE=D,indlm=|); %let required_user_groups=
%mf_getquotedstr(&required_user_groups,QUOTE=D,indlm=|);
data _null_; data _null_;
file &fname2; file &fname2;
@@ -139,9 +145,11 @@ data _null_;
if reqd_groups = '""' then reqd_groups =''; if reqd_groups = '""' then reqd_groups ='';
else reqd_groups=cats(',"required_user_groups":[',reqd_groups,']'); else reqd_groups=cats(',"required_user_groups":[',reqd_groups,']');
autoapprove=trim(symget('autoapprove')); autoapprove=trim(symget('autoapprove'));
if not missing(autoapprove) then autoapprove=cats(',"autoapprove":',autoapprove); if not missing(autoapprove) then autoapprove=
cats(',"autoapprove":',autoapprove);
use_session=trim(symget('use_session')); use_session=trim(symget('use_session'));
if not missing(use_session) then use_session=cats(',"use_session":',use_session); if not missing(use_session) then use_session=
cats(',"use_session":',use_session);
put '{' clientid ; put '{' clientid ;
put clientsecret ; put clientsecret ;
@@ -206,10 +214,12 @@ run;
%put GRANT_TYPE=&grant_type; %put GRANT_TYPE=&grant_type;
%put; %put;
%if %index(%superq(grant_type),authorization_code) %then %do; %if %index(%superq(grant_type),authorization_code) %then %do;
/* cannot use base_uri here as it includes the protocol which may be incorrect externally */ /* cannot use base_uri here as it includes the protocol which may be incorrect
%put NOTE: The developer must also register below and select 'openid' to get the grant code:; externally */
%put NOTE: Visit the link below and select 'openid' to get the grant code:;
%put NOTE- ; %put NOTE- ;
%put NOTE- &url/SASLogon/oauth/authorize?client_id=&client_id%str(&)response_type=code; %put NOTE- &url/SASLogon/oauth/authorize?client_id=&client_id%str(&)%trim(
)response_type=code;
%put NOTE- ; %put NOTE- ;
%end; %end;

View File

@@ -15,7 +15,8 @@
Usage: Usage:
filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas"; filename mc url
"https://raw.githubusercontent.com/sasjs/core/main/all.sas";
%inc mc; %inc mc;
@@ -31,13 +32,15 @@
@param outds= A dataset containing access_token and refresh_token @param outds= A dataset containing access_token and refresh_token
@param client_id= The client name @param client_id= The client name
@param client_secret= client secret @param client_secret= client secret
@param grant_type= valid values are "password" or "authorization_code" (unquoted). @param grant_type= valid values are "password" or "authorization_code"
The default is authorization_code. (unquoted). The default is authorization_code.
@param code= If grant_type=authorization_code then provide the necessary code here @param code= If grant_type=authorization_code then provide the necessary code
here
@param user= If grant_type=password then provide the username here @param user= If grant_type=password then provide the username here
@param pass= If grant_type=password then provide the password here @param pass= If grant_type=password then provide the password here
@param access_token_var= The global macro variable to contain the access token @param access_token_var= The global macro variable to contain the access token
@param refresh_token_var= The global macro variable to contain the refresh token @param refresh_token_var= The global macro variable to contain the refresh
token
@param base_uri= The Viya API server location @param base_uri= The Viya API server location
@version VIYA V.03.04 @version VIYA V.03.04
@@ -88,7 +91,8 @@
,msg=%str(Authorization code required) ,msg=%str(Authorization code required)
) )
%mp_abort(iftrue=(&grant_type=password and (%str(&user)=%str() or %str(&pass)=%str())) %mp_abort(iftrue=(
&grant_type=password and (%str(&user)=%str() or %str(&pass)=%str()))
,mac=&sysmacroname ,mac=&sysmacroname
,msg=%str(username / password required) ,msg=%str(username / password required)
) )
@@ -99,7 +103,7 @@
data _null_; data _null_;
file &fref1; file &fref1;
if "&grant_type"='authorization_code' then string=cats( if "&grant_type"='authorization_code' then string=cats(
'grant_type=authorization_code&code=',symget('code')); 'grant_type=authorization_code&code=',symget('code'));
else string=cats('grant_type=password&username=',symget('user') else string=cats('grant_type=password&username=',symget('user')
,'&password=',symget(pass)); ,'&password=',symget(pass));
call symputx('grantstring',cats("'",string,"'")); call symputx('grantstring',cats("'",string,"'"));
@@ -107,8 +111,8 @@ run;
/*data _null_;infile &fref1;input;put _infile_;run;*/ /*data _null_;infile &fref1;input;put _infile_;run;*/
/** /**
* Request access token * Request access token
*/ */
%if &base_uri=#NOTSET# %then %let base_uri=%mf_getplatform(VIYARESTAPI); %if &base_uri=#NOTSET# %then %let base_uri=%mf_getplatform(VIYARESTAPI);
%let fref2=%mf_getuniquefileref(); %let fref2=%mf_getuniquefileref();
@@ -123,8 +127,8 @@ run;
/*data _null_;infile &fref2;input;put _infile_;run;*/ /*data _null_;infile &fref2;input;put _infile_;run;*/
/** /**
* Extract access / refresh tokens * Extract access / refresh tokens
*/ */
%let libref=%mf_getuniquelibref(); %let libref=%mf_getuniquelibref();
libname &libref JSON fileref=&fref2; libname &libref JSON fileref=&fref2;

View File

@@ -32,12 +32,13 @@
@param outds= A dataset containing access_token and refresh_token @param outds= A dataset containing access_token and refresh_token
@param client_id= The client name (alternative to inds) @param client_id= The client name (alternative to inds)
@param client_secret= client secret (alternative to inds) @param client_secret= client secret (alternative to inds)
@param grant_type= valid values are "password" or "authorization_code" (unquoted). @param grant_type= valid values are "password" or "authorization_code"
The default is authorization_code. (unquoted). The default is authorization_code.
@param user= If grant_type=password then provide the username here @param user= If grant_type=password then provide the username here
@param pass= If grant_type=password then provide the password here @param pass= If grant_type=password then provide the password here
@param access_token_var= The global macro variable to contain the access token @param access_token_var= The global macro variable to contain the access token
@param refresh_token_var= The global macro variable containing the refresh token @param refresh_token_var= The global macro variable containing the refresh
token
@version VIYA V.03.04 @version VIYA V.03.04
@author Allan Bowe, source: https://github.com/sasjs/core @author Allan Bowe, source: https://github.com/sasjs/core
@@ -72,7 +73,8 @@ options noquotelenmax;
,msg=%str(Invalid value for grant_type: &grant_type) ,msg=%str(Invalid value for grant_type: &grant_type)
) )
%mp_abort(iftrue=(&grant_type=password and (%str(&user)=%str() or %str(&pass)=%str())) %mp_abort(
iftrue=(&grant_type=password and (%str(&user)=%str() or %str(&pass)=%str()))
,mac=&sysmacroname ,mac=&sysmacroname
,msg=%str(username / password required) ,msg=%str(username / password required)
) )
@@ -92,8 +94,8 @@ options noquotelenmax;
) )
/** /**
* Request access token * Request access token
*/ */
%local base_uri; /* location of rest apis */ %local base_uri; /* location of rest apis */
%let base_uri=%mf_getplatform(VIYARESTAPI); %let base_uri=%mf_getplatform(VIYARESTAPI);
@@ -111,8 +113,8 @@ run;
/*data _null_;infile &fref1;input;put _infile_;run;*/ /*data _null_;infile &fref1;input;put _infile_;run;*/
/** /**
* Extract access / refresh tokens * Extract access / refresh tokens
*/ */
%let libref=%mf_getuniquelibref(); %let libref=%mf_getuniquelibref();
libname &libref JSON fileref=&fref1; libname &libref JSON fileref=&fref1;

View File

@@ -109,7 +109,8 @@
if _n_=1 then call symputx('input_statement',_infile_); if _n_=1 then call symputx('input_statement',_infile_);
list; list;
data &table; data &table;
infile "%sysfunc(pathname(work))/&table..csv" firstobs=2 dsd termstr=crlf; infile "%sysfunc(pathname(work))/&table..csv" firstobs=2 dsd
termstr=crlf;
input &input_statement; input &input_statement;
run; run;
%end; %end;
@@ -141,7 +142,7 @@
/* setup webout */ /* setup webout */
OPTIONS NOBOMFILE; OPTIONS NOBOMFILE;
%if "X&SYS_JES_JOB_URI.X"="XX" %then %do; %if "X&SYS_JES_JOB_URI.X"="XX" %then %do;
filename _webout temp lrecl=999999 mod; filename _webout temp lrecl=999999 mod;
%end; %end;
%else %do; %else %do;
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" filename _webout filesrvc parenturi="&SYS_JES_JOB_URI"
@@ -150,7 +151,8 @@
/* setup temp ref */ /* setup temp ref */
%if %upcase(&fref) ne _WEBOUT %then %do; %if %upcase(&fref) ne _WEBOUT %then %do;
filename &fref temp lrecl=999999 permission='A::u::rwx,A::g::rw-,A::o::---' mod; filename &fref temp lrecl=999999 permission='A::u::rwx,A::g::rw-,A::o::---'
mod;
%end; %end;
/* setup json */ /* setup json */