mirror of
https://github.com/sasjs/core.git
synced 2025-12-11 06:24:35 +00:00
123 lines
3.8 KiB
SAS
123 lines
3.8 KiB
SAS
/**
|
|
@file mv_getfoldermembers.sas
|
|
@brief Gets a list of folders (and ids) for a given root
|
|
@details Works for both root level and below, oauth or password. Default is
|
|
oauth, and the token is expected in a global ACCESS_TOKEN variable.
|
|
|
|
%mv_getfoldermembers(root=/Public)
|
|
|
|
|
|
@param root= The path for which to return the list of folders
|
|
@param outds= The output dataset to create (default is work.mv_getfolders). Format:
|
|
|ordinal_root|ordinal_items|creationTimeStamp| modifiedTimeStamp|createdBy|modifiedBy|id| uri|added| type|name|description|
|
|
|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
|1|1|2021-05-25T11:15:04.204Z|2021-05-25T11:15:04.204Z|allbow|allbow|4f1e3945-9655-462b-90f2-c31534b3ca47|/folders/folders/ed701ff3-77e8-468d-a4f5-8c43dec0fd9e|2021-05-25T11:15:04.212Z|child|my_folder_name|My folder Description|
|
|
|
|
@param access_token_var= The global macro variable to contain the access token
|
|
@param grant_type= valid values are "password" or "authorization_code" (unquoted).
|
|
The default is authorization_code.
|
|
|
|
|
|
@version VIYA V.03.04
|
|
@author Allan Bowe, source: https://github.com/sasjs/core
|
|
|
|
<h4> SAS Macros </h4>
|
|
@li mp_abort.sas
|
|
@li mf_getplatform.sas
|
|
@li mf_getuniquefileref.sas
|
|
@li mf_getuniquelibref.sas
|
|
@li mf_isblank.sas
|
|
|
|
**/
|
|
|
|
%macro mv_getfoldermembers(root=/
|
|
,access_token_var=ACCESS_TOKEN
|
|
,grant_type=sas_services
|
|
,outds=mv_getfolders
|
|
);
|
|
%local oauth_bearer;
|
|
%if &grant_type=detect %then %do;
|
|
%if %symexist(&access_token_var) %then %let grant_type=authorization_code;
|
|
%else %let grant_type=sas_services;
|
|
%end;
|
|
%if &grant_type=sas_services %then %do;
|
|
%let oauth_bearer=oauth_bearer=sas_services;
|
|
%let &access_token_var=;
|
|
%end;
|
|
|
|
%mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
|
|
and &grant_type ne sas_services
|
|
)
|
|
,mac=&sysmacroname
|
|
,msg=%str(Invalid value for grant_type: &grant_type)
|
|
)
|
|
|
|
%if %mf_isblank(&root)=1 %then %let root=/;
|
|
|
|
options noquotelenmax;
|
|
|
|
/* request the client details */
|
|
%local fname1 libref1;
|
|
%let fname1=%mf_getuniquefileref();
|
|
%let libref1=%mf_getuniquelibref();
|
|
|
|
%local base_uri; /* location of rest apis */
|
|
%let base_uri=%mf_getplatform(VIYARESTAPI);
|
|
|
|
%if "&root"="/" %then %do;
|
|
/* if root just list root folders */
|
|
proc http method='GET' out=&fname1 &oauth_bearer
|
|
url="&base_uri/folders/rootFolders";
|
|
%if &grant_type=authorization_code %then %do;
|
|
headers "Authorization"="Bearer &&&access_token_var";
|
|
%end;
|
|
run;
|
|
libname &libref1 JSON fileref=&fname1;
|
|
data &outds;
|
|
set &libref1..items;
|
|
run;
|
|
%end;
|
|
%else %do;
|
|
/* first get parent folder id */
|
|
proc http method='GET' out=&fname1 &oauth_bearer
|
|
url="&base_uri/folders/folders/@item?path=&root";
|
|
%if &grant_type=authorization_code %then %do;
|
|
headers "Authorization"="Bearer &&&access_token_var";
|
|
%end;
|
|
run;
|
|
/*data _null_;infile &fname1;input;putlog _infile_;run;*/
|
|
libname &libref1 JSON fileref=&fname1;
|
|
/* now get the followon link to list members */
|
|
%local href;
|
|
%let href=0;
|
|
data _null_;
|
|
set &libref1..links;
|
|
if rel='members' then call symputx('href',quote("&base_uri"!!trim(href)),'l');
|
|
run;
|
|
%if &href=0 %then %do;
|
|
%put NOTE:;%put NOTE- No members found in &root!!;%put NOTE-;
|
|
%return;
|
|
%end;
|
|
%local fname2 libref2;
|
|
%let fname2=%mf_getuniquefileref();
|
|
%let libref2=%mf_getuniquelibref();
|
|
proc http method='GET' out=&fname2 &oauth_bearer
|
|
url=%unquote(%superq(href));
|
|
%if &grant_type=authorization_code %then %do;
|
|
headers "Authorization"="Bearer &&&access_token_var";
|
|
%end;
|
|
run;
|
|
libname &libref2 JSON fileref=&fname2;
|
|
data &outds;
|
|
set &libref2..items;
|
|
run;
|
|
filename &fname2 clear;
|
|
libname &libref2 clear;
|
|
%end;
|
|
|
|
|
|
/* clear refs */
|
|
filename &fname1 clear;
|
|
libname &libref1 clear;
|
|
|
|
%mend mv_getfoldermembers; |