Hi all,
Is it possible to use scripts like this https://support.sas.com/documentation/cdl/en/lrmeta/63180/HTML/default/viewer.htm#p1k9zipe59ha2an1pq... to export metadata information in SAS Viya?
Thank you in advance!
Hi @JM7
There is no concept of Metadata server in Viya. It uses configuration server based on consul to store most of the information related to platform.
Hi Greg,
Thank you for your answer.
I need information related with user access, user roles and groups as you can see with Metadata
Thanks
The Identities service can surface user and group information that it pulls from LDAP. For example, /identities/users returns a list of users.
This example code connects to Viya and pulls from identities a list of user ids, user names, phone number and email, but you could similarly pull a list of groups (/identities/groups) and then for each group pull a list of members (/identities/groups/<group_id>/members)
There isn't really a concept of roles in Viya, but you can drive capabilities based on rules and group memberships.
/* Specify host and logon credentials. */
%let username=%nrstr(sasdemo);
%let pwd=%nrstr(password);
%let baseurl=http://viya.demo.sas.com;
/* Correct username and password for URL encoding special characters. */
%let username=%sysfunc(urlencode(&username));
%let pwd=%sysfunc(urlencode(&pwd));
/* Set a response limit. */
%let limit=100;
%let serviceurl=/identities/users/;
/* Init some files for the PROC HTTP output. */
filename headout temp;
filename resp temp;
filename outref temp;
/* Get an authentication token. */
proc http url="&baseurl/SASLogon/oauth/token" in="grant_type=password%nrstr(&username)=&username.%nrstr(&password)=&pwd" out=resp headerout=headout HEADEROUT_OVERWRITE webusername="sas.ec" webpassword="";
headers "Accept"="application/json";
run;
libname resp;
/* Read in the response */
libname resp json fileref=resp;
/* Set the access token in the response to a macro variable. */
data _null_;
set resp.alldata;
if P1="access_token" then call symput("bearer",trim(value));
run;
/* Use this new token for authentication to the service URL. */
proc http url="&baseurl.&serviceurl%nrstr(?limit=)&limit"
out=outref headerout=headout HEADEROUT_OVERWRITE;
headers "Authorization"="Bearer &bearer" "Accept"="application/json";
run;
/* Clear the library assignment for def if present. */
libname def;
/* Read in the response from the service URL using the JSON libname engine. */
libname def json fileref=outref;
%macro pullident;
/* Read the total number of identities and each id into macro variables. */
proc sql noprint;
select count(*) into :nident from def.items;
quit;
%put INFO: Found %trim(&nident) identities.;
%if &nident > 0 %then %do;
proc sql noprint;
select id into:id1-:id%left(&nident) from def.items;
quit;
%end;
%else;
/* For each identity found, hit the identities REST endpoint for that ID. */
/* Define and empty the dataset where we will put all the identities and their attributes. */
data work.identities;
length id name email phone $ 255;
call missing (of _character_);
if compress(cats(of _all_),'.')=' ' then delete;
run;
/* For each identity found, pull the identities endpoint for that identity. */
%do i=1 %to &nident;
proc http url="&baseurl.&serviceurl.&&id&i"
out=outref headerout=headout HEADEROUT_OVERWRITE;
headers "Authorization"="Bearer &bearer" "Accept"="application/json";
run;
/* Clear the library assignment for ID if already present, and assign to the output of the PROC HTTP call. */
libname id ;
libname id json fileref=outref;
/* Pull the desired values from the output into macro variables. As there can be multiple emails/phones per user, this only gets the first one (V=1). */
data _null_;
set id.alldata;
if P1="id" then call symput("id&i",value);
if P1="name" then call symput("name&i",value);
if P1="emailAddresses" and P2="value" and V="1" then call symput("email&i",value);
if P1="phoneNumbers" and P2="value" and V="1" then call symput("phone&i",value);
run;
/* Write the values to the log. */
%put ID&i = &&id&i;
%put Name&i = &&name&i;
%if %symexist(phone&i) %then %put Phone&i = &&phone&i;
%if %symexist(email&i) %then %put Email&i = &&email&i;
/* Create a one observation data set for each identity with the values. */
data ident&i;
length id name email phone $ 255;
call missing (of _character_);
id="&&id&i";
name="&&name&i";
%if %symexist(email&i) %then email="&&email&i";;
%if %symexist(phone&i) %then phone="&&phone&i";;
run;
/* Append that to the main dataset for all values. */
proc sql;
insert into work.identities select * from work.ident&i;
quit;
proc delete data=ident&i; run;
%end;
/* Print the data set of all values. */
proc print data=work.identities; run;
%mend;
/* Run the macro. */
%pullident;
@gwootton is it possible to expand this SAS code with user groups ?
The SAS Users Group for Administrators (SUGA) is open to all SAS administrators and architects who install, update, manage or maintain a SAS deployment.
SAS technical trainer Erin Winters shows you how to explore assets, create new data discovery agents, schedule data discovery agents, and much more.
Find more tutorials on the SAS Users YouTube channel.