Production Ready Macros for SAS Application Developers
https://github.com/sasjs/core
mv_getclients.sas
Go to the documentation of this file.
1 /**
2  @file mv_getclients.sas
3  @brief Get a list of Viya Clients
4  @details First, be sure you have an access token (which requires an app token).
5 
6  Using the macros here:
7 
8  filename mc url
9  "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
10  %inc mc;
11 
12  An administrator needs to set you up with an access code:
13 
14  %mv_registerclient(outds=client)
15 
16  Navigate to the url from the log (opting in to the groups) and paste the
17  access code below:
18 
19  %mv_tokenauth(inds=client,code=wKDZYTEPK6)
20 
21  Now we can run the macro!
22 
23  %mv_getclients()
24 
25  @param access_token_var= The global macro variable to contain the access token
26  @param grant_type= valid values are "password" or "authorization_code" (unquoted).
27  The default is authorization_code.
28  @param outds= The library.dataset to be created that contains the list of groups
29 
30 
31  @version VIYA V.03.04
32  @author Allan Bowe
33  @source https://github.com/sasjs/core
34 
35  <h4> Dependencies </h4>
36  @li mp_abort.sas
37  @li mf_getplatform.sas
38  @li mf_getuniquefileref.sas
39  @li mf_getuniquelibref.sas
40  @li mf_loc.sas
41 
42 **/
43 
44 %macro mv_getclients(outds=work.mv_getclients
45 )/*/STORE SOURCE*/;
46 
47 options noquotelenmax;
48 %local base_uri; /* location of rest apis */
49 %let base_uri=%mf_getplatform(VIYARESTAPI);
50 
51 /* first, get consul token needed to get client id / secret */
52 data _null_;
53  infile "%mf_loc(VIYACONFIG)/etc/SASSecurityCertificateFramework/tokens/consul/default/client.token";
54  input token:$64.;
55  call symputx('consul_token',token);
56 run;
57 
58 /* request the client details */
59 %local fname1;
60 %let fname1=%mf_getuniquefileref();
61 proc http method='POST' out=&fname1
62  url="&base_uri/SASLogon/oauth/clients/consul?callback=false%str(&)serviceId=app";
63  headers "X-Consul-Token"="&consul_token";
64 run;
65 
66 %local libref1;
67 %let libref1=%mf_getuniquelibref();
68 libname &libref1 JSON fileref=&fname1;
69 
70 /* extract the token */
71 data _null_;
72  set &libref1..root;
73  call symputx('access_token',access_token,'l');
74 run;
75 
76 /* fetching folder details for provided path */
77 %local fname2;
78 %let fname2=%mf_getuniquefileref();
79 %let libref2=%mf_getuniquelibref();
80 
81 proc http method='GET' out=&fname2 oauth_bearer=sas_services
82  url="&base_uri/SASLogon/oauth/clients";
83  headers "Accept"="application/json";
84 run;
85 /*data _null_;infile &fname1;input;putlog _infile_;run;*/
86 %mp_abort(iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200)
87  ,mac=&sysmacroname
88  ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
89 )
90 libname &libref2 JSON fileref=&fname1;
91 
92 data &outds;
93  set &libref2..items;
94 run;
95 
96 
97 
98 /* clear refs
99 filename &fname1 clear;
100 libname &libref1 clear;
101 */
102 %mend;