Guest User

Untitled

a guest
Feb 20th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.53 KB | None | 0 0
  1. /************************************************************
  2. Author Nicolas Housset
  3. /******************************************/
  4.  
  5.  
  6.  
  7. %macro getMetaInfos(EXCELFILE,OUTPUTFORMAT);
  8. data metadata_libraries;
  9. length uri serveruri conn_uri domainuri libname ServerContext AuthDomain path_schema
  10. usingpkguri type tableuri coluri $256 id $17
  11. desc $200 libref engine $8 isDBMS $1 DomainLogin $32;
  12. keep libname desc libref engine ServerContext path_schema AuthDomain table colname
  13. coltype collen IsPreassigned IsDBMSLibname id;
  14. nobj=.;
  15. n=1;
  16. uri='';
  17. serveruri='';
  18. conn_uri='';
  19. domainuri='';
  20.  
  21. /***Determine how many libraries there are***/
  22. nobj=metadata_getnobj("omsobj:SASLibrary?@Id contains '.'",n,uri);
  23. /***Retrieve the attributes for all libraries, if there are any***/
  24. if n>0 then do n=1 to nobj;
  25. libname='';
  26. ServerContext='';
  27. AuthDomain='';
  28. desc='';
  29. libref='';
  30. engine='';
  31. isDBMS='';
  32. IsPreassigned='';
  33. IsDBMSLibname='';
  34. path_schema='';
  35. usingpkguri='';
  36. type='';
  37. id='';
  38. nobj=metadata_getnobj("omsobj:SASLibrary?@Id contains '.'",n,uri);
  39. rc= metadata_getattr(uri, "Name", libname);
  40. rc= metadata_getattr(uri, "Desc", desc);
  41. rc= metadata_getattr(uri, "Libref", libref);
  42. rc= metadata_getattr(uri, "Engine", engine);
  43. rc= metadata_getattr(uri, "IsDBMSLibname", isDBMS);
  44. rc= metadata_getattr(uri, "IsDBMSLibname", IsDBMSLibname);
  45. rc= metadata_getattr(uri, "IsPreassigned", IsPreassigned);
  46. rc= metadata_getattr(uri, "Id", Id);
  47.  
  48. /*** Get associated ServerContext ***/
  49. i=1;
  50. rc= metadata_getnasn(uri, "DeployedComponents", i, serveruri);
  51. if rc > 0 then rc2= metadata_getattr(serveruri, "Name", ServerContext);
  52. else ServerContext='';
  53.  
  54. /*** If the library is a DBMS library, get the Authentication Domain
  55. associated with the DBMS connection credentials ***/
  56. if isDBMS="1" then do;
  57. i=1;
  58. rc= metadata_getnasn(uri, "LibraryConnection", i, conn_uri);
  59. if rc > 0 then do;
  60. rc2= metadata_getnasn(conn_uri, "Domain", i, domainuri);
  61.  
  62.  
  63. if rc2 > 0 then rc3= metadata_getattr(domainuri, "Name", AuthDomain);
  64. end;
  65. end;
  66.  
  67. /*** Get the path/database schema for this library ***/
  68. rc=metadata_getnasn(uri, "UsingPackages", 1, usingpkguri);
  69. if rc>0 then do;
  70. rc=metadata_resolve(usingpkguri,type,id);
  71. if type='Directory' then
  72. rc=metadata_getattr(usingpkguri, "DirectoryName", path_schema);
  73. else if type='DatabaseSchema' then
  74. rc=metadata_getattr(usingpkguri, "Name", path_schema);
  75. else path_schema="unknown";
  76. end;
  77.  
  78. output;
  79.  
  80. end;
  81.  
  82. run;
  83.  
  84. data work.Libraries;
  85. length LibId LibName $ 32 LibRef LibEngine $ 8 LibPath $ 256 ServerContext uri uri2 type $ 256 server $ 32 ;
  86. label
  87. LibId = "ID"
  88. LibName = "Nom"
  89. LibRef = "Libref"
  90. LibEngine = "Moteur"
  91. ServerContext = "Serveur"
  92. LibPath = "Path";
  93.  
  94. call missing(LibId,LibName,LibRef,LibEngine,LibPath,ServerContext,uri,uri2,type,server);
  95. n=1;
  96. n2=1;
  97.  
  98. rc=metadata_getnobj("omsobj:SASLibrary?@Id contains '.'",n,uri);
  99. if rc<=0 then put "NOTE: rc=" rc
  100. "There are no Libraries defined in this repository"
  101. " or there was an error reading the repository.";
  102.  
  103. do while(rc>0);
  104. objrc=metadata_getattr(uri,"Id",LibId);
  105. objrc=metadata_getattr(uri,"Name",LibName);
  106. objrc=metadata_getattr(uri,"Libref",LibRef);
  107. objrc=metadata_getattr(uri,"Engine",LibEngine);
  108. objrc=metadata_getnasn(uri,"DeployedComponents",n2,uri2);
  109. if objrc<=0 then
  110. do;
  111. put "NOTE: There is no DeployedComponents association for "
  112. LibName +(-1)", and therefore no server context.";
  113. ServerContext="";
  114. end;
  115.  
  116. do while(objrc>0);
  117. objrc=metadata_getattr(uri2,"Name",server);
  118. if n2=1 then ServerContext=quote(trim(server));
  119. else ServerContext=trim(ServerContext)||" "||quote(trim(server));
  120. n2+1;
  121. objrc=metadata_getnasn(uri,"DeployedComponents",n2,uri2);
  122. end;
  123. n2=1;
  124. objrc=metadata_getnasn(uri,"UsingPackages",n2,uri2);
  125. if objrc<=0 then
  126. do;
  127. put "NOTE: There is no UsingPackages association for "
  128. LibName +(-1)", and therefore no Path.";
  129. LibPath="";
  130. end;
  131.  
  132. do while(objrc>0);
  133. objrc=metadata_resolve(uri2,type,id);
  134. if type='Directory' then objrc=metadata_getattr(uri2,"DirectoryName",LibPath);
  135. else if type='DatabaseSchema' then objrc=metadata_getattr(uri2, "Name", LibPath);
  136. else LibPath="*unknown*";
  137. output;
  138. LibPath="";
  139. n2+1;
  140. objrc=metadata_getnasn(uri,"UsingPackages",n2,uri2);
  141. end;
  142. ServerContext="";
  143. n+1;
  144. n2=1;
  145. rc=metadata_getnobj("omsobj:SASLibrary?@Id contains '.'",n,uri);
  146. end;
  147.  
  148. keep
  149. LibName
  150. LibRef
  151. LibEngine
  152. ServerContext
  153. LibPath
  154. LibId;
  155. run;
  156.  
  157.  
  158. data logins;
  159.  
  160.  
  161. length LoginObjId UserId IdentId AuthDomId $ 17
  162. IdentType $ 32
  163. Name DispName Desc uri uri2 uri3 AuthDomName $ 256;
  164.  
  165. call missing
  166. (LoginObjId, UserId, IdentType, IdentId, Name, DispName, Desc, AuthDomId, AuthDomName);
  167. call missing(uri, uri2, uri3);
  168. n=1;
  169.  
  170.  
  171. objrc=metadata_getnobj("omsobj:Login?@Id contains '.'",n,uri);
  172. if objrc<=0 then put "NOTE: rc=" objrc
  173. "There are no Logins defined in this repository"
  174. " or there was an error reading the repository.";
  175.  
  176. do while(objrc>0);
  177. arc=metadata_getattr(uri,"Id",LoginObjId);
  178. arc=metadata_getattr(uri,"UserId",UserId);
  179.  
  180.  
  181.  
  182. n2=1;
  183. asnrc=metadata_getnasn(uri,"AssociatedIdentity",n2,uri2);
  184. if asnrc<=0 then put "NOTE: rc=" asnrc
  185. "There is no Person or Group associated with the " UserId "user ID.";
  186.  
  187.  
  188.  
  189. else do;
  190. arc=metadata_resolve(uri2,IdentType,IdentId);
  191.  
  192.  
  193.  
  194. arc=metadata_getattr(uri2,"Name",Name);
  195. arc=metadata_getattr(uri2,"DisplayName",DispName);
  196. arc=metadata_getattr(uri2,"Desc",Desc);
  197. end;
  198.  
  199.  
  200. n3=1;
  201. autrc=metadata_getnasn(uri,"Domain",n3,uri3);
  202. if autrc<=0 then put "NOTE: rc=" autrc
  203. "There is no Authentication Domain associated with the " UserId "user ID.";
  204.  
  205.  
  206. else do;
  207. arc=metadata_getattr(uri3,"Id",AuthDomId);
  208. arc=metadata_getattr(uri3,"Name",AuthDomName);
  209.  
  210. end;
  211.  
  212. output;
  213.  
  214.  
  215. call missing(LoginObjId, UserId, IdentType, IdentId, Name, DispName, Desc, AuthDomId,
  216. AuthDomName);
  217.  
  218. n+1;
  219. objrc=metadata_getnobj("omsobj:Login?@Id contains '.'",n,uri);
  220. end;
  221.  
  222.  
  223.  
  224. keep LoginObjId UserId IdentType Name DispName Desc AuthDomId AuthDomName;
  225. run;
  226.  
  227.  
  228. data users_grps;
  229. length uri name group groupuri $256 id $20;
  230.  
  231. /* Initialize variables to missing. */
  232. n=1;
  233. uri='';
  234. name='';
  235. group='';
  236. groupuri='';
  237. id='';
  238.  
  239. /* Determine how many person objects are defined. */
  240. nobj=metadata_getnobj("omsobj:Person?@Id contains '.'",n,uri);
  241. if nobj=0 then put 'No Persons available.';
  242.  
  243. else do while (nobj > 0);
  244.  
  245. /* Retrieve the current person's name. */
  246. rc=metadata_getattr(uri, "Name", Name);
  247.  
  248. /* Get the group association information for the current person. */
  249. a=1;
  250. grpassn=metadata_getnasn(uri,"IdentityGroups",a,groupuri);
  251.  
  252. /* If this person does not belong to any groups, set their group */
  253. /* variable to 'No groups' and output the name. */
  254. if grpassn in (-3,-4) then do;
  255. group="No groups";
  256. output;
  257. end;
  258.  
  259. /* If the person belongs to any groups, loop through the list */
  260. /* and retrieve the name of each group, outputting each on a */
  261. /* separate record. */
  262. else do while (grpassn > 0);
  263. rc2=metadata_getattr(groupuri, "Name", group);
  264. a+1;
  265. output;
  266. grpassn=metadata_getnasn(uri,"IdentityGroups",a,groupuri);
  267. end;
  268.  
  269. /* Retrieve the next person's information. */
  270. n+1;
  271. nobj=metadata_getnobj("omsobj:Person?@Id contains '.'",n,uri);
  272. end;
  273. keep name group;
  274. run;
  275.  
  276. /* Display the list of users and their groups. */
  277. proc report data=users_grps nowd headline headskip;
  278. columns name group;
  279. define name / order 'User Name' format=$30.;
  280. define group / order 'Group' format=$30.;
  281. break after name / skip;
  282. run;
  283.  
  284.  
  285. data work.Identities;
  286.  
  287. length IdentId IdentName DispName ExtLogin IntLogin DomainName $32
  288. uri uri2 uri3 uri4 $256;
  289.  
  290.  
  291. label
  292. IdentId = "Identity Id"
  293. IdentName = "Identity Name"
  294. DispName = "Display Name"
  295. ExtLogin = "External Login"
  296. IntLogin = "Is Account Internal?"
  297. DomainName = "Authentication Domain";
  298.  
  299.  
  300. call missing(IdentId, IdentName, DispName, ExtLogin, IntLogin, DomainName,
  301. uri, uri2, uri3, uri4);
  302. n=1;
  303. n2=1;
  304.  
  305.  
  306. rc=metadata_getnobj("omsobj:Person?@Id contains '.'",n,uri);
  307. if rc<=0 then put "NOTE: rc=" rc
  308. "There are no identities defined in this repository"
  309. " or there was an error reading the repository.";
  310.  
  311.  
  312. do while(rc>0);
  313. objrc=metadata_getattr(uri,"Id",IdentId);
  314. objrc=metadata_getattr(uri,"Name",IdentName);
  315. objrc=metadata_getattr(uri,"DisplayName",DispName);
  316.  
  317.  
  318. objrc=metadata_getnasn(uri,"InternalLoginInfo",n2,uri2);
  319.  
  320.  
  321. IntLogin="Yes";
  322. DomainName="**None**";
  323. if objrc<=0 then
  324. do;
  325. put "NOTE: There are no internal Logins defined for " IdentName +(-1)".";
  326. IntLogin="No";
  327. end;
  328.  
  329.  
  330. objrc=metadata_getnasn(uri,"Logins",n2,uri3);
  331.  
  332.  
  333. if objrc<=0 then
  334. do;
  335. put "NOTE: There are no external Logins defined for " IdentName +(-1)".";
  336. ExtLogin="**None**";
  337. output;
  338. end;
  339.  
  340.  
  341. do while(objrc>0);
  342. objrc=metadata_getattr(uri3,"UserID",ExtLogin);
  343.  
  344. DomainName="**None**";
  345. objrc2=metadata_getnasn(uri3,"Domain",1,uri4);
  346. if objrc2 >0 then
  347. do;
  348. objrc2=metadata_getattr(uri4,"Name",DomainName);
  349. end;
  350.  
  351. /*Output the record. */
  352. output;
  353.  
  354. n2+1;
  355.  
  356.  
  357. objrc=metadata_getnasn(uri,"Logins",n2,uri3);
  358. end;
  359.  
  360.  
  361. n+1;
  362. n2=1;
  363.  
  364. rc=metadata_getnobj("omsobj:Person?@Id contains '.'",n,uri);
  365. end;
  366.  
  367. keep IdentId IdentName DispName ExtLogin IntLogin DomainName;
  368. run;
  369.  
  370. /* extraction des informations sur les librairies */
  371. %mdsecds(membertypes="Library");
  372.  
  373.  
  374. PROC EXPORT DATA=metadata_libraries outfile=&EXCELFILE dbms=&OUTPUTFORMAT label replace;
  375. sheet="LIB I";
  376. run;
  377.  
  378. PROC EXPORT DATA=Libraries outfile=&EXCELFILE dbms=&OUTPUTFORMAT label replace;
  379. sheet="LIB II";
  380. run;
  381.  
  382. PROC EXPORT DATA=Mdsecds_permsl outfile=&EXCELFILE dbms=&OUTPUTFORMAT label replace;
  383. sheet="Libraries and Permissions";
  384. run;
  385.  
  386. PROC EXPORT DATA=Identities outfile=&EXCELFILE dbms=&OUTPUTFORMAT label replace;
  387. sheet="Identities";
  388. run;
  389. PROC EXPORT DATA=logins outfile=&EXCELFILE dbms=&OUTPUTFORMAT label replace;
  390. sheet="Logins";
  391. run;
  392. PROC EXPORT DATA=users_grps outfile=&EXCELFILE dbms=&OUTPUTFORMAT label replace;
  393. sheet="Users and Groups";
  394. run;
  395.  
  396. %mend getMetaInfos;
  397.  
  398. options metaserver="XXXXX"
  399. metaport=8561
  400. metauser="sasadm@saspw"
  401. metapass="XXXXX"
  402. metarepository="Foundation";
  403.  
  404. %getMetaInfos("C:\Users\sasdemo\Downloads\meta.xlsx","xlsx");
Add Comment
Please, Sign In to add comment