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