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