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, source: https://github.com/sasjs/core
33 
34  <h4> SAS Macros </h4>
35  @li mp_abort.sas
36  @li mf_getplatform.sas
37  @li mf_getuniquefileref.sas
38  @li mf_getuniquelibref.sas
39  @li mf_loc.sas
40 
41 **/
42 
43 %macro mv_getclients(outds=work.mv_getclients
44 )/*/STORE SOURCE*/;
45 
46 options noquotelenmax;
47 %local base_uri; /* location of rest apis */
48 %let base_uri=%mf_getplatform(VIYARESTAPI);
49 
50 /* first, get consul token needed to get client id / secret */
51 data _null_;
52  infile "%mf_loc(VIYACONFIG)/etc/SASSecurityCertificateFramework/tokens/consul/default/client.token";
53  input token:$64.;
54  call symputx('consul_token',token);
55 run;
56 
57 /* request the client details */
58 %local fname1;
59 %let fname1=%mf_getuniquefileref();
60 proc http method='POST' out=&fname1
61  url="&base_uri/SASLogon/oauth/clients/consul?callback=false%str(&)serviceId=app";
62  headers "X-Consul-Token"="&consul_token";
63 run;
64 
65 %local libref1;
66 %let libref1=%mf_getuniquelibref();
67 libname &libref1 JSON fileref=&fname1;
68 
69 /* extract the token */
70 data _null_;
71  set &libref1..root;
72  call symputx('access_token',access_token,'l');
73 run;
74 
75 /* fetching folder details for provided path */
76 %local fname2;
77 %let fname2=%mf_getuniquefileref();
78 %let libref2=%mf_getuniquelibref();
79 
80 proc http method='GET' out=&fname2 oauth_bearer=sas_services
81  url="&base_uri/SASLogon/oauth/clients";
82  headers "Accept"="application/json";
83 run;
84 /*data _null_;infile &fname1;input;putlog _infile_;run;*/
85 %mp_abort(iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200)
86  ,mac=&sysmacroname
87  ,msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
88 )
89 libname &libref2 JSON fileref=&fname1;
90 
91 data &outds;
92  set &libref2..items;
93 run;
94 
95 
96 
97 /* clear refs
98 filename &fname1 clear;
99 libname &libref1 clear;
100 */
101 %mend;