mirror of
https://github.com/sasjs/core.git
synced 2026-01-03 15:40:05 +00:00
feat(*): recreate library as scoped package
This commit is contained in:
102
viya/mv_getclients.sas
Normal file
102
viya/mv_getclients.sas
Normal file
@@ -0,0 +1,102 @@
|
||||
/**
|
||||
@file mv_getgroups.sas
|
||||
@brief Creates a dataset with a list of viya groups
|
||||
@details First, be sure you have an access token (which requires an app token).
|
||||
|
||||
Using the macros here:
|
||||
|
||||
filename mc url
|
||||
"https://raw.githubusercontent.com/macropeople/macrocore/master/mc_all.sas";
|
||||
%inc mc;
|
||||
|
||||
An administrator needs to set you up with an access code:
|
||||
|
||||
%mv_registerclient(outds=client)
|
||||
|
||||
Navigate to the url from the log (opting in to the groups) and paste the
|
||||
access code below:
|
||||
|
||||
%mv_tokenauth(inds=client,code=wKDZYTEPK6)
|
||||
|
||||
Now we can run the macro!
|
||||
|
||||
%mv_getgroups()
|
||||
|
||||
@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.
|
||||
@param outds= The library.dataset to be created that contains the list of groups
|
||||
|
||||
|
||||
@version VIYA V.03.04
|
||||
@author Allan Bowe
|
||||
@source https://github.com/macropeople/macrocore
|
||||
|
||||
<h4> Dependencies </h4>
|
||||
@li mp_abort.sas
|
||||
@li mf_getplatform.sas
|
||||
@li mf_getuniquefileref.sas
|
||||
@li mf_getuniquelibref.sas
|
||||
@li mf_loc.sas
|
||||
|
||||
**/
|
||||
|
||||
%macro mv_getclients(outds=work.mv_getclients
|
||||
)/*/STORE SOURCE*/;
|
||||
|
||||
options noquotelenmax;
|
||||
%local base_uri; /* location of rest apis */
|
||||
%let base_uri=%mf_getplatform(VIYARESTAPI);
|
||||
|
||||
/* first, get consul token needed to get client id / secret */
|
||||
data _null_;
|
||||
infile "%mf_loc(VIYACONFIG)/etc/SASSecurityCertificateFramework/tokens/consul/default/client.token";
|
||||
input token:$64.;
|
||||
call symputx('consul_token',token);
|
||||
run;
|
||||
|
||||
/* request the client details */
|
||||
%local fname1;
|
||||
%let fname1=%mf_getuniquefileref();
|
||||
proc http method='POST' out=&fname1
|
||||
url="&base_uri/SASLogon/oauth/clients/consul?callback=false%str(&)serviceId=app";
|
||||
headers "X-Consul-Token"="&consul_token";
|
||||
run;
|
||||
|
||||
%local libref1;
|
||||
%let libref1=%mf_getuniquelibref();
|
||||
libname &libref1 JSON fileref=&fname1;
|
||||
|
||||
/* extract the token */
|
||||
data _null_;
|
||||
set &libref1..root;
|
||||
call symputx('access_token',access_token,'l');
|
||||
run;
|
||||
|
||||
/* fetching folder details for provided path */
|
||||
%local fname2;
|
||||
%let fname2=%mf_getuniquefileref();
|
||||
%let libref2=%mf_getuniquelibref();
|
||||
|
||||
proc http method='GET' out=&fname2 oauth_bearer=sas_services
|
||||
url="&base_uri/SASLogon/oauth/clients";
|
||||
headers "Accept"="application/json";
|
||||
run;
|
||||
/*data _null_;infile &fname1;input;putlog _infile_;run;*/
|
||||
%mp_abort(iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200)
|
||||
,mac=&sysmacroname
|
||||
,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
|
||||
)
|
||||
libname &libref2 JSON fileref=&fname1;
|
||||
|
||||
data &outds;
|
||||
set &libref2..items;
|
||||
run;
|
||||
|
||||
|
||||
|
||||
/* clear refs
|
||||
filename &fname1 clear;
|
||||
libname &libref1 clear;
|
||||
*/
|
||||
%mend;
|
||||
Reference in New Issue
Block a user