mirror of
https://github.com/sasjs/core.git
synced 2026-01-07 01:20:05 +00:00
Merge pull request #175 from sasjs/authbranch
fix: tidyup of mm_getauthinfo.sas
This commit is contained in:
99
all.sas
99
all.sas
@@ -15177,17 +15177,22 @@ run;
|
|||||||
%mend mm_deletestp;
|
%mend mm_deletestp;
|
||||||
/**
|
/**
|
||||||
@file mm_getauthinfo.sas
|
@file mm_getauthinfo.sas
|
||||||
@brief extracts authentication info
|
@brief Extracts authentication info for each user in metadata
|
||||||
@details usage:
|
@details
|
||||||
|
Usage:
|
||||||
|
|
||||||
%mm_getauthinfo(outds=auths)
|
%mm_getauthinfo(outds=auths)
|
||||||
|
|
||||||
@param outds= the ONE LEVEL work dataset to create
|
|
||||||
|
@param [in] mdebug= (0) Set to 1 to enable DEBUG messages and preserve outputs
|
||||||
|
@param [out] outds= (mm_getauthinfo) The output dataset to create
|
||||||
|
|
||||||
<h4> SAS Macros </h4>
|
<h4> SAS Macros </h4>
|
||||||
@li mm_getobjects.sas
|
|
||||||
@li mf_getuniquefileref.sas
|
@li mf_getuniquefileref.sas
|
||||||
|
@li mf_getuniquename.sas
|
||||||
@li mm_getdetails.sas
|
@li mm_getdetails.sas
|
||||||
|
@li mm_getobjects.sas
|
||||||
|
|
||||||
|
|
||||||
@version 9.4
|
@version 9.4
|
||||||
@author Allan Bowe
|
@author Allan Bowe
|
||||||
@@ -15195,67 +15200,69 @@ run;
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
%macro mm_getauthinfo(outds=mm_getauthinfo
|
%macro mm_getauthinfo(outds=mm_getauthinfo
|
||||||
|
,mdebug=0
|
||||||
)/*/STORE SOURCE*/;
|
)/*/STORE SOURCE*/;
|
||||||
|
%local prefix fileref;
|
||||||
|
%let prefix=%substr(%mf_getuniquename(),1,25);
|
||||||
|
|
||||||
%if %length(&outds)>30 %then %do;
|
%mm_getobjects(type=Login,outds=&prefix.0)
|
||||||
%put %str(ERR)OR: Temp tables are created with the &outds prefix, which
|
|
||||||
therefore needs to be 30 characters or less;
|
|
||||||
%return;
|
|
||||||
%end;
|
|
||||||
%if %index(&outds,'.')>0 %then %do;
|
|
||||||
%put %str(ERR)OR: Table &outds should be ONE LEVEL (no library);
|
|
||||||
%return;
|
|
||||||
%end;
|
|
||||||
|
|
||||||
%mm_getobjects(type=Login,outds=&outds.0)
|
|
||||||
|
|
||||||
%local fileref;
|
%local fileref;
|
||||||
%let fileref=%mf_getuniquefileref();
|
%let fileref=%mf_getuniquefileref();
|
||||||
|
|
||||||
data _null_;
|
data _null_;
|
||||||
file &fileref;
|
file &fileref;
|
||||||
set &outds.0 end=last;
|
set &prefix.0 end=last;
|
||||||
/* run macro */
|
/* run macro */
|
||||||
str=cats('%mm_getdetails(uri=',id,",outattrs=&outds.d",_n_
|
str=cats('%mm_getdetails(uri=',id,",outattrs=&prefix.d",_n_
|
||||||
,",outassocs=&outds.a",_n_,")");
|
,",outassocs=&prefix.a",_n_,")");
|
||||||
put str;
|
put str;
|
||||||
/* transpose attributes */
|
/* transpose attributes */
|
||||||
str=cats("proc transpose data=&outds.d",_n_,"(drop=type) out=&outds.da"
|
str=cats("proc transpose data=&prefix.d",_n_,"(drop=type) out=&prefix.da"
|
||||||
,_n_,"(drop=_name_);var value;id name;run;");
|
,_n_,"(drop=_name_);var value;id name;run;");
|
||||||
put str;
|
put str;
|
||||||
/* add extra info to attributes */
|
/* add extra info to attributes */
|
||||||
str=cats("data &outds.da",_n_,";length login_id login_name $256; login_id="
|
str=cats("data &prefix.da",_n_,";length login_id login_name $256; login_id="
|
||||||
,quote(trim(id)),";set &outds.da",_n_
|
,quote(trim(id)),";set &prefix.da",_n_
|
||||||
,";login_name=trim(subpad(name,1,256));drop name;run;");
|
,";login_name=trim(subpad(name,1,256));drop name;run;");
|
||||||
put str;
|
put str;
|
||||||
/* add extra info to associations */
|
/* add extra info to associations */
|
||||||
str=cats("data &outds.a",_n_,";length login_id login_name $256; login_id="
|
str=cats("data &prefix.a",_n_,";length login_id login_name $256; login_id="
|
||||||
,quote(trim(id)),";login_name=",quote(trim(name))
|
,quote(trim(id)),";login_name=",quote(trim(name))
|
||||||
,";set &outds.a",_n_,";run;");
|
,";set &prefix.a",_n_,";run;");
|
||||||
put str;
|
put str;
|
||||||
if last then do;
|
if last then do;
|
||||||
/* collate attributes */
|
/* collate attributes */
|
||||||
str=cats("data &outds._logat; set &outds.da1-&outds.da",_n_,";run;");
|
str=cats("data &prefix._logat; set &prefix.da1-&prefix.da",_n_,";run;");
|
||||||
put str;
|
put str;
|
||||||
/* collate associations */
|
/* collate associations */
|
||||||
str=cats("data &outds._logas; set &outds.a1-&outds.a",_n_,";run;");
|
str=cats("data &prefix._logas; set &prefix.a1-&prefix.a",_n_,";run;");
|
||||||
put str;
|
put str;
|
||||||
/* tidy up */
|
/* tidy up */
|
||||||
str=cats("proc delete data=&outds.da1-&outds.da",_n_,";run;");
|
str=cats("proc delete data=&prefix.da1-&prefix.da",_n_,";run;");
|
||||||
put str;
|
put str;
|
||||||
str=cats("proc delete data=&outds.d1-&outds.d",_n_,";run;");
|
str=cats("proc delete data=&prefix.d1-&prefix.d",_n_,";run;");
|
||||||
put str;
|
put str;
|
||||||
str=cats("proc delete data=&outds.a1-&outds.a",_n_,";run;");
|
str=cats("proc delete data=&prefix.a1-&prefix.a",_n_,";run;");
|
||||||
put str;
|
put str;
|
||||||
end;
|
end;
|
||||||
run;
|
run;
|
||||||
|
|
||||||
|
%if &mdebug=1 %then %do;
|
||||||
|
data _null_;
|
||||||
|
infile &fileref;
|
||||||
|
if _n_=1 then putlog // "Now executing the following code:" //;
|
||||||
|
input; putlog _infile_;
|
||||||
|
run;
|
||||||
|
%end;
|
||||||
%inc &fileref;
|
%inc &fileref;
|
||||||
|
filename &fileref clear;
|
||||||
|
|
||||||
/* get libraries */
|
/* get libraries */
|
||||||
proc sort data=&outds._logas(where=(assoc='Libraries')) out=&outds._temp;
|
proc sort data=&prefix._logas(where=(assoc='Libraries')) out=&prefix._temp;
|
||||||
by login_id;
|
by login_id;
|
||||||
data &outds._temp;
|
data &prefix._temp;
|
||||||
set &outds._temp;
|
set &prefix._temp;
|
||||||
by login_id;
|
by login_id;
|
||||||
length library_list $32767;
|
length library_list $32767;
|
||||||
retain library_list;
|
retain library_list;
|
||||||
@@ -15263,32 +15270,28 @@ data &outds._temp;
|
|||||||
else library_list=catx(' !! ',library_list,name);
|
else library_list=catx(' !! ',library_list,name);
|
||||||
proc sql;
|
proc sql;
|
||||||
/* get auth domain */
|
/* get auth domain */
|
||||||
create table &outds._dom as
|
create table &prefix._dom as
|
||||||
select login_id,name as domain
|
select login_id,name as domain
|
||||||
from &outds._logas
|
from &prefix._logas
|
||||||
where assoc='Domain';
|
where assoc='Domain';
|
||||||
create unique index login_id on &outds._dom(login_id);
|
create unique index login_id on &prefix._dom(login_id);
|
||||||
/* join it all together */
|
/* join it all together */
|
||||||
create table &outds._logins as
|
create table &outds as
|
||||||
select a.*
|
select a.*
|
||||||
,c.domain
|
,c.domain
|
||||||
,b.library_list
|
,b.library_list
|
||||||
from &outds._logat (drop=ishidden lockedby usageversion publictype) a
|
from &prefix._logat (drop=ishidden lockedby usageversion publictype) a
|
||||||
left join &outds._temp b
|
left join &prefix._temp b
|
||||||
on a.login_id=b.login_id
|
on a.login_id=b.login_id
|
||||||
left join &outds._dom c
|
left join &prefix._dom c
|
||||||
on a.login_id=c.login_id;
|
on a.login_id=c.login_id;
|
||||||
drop table &outds._temp;
|
|
||||||
drop table &outds._logat;
|
|
||||||
drop table &outds._logas;
|
|
||||||
|
|
||||||
data _null_;
|
%if &mdebug=0 %then %do;
|
||||||
infile &fileref;
|
proc datasets lib=work;
|
||||||
if _n_=1 then putlog // "Now executing the following code:" //;
|
delete &prefix:;
|
||||||
input; putlog _infile_;
|
run;
|
||||||
run;
|
%end;
|
||||||
|
|
||||||
filename &fileref clear;
|
|
||||||
|
|
||||||
%mend mm_getauthinfo;/**
|
%mend mm_getauthinfo;/**
|
||||||
@file
|
@file
|
||||||
|
|||||||
@@ -1,16 +1,21 @@
|
|||||||
/**
|
/**
|
||||||
@file mm_getauthinfo.sas
|
@file mm_getauthinfo.sas
|
||||||
@brief extracts authentication info
|
@brief Extracts authentication info for each user in metadata
|
||||||
@details usage:
|
@details
|
||||||
|
Usage:
|
||||||
|
|
||||||
%mm_getauthinfo(outds=auths)
|
%mm_getauthinfo(outds=auths)
|
||||||
|
|
||||||
@param outds= the ONE LEVEL work dataset to create
|
|
||||||
|
@param [in] mdebug= (0) Set to 1 to enable DEBUG messages and preserve outputs
|
||||||
|
@param [out] outds= (mm_getauthinfo) The output dataset to create
|
||||||
|
|
||||||
<h4> SAS Macros </h4>
|
<h4> SAS Macros </h4>
|
||||||
@li mm_getobjects.sas
|
|
||||||
@li mf_getuniquefileref.sas
|
@li mf_getuniquefileref.sas
|
||||||
|
@li mf_getuniquename.sas
|
||||||
@li mm_getdetails.sas
|
@li mm_getdetails.sas
|
||||||
|
@li mm_getobjects.sas
|
||||||
|
|
||||||
|
|
||||||
@version 9.4
|
@version 9.4
|
||||||
@author Allan Bowe
|
@author Allan Bowe
|
||||||
@@ -18,67 +23,69 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
%macro mm_getauthinfo(outds=mm_getauthinfo
|
%macro mm_getauthinfo(outds=mm_getauthinfo
|
||||||
|
,mdebug=0
|
||||||
)/*/STORE SOURCE*/;
|
)/*/STORE SOURCE*/;
|
||||||
|
%local prefix fileref;
|
||||||
|
%let prefix=%substr(%mf_getuniquename(),1,25);
|
||||||
|
|
||||||
%if %length(&outds)>30 %then %do;
|
%mm_getobjects(type=Login,outds=&prefix.0)
|
||||||
%put %str(ERR)OR: Temp tables are created with the &outds prefix, which
|
|
||||||
therefore needs to be 30 characters or less;
|
|
||||||
%return;
|
|
||||||
%end;
|
|
||||||
%if %index(&outds,'.')>0 %then %do;
|
|
||||||
%put %str(ERR)OR: Table &outds should be ONE LEVEL (no library);
|
|
||||||
%return;
|
|
||||||
%end;
|
|
||||||
|
|
||||||
%mm_getobjects(type=Login,outds=&outds.0)
|
|
||||||
|
|
||||||
%local fileref;
|
%local fileref;
|
||||||
%let fileref=%mf_getuniquefileref();
|
%let fileref=%mf_getuniquefileref();
|
||||||
|
|
||||||
data _null_;
|
data _null_;
|
||||||
file &fileref;
|
file &fileref;
|
||||||
set &outds.0 end=last;
|
set &prefix.0 end=last;
|
||||||
/* run macro */
|
/* run macro */
|
||||||
str=cats('%mm_getdetails(uri=',id,",outattrs=&outds.d",_n_
|
str=cats('%mm_getdetails(uri=',id,",outattrs=&prefix.d",_n_
|
||||||
,",outassocs=&outds.a",_n_,")");
|
,",outassocs=&prefix.a",_n_,")");
|
||||||
put str;
|
put str;
|
||||||
/* transpose attributes */
|
/* transpose attributes */
|
||||||
str=cats("proc transpose data=&outds.d",_n_,"(drop=type) out=&outds.da"
|
str=cats("proc transpose data=&prefix.d",_n_,"(drop=type) out=&prefix.da"
|
||||||
,_n_,"(drop=_name_);var value;id name;run;");
|
,_n_,"(drop=_name_);var value;id name;run;");
|
||||||
put str;
|
put str;
|
||||||
/* add extra info to attributes */
|
/* add extra info to attributes */
|
||||||
str=cats("data &outds.da",_n_,";length login_id login_name $256; login_id="
|
str=cats("data &prefix.da",_n_,";length login_id login_name $256; login_id="
|
||||||
,quote(trim(id)),";set &outds.da",_n_
|
,quote(trim(id)),";set &prefix.da",_n_
|
||||||
,";login_name=trim(subpad(name,1,256));drop name;run;");
|
,";login_name=trim(subpad(name,1,256));drop name;run;");
|
||||||
put str;
|
put str;
|
||||||
/* add extra info to associations */
|
/* add extra info to associations */
|
||||||
str=cats("data &outds.a",_n_,";length login_id login_name $256; login_id="
|
str=cats("data &prefix.a",_n_,";length login_id login_name $256; login_id="
|
||||||
,quote(trim(id)),";login_name=",quote(trim(name))
|
,quote(trim(id)),";login_name=",quote(trim(name))
|
||||||
,";set &outds.a",_n_,";run;");
|
,";set &prefix.a",_n_,";run;");
|
||||||
put str;
|
put str;
|
||||||
if last then do;
|
if last then do;
|
||||||
/* collate attributes */
|
/* collate attributes */
|
||||||
str=cats("data &outds._logat; set &outds.da1-&outds.da",_n_,";run;");
|
str=cats("data &prefix._logat; set &prefix.da1-&prefix.da",_n_,";run;");
|
||||||
put str;
|
put str;
|
||||||
/* collate associations */
|
/* collate associations */
|
||||||
str=cats("data &outds._logas; set &outds.a1-&outds.a",_n_,";run;");
|
str=cats("data &prefix._logas; set &prefix.a1-&prefix.a",_n_,";run;");
|
||||||
put str;
|
put str;
|
||||||
/* tidy up */
|
/* tidy up */
|
||||||
str=cats("proc delete data=&outds.da1-&outds.da",_n_,";run;");
|
str=cats("proc delete data=&prefix.da1-&prefix.da",_n_,";run;");
|
||||||
put str;
|
put str;
|
||||||
str=cats("proc delete data=&outds.d1-&outds.d",_n_,";run;");
|
str=cats("proc delete data=&prefix.d1-&prefix.d",_n_,";run;");
|
||||||
put str;
|
put str;
|
||||||
str=cats("proc delete data=&outds.a1-&outds.a",_n_,";run;");
|
str=cats("proc delete data=&prefix.a1-&prefix.a",_n_,";run;");
|
||||||
put str;
|
put str;
|
||||||
end;
|
end;
|
||||||
run;
|
run;
|
||||||
|
|
||||||
|
%if &mdebug=1 %then %do;
|
||||||
|
data _null_;
|
||||||
|
infile &fileref;
|
||||||
|
if _n_=1 then putlog // "Now executing the following code:" //;
|
||||||
|
input; putlog _infile_;
|
||||||
|
run;
|
||||||
|
%end;
|
||||||
%inc &fileref;
|
%inc &fileref;
|
||||||
|
filename &fileref clear;
|
||||||
|
|
||||||
/* get libraries */
|
/* get libraries */
|
||||||
proc sort data=&outds._logas(where=(assoc='Libraries')) out=&outds._temp;
|
proc sort data=&prefix._logas(where=(assoc='Libraries')) out=&prefix._temp;
|
||||||
by login_id;
|
by login_id;
|
||||||
data &outds._temp;
|
data &prefix._temp;
|
||||||
set &outds._temp;
|
set &prefix._temp;
|
||||||
by login_id;
|
by login_id;
|
||||||
length library_list $32767;
|
length library_list $32767;
|
||||||
retain library_list;
|
retain library_list;
|
||||||
@@ -86,31 +93,27 @@ data &outds._temp;
|
|||||||
else library_list=catx(' !! ',library_list,name);
|
else library_list=catx(' !! ',library_list,name);
|
||||||
proc sql;
|
proc sql;
|
||||||
/* get auth domain */
|
/* get auth domain */
|
||||||
create table &outds._dom as
|
create table &prefix._dom as
|
||||||
select login_id,name as domain
|
select login_id,name as domain
|
||||||
from &outds._logas
|
from &prefix._logas
|
||||||
where assoc='Domain';
|
where assoc='Domain';
|
||||||
create unique index login_id on &outds._dom(login_id);
|
create unique index login_id on &prefix._dom(login_id);
|
||||||
/* join it all together */
|
/* join it all together */
|
||||||
create table &outds._logins as
|
create table &outds as
|
||||||
select a.*
|
select a.*
|
||||||
,c.domain
|
,c.domain
|
||||||
,b.library_list
|
,b.library_list
|
||||||
from &outds._logat (drop=ishidden lockedby usageversion publictype) a
|
from &prefix._logat (drop=ishidden lockedby usageversion publictype) a
|
||||||
left join &outds._temp b
|
left join &prefix._temp b
|
||||||
on a.login_id=b.login_id
|
on a.login_id=b.login_id
|
||||||
left join &outds._dom c
|
left join &prefix._dom c
|
||||||
on a.login_id=c.login_id;
|
on a.login_id=c.login_id;
|
||||||
drop table &outds._temp;
|
|
||||||
drop table &outds._logat;
|
|
||||||
drop table &outds._logas;
|
|
||||||
|
|
||||||
data _null_;
|
%if &mdebug=0 %then %do;
|
||||||
infile &fileref;
|
proc datasets lib=work;
|
||||||
if _n_=1 then putlog // "Now executing the following code:" //;
|
delete &prefix:;
|
||||||
input; putlog _infile_;
|
run;
|
||||||
run;
|
%end;
|
||||||
|
|
||||||
filename &fileref clear;
|
|
||||||
|
|
||||||
%mend mm_getauthinfo;
|
%mend mm_getauthinfo;
|
||||||
21
tests/sas9only/mm_getauthinfo.test.sas
Normal file
21
tests/sas9only/mm_getauthinfo.test.sas
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
/**
|
||||||
|
@file
|
||||||
|
@brief Testing mm_getauthinfo macro
|
||||||
|
|
||||||
|
<h4> SAS Macros </h4>
|
||||||
|
@li mf_existds.sas
|
||||||
|
@li mm_getauthinfo.sas
|
||||||
|
@li mp_assertscope.sas
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
|
||||||
|
%mp_assertscope(SNAPSHOT)
|
||||||
|
%mm_getauthinfo(outds=auths)
|
||||||
|
%mp_assertscope(COMPARE)
|
||||||
|
|
||||||
|
|
||||||
|
%mp_assert(
|
||||||
|
iftrue=(%mf_existds(work.auths)=1),
|
||||||
|
desc=Check if the auths dataset was created
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user