Skip to main content

RFW project creation automation

 


/*****************************************************************************************************

@Note:Encrypt the password:

  SAS Password Encryption code: proc pwencode in="AAA123"; run;

  Use the code on SAS Studio to encrypt the password

  In the place of “AAA123” in the code, replace with password and execute

  Check the log to find the encrypted password looks like “{SAS002}993090402DD916161D2D84542B0148C”

  Update the encrypted password in the code

*******************************************************************************************************/;

 

%let usr=sasdemo;

%let pwd={SAS002}35BAE0144C92782311439227468DDB33;

/* Start timer */

%let _timer_start = %sysfunc(datetime());


%macro adduser_group(user=

,group=

,mdebug=0

);

%local check uuri guri;

%let check=ok;


data _null_;

length uri type msg $256;

call missing(of _all_);

rc=metadata_getnobj("omsobj:Person?@Name='&user'",1,uri);


if rc<=0 then

do;

msg="WARNING: rc="!!cats(rc)!!" &user not found "!!

", or there was an error reading the repository.";

call symputx('check',msg);

putlog msg;

stop;

end;


call symputx('uuri',scan(uri,2,'\'));

rc=metadata_getnobj("omsobj:IdentityGroup?@Name='&group'",1,uri);


if rc<=0 then

do;

msg="WARNING: rc="!!cats(rc)!!" &group not found "!!

", or there was an error reading the repository.";

call symputx('check',msg);

putlog msg;

stop;

end;


call symputx('guri',scan(uri,2,'\'));

rc=metadata_getnobj("omsobj:Person?Person[@Name='&user'][IdentityGroups/*[@Name='&group']]",1,uri);


if rc=0 then

do;

msg="WARNING: rc="!!cats(rc)!!" &user already in &group";

call symputx('check',msg);

stop;

end;


if &mdebug ne 0 then

put (_all_)(=);

run;


/* stop if issues */

%if %quote(&check) ne %quote(ok) %then

%do;

%put &check;


%return;

%end;


%if %length(&syscc) ge 4 %then

%do;

%put WARNING:  SYSCC=&syscc, exiting &sysmacroname;


%return;

%end;


filename __us2grp temp;


proc metadata in= "<UpdateMetadata><Reposid>$METAREPOSITORY</Reposid><Metadata>

<Person Id='&uuri'><IdentityGroups><IdentityGroup ObjRef='&guri' />

</IdentityGroups></Person></Metadata>

<NS>SAS</NS><Flags>268435456</Flags></UpdateMetadata>"

out=__us2grp verbose;

run;


%if &mdebug ne 0 %then

%do;


data _null_;

infile __us2grp lrecl=32767;

input;

put _infile_;

run;


%end;


filename __us2grp clear;

%mend;

 

filename LUAPATH ('!SASROOT/misc/stresssvr/lua/sas' '!SASROOT/stresssvr/sasmisc/lua/sas'  '!SASROOT/lua/stresssvr');

 

proc lua restart;

submit;

 

local rest       = require 'risk.stress.rest_service'

local json       = require 'risk.common.json'

local rfw        = require 'risk.stress.rfw_api'

local utils      = require 'risk.common.rest_utils'

local file       = require 'risk.common.file_utils'

local content    = require 'risk.stress.rfw_content_utils'

local metadata= require 'risk.common.metadata'

local urausr = sas.symget('usr')

local password = sas.symget('pwd')

 

-- Set the url for rest calls

local pass = rfw.url_set()

if not pass then sas.print("%1zUnable to set the rest url.") return end

pass = rest.set_auth('ticket',urausr,password)

pass = rest.set_tgt()

local work_path = sas.getoption("work")

local file_sep = utils.get_file_sep()

 

--creating the PD location path

local staging_dir, pass =rfw.staging_dir_get( )

local ind = sas.findc(staging_dir,file_sep,'b')

local config_path = sas.substr(staging_dir,1,ind-1)

local pd_dir = config_path..file_sep..'archives'

local indapp = sas.find(staging_dir,'SASR')

local appdata= sas.substr(staging_dir,1,indapp-2)

local batch = sas.symget("batch")

local batchpath = sas.symget("batchpath")

sas.submit([[


proc import datafile="@staging_dir@/data/rfw/SBAP-User-Access-Request-Template.xlsx"

out=ura dbms=xlsx replace;

sheet="SBAP Access Request";

quit;


proc import datafile="@staging_dir@/data/rfw/Env_prefix_control.xlsx"

out=enva dbms=xlsx replace;

quit;


proc import datafile="@staging_dir@/data/rfw/smgpc.xlsx"

out=smcgrp dbms=xlsx replace;

quit;


%macro pref;

proc sql noprint;

select a_prefix_sts into :prefix

from work.svc as a left join enva as b

on a.hostname=b.hostname

where b.hostname ne "";

quit;


%if &prefix. > 0 %then


%do;


data ura;

length dv $10.;

set ura;


if Team ne "" then

dv=cats('a',psid);

drop psid;

rename dv=psid;

run;

%end;

%mend;


%pref;


proc transpose data=ura out=double(rename=(_name_=Name) keep=_name_ col1 );

var _all_;

quit;


data header_rename;

length main $50.;

set double;


if _n_ < 5 then

main=name;


if _n_ >= 5 and _n_ < 22 then

main="1Model"||"_"||col1;


if _n_ >= 22 and _n_ < 28 then

main="2WorkFlow"||"_"||col1;


if _n_ >= 31 and _n_ < 35 then

main="3Entity"||"_"||col1;


if _n_ >= 35 and _n_ < 43 then

main="4Access"||"_"||col1;


if _n_ >= 28 and _n_ < 31 then

main="5RECP"||"_"||col1;

drop col1;

run;


proc sql noprint;

select cats("'",name,"'n","=","'",main,"'n") into :rnm separated by " " from header_rename

where main ne "";

select cats("'",main,"'n") into : names separated by " " from header_rename

where main not in ("Action", "PSID" ,"User Name" ,"Team") and main ne "";

quit;


data ura1;

set ura(rename=(&rnm));

where Action not in ("Action", " ");

run;


proc sort data=ura1;

by psid "user name"n;

quit;


proc transpose data=ura1 out=ura2(drop=_label_ where=(col1 ne " "));

by Action PSID 'User Name'n Team;

var  &names.;

quit;


proc sort data=ura2;

by psid _name_;

quit;


proc Sql;

create table M1 as 

select psid, scan(_name_,2,"_") as model

from ura2 

where index(upcase(_name_), '1MOD') > 0;

create table G2 as 

select  psid, scan(_name_,2,"_") as Group

from ura2 

where index(upcase(_name_), '2WOR') > 0;

create table E3 as 

select psid, scan(_name_,2,"_") as Entity

from ura2

where index(upcase(_name_), '3ENT') > 0;

quit;


data g2(drop=group);

set g2;

if index(Group,"&") > 0 then gr=scan(group,1,'&');

if index(Group,"&") > 0 then gr1=scan(group,2,'&');

if index(Group,"&") = 0 then gr=group;

run;


data g2(rename=(gr=Group) where=(group ne ''));

set g2(drop=gr1) g2(drop=gr rename=(gr1=gr));

run;


%macro srt(in);


proc Sort data=&in;

by psid;

quit;


%mend srt;


%srt(M1);

%srt(G2);

%srt(E3);



proc sql;

create table main as

select 

(case when a.psid ne " " then catx('_',a.model,b.group,a.psid,c.entity) end) as Project_name

from m1 as a,g2 as b,E3 as c

where a.psid=b.psid and a.psid=c.psid;

quit;



proc Sql;

create table RECPM1 as 

select psid, scan(_name_,2,"_") as model

from ura2 

where index(upcase(_name_), 'RECP') > 0;

create table G2 as 

select  psid, scan(_name_,2,"_") as Group

from ura2 

where index(upcase(_name_), '2WOR') > 0;

create table E3 as 

select psid, scan(_name_,2,"_") as Entity

from ura2

where index(upcase(_name_), '3ENT') > 0;

quit;


data g2(drop=group);

set g2;

if index(Group,"&") > 0 then gr=scan(group,1,'&');

if index(Group,"&") > 0 then gr1=scan(group,2,'&');

if index(Group,"&") = 0 then gr=group;

run;


data g2(rename=(gr=Group) where=(group ne ''));

set g2(drop=gr1) g2(drop=gr rename=(gr1=gr));

run;


%macro srt(in);


proc Sort data=&in;

by psid;

quit;


%mend srt;


%srt(RECPM1);

%srt(G2);

%srt(E3);



proc sql;

create table main1 as

select 

(case when a.psid ne " " then catx('_',a.model,b.group,a.psid,c.entity) end) as Project_name

from RECPm1 as a,g2 as b,E3 as c

where a.psid=b.psid and a.psid=c.psid;

quit;


proc sql;

create table final as 

select distinct Project_name

from main where Project_name ne ""

union

select distinct Project_name

from main1 where Project_name ne "";

create table source as

select a.Project_name, b.RFWProcessDefinition as PD_name, 'add' as action

from final as a left join EWSTCONF.IRM_ModelFlow as b

on scan(upcase(a.Project_name),1,'_')=upcase(b.SAS_ModelName) &

scan(upcase(a.Project_name),2,'_')=upcase(b.Exercise) &

scan(upcase(a.Project_name),4,'_')=upcase(b.ModelEntity) 

where Project_name ne "";

create table ura_users as 

select distinct scan(project_name,3,"_") as psid, catx("_","RFW",scan(project_name,3,"_")) as demogp

from source;

quit;;

]],nil,nil,4) 


sas.submit([[

%macro ewst_security_init(source_ds=);

%local sec_lib_path;

%local

rfw_workgroup_id

rfw_workgroup

;

%let sec_lib_path = %sysfunc(pathname(RFW));

%put "sec_lib_path = &sec_lib_path";

libname rfw_sec "&sec_lib_path";


/* create default roles, groups and users if it does not exist */

/* otherwise macro will fail */

%if %sysfunc(exist(rfw_sec.default_roles)) eq 0 %then

%do;


proc sql noprint;

create table rfw_sec.default_roles 

(

role_name char(200)

);

insert into rfw_sec.default_roles

(role_name)

values("Risk and Finance Workbench: User")

;

insert into rfw_sec.default_roles

(role_name)

values("Visual Analytics: Report Viewing")

;

insert into rfw_sec.default_roles

(role_name)

values("IRM: Access All Entities")

;

quit;


%end;


%if %sysfunc(exist(rfw_sec.default_groups)) eq 0 %then

%do;


proc sql noprint;

create table rfw_sec.default_groups

(

group_name char(200)

);

insert into rfw_sec.default_groups

(group_name)

values ("Risk and Finance Workbench Users")

;

insert into rfw_sec.default_groups

(group_name)

values ("Visual Analytics Users")

;

insert into rfw_sec.default_groups

(group_name)

values ("IRM: Database Group")

;

quit;


%end;


%if %sysfunc(exist(rfw_sec.default_users)) eq 0 %then

%do;


proc sql noprint;

create table rfw_sec.default_users

(

user_name char(200)

);

insert into rfw_sec.default_users

(user_name)

values ("sasdemo")

;

quit;


%end;


proc sql noprint;

/* mapping of reviewers and approvers */

create table work.rev_app as

select distinct

strip(psid) as reviewer_id

,

(case 

when psid is not null then 

catx("_", "GRFW",PSID)

end)

as rfw_reviewer_workgroup_id

,

(case 

when psid is not null then 

catx("_","RFW",PSID)

end)

as rfw_reviewer_workgroup

from &source_ds.

where

PSID <> ""

;


/* create dynamic workgroups */

create table work.create_workgroups as 

select distinct 

rfw_reviewer_workgroup_id as workgroup_id

, rfw_reviewer_workgroup as workgroup

from work.rev_app

;


/* users to be assigned to new workgroups */

create table work.user_workgroups as 

select distinct /* add reviewer to the reviewer rfw workgroup */

reviewer_id as user_id

, rfw_reviewer_workgroup_id as workgroup_id

from work.rev_app

;

quit;


%mend ewst_security_init;


/* submit changes */

%macro exec_mduchglb(change=);

%if (&mduchgv_errors ^= 0) %then

%do;

%put ERROR: Validation errors detected by %nstr(%mduchgv). Load not attempted.;


%return;

%end;

%else

%do;

%mduchglb(change=&change);

%end;

%mend exec_mduchglb;;


%macro ewst_security_update(source_ds=, testing=);

%local work_path

cg_source_nobs;

%let work_path = %sysfunc(pathname(work));

%let cg_source_nobs = 0;


%if (%sysfunc(exist(&SOURCE_DS))) %then

%do;


proc sql noprint;

select 

count(*) 

into :source_nobs

from &source_ds.

;

quit;


%end;


/* create temp library folders */

x "mkdir &work_path/extr";

x "mkdir &work_path/impc";

x "mkdir &work_path/updates";

x "rm &work_path/extr/*";

x "rm &work_path/impc/*";

x "rm &work_path/updates/*";

libname extr "&work_path/extr";

libname impc "&work_path/impc";

libname updates "&work_path/updates";


/* dump metadata security */

%mduextr(libref=impc);

%mduextr(libref=extr);


%if (&source_nobs ne 0) %then

%do;

/* prepare data for EWST security updates */

%ewst_security_init(source_ds=&SOURCE_DS);

%let mit=0;


proc sql noprint;

select sum(

(case 

when a.name=b.workgroup then 0 

else 1 

end)

) into :mit

from extr.idgrps as a right join work.create_workgroups as b

on a.name=b.workgroup

where b.workgroup ne "";

quit;


%if &mit > 0 %then

%do;


proc sql noprint;

delete from work.create_workgroups

where workgroup in (select name from  extr.idgrps);

delete from work.user_workgroups

where workgroup_id in (select keyid from extr.idgrps where index(name,'RFW_') > 0);


/* create new workgroups */

/* remove already existing workgroups */

delete from work.create_workgroups

where 

workgroup_id in (select keyid from impc.idgrps)

;


/* finalize */

insert into impc.idgrps

( keyid

, name

, externalkey

)

select

workgroup_id

, workgroup

, 1

from work.create_workgroups

;

quit;


/* add default roles and workgroups to new workgroups */

proc sql noprint;

/* add default roles */

create table work.add_default_roles as 

select

catx("_", g.keyid, w.workgroup_id) as id

, g.keyid as grpkeyid

, w.workgroup_id as memkeyid

from impc.idgrps as g

inner join (select workgroup_id from work.create_workgroups) as w

on 1 = 1

where

g.name in (select role_name from rfw_sec.default_roles) /*"Risk and Finance Workbench: User", "Visual Analytics: Report Viewing"*/

and

g.grpType = "ROLE"

;


/* add default workgroups */

insert into work.add_default_roles

select

catx("_", g.keyid, w.workgroup_id) as id

, g.keyid as grpkeyid

, w.workgroup_id as memkeyid

from impc.idgrps as g

inner join (select workgroup_id from work.create_workgroups) as w

on 1 = 1

where

g.name in (select group_name from rfw_sec.default_groups) /*"Risk and Finance Workbench Users", "Visual Analytics Users"*/

and

g.grpType = ""

;


/* remove already existing relationships */

delete from work.add_default_roles

where

id in (select catx("_", grpkeyid, memkeyid) from impc.grpmems)

;


/* finalize */

insert into impc.grpmems

( grpkeyid

, memkeyid

)

select 

grpkeyid

, memkeyid

from work.add_default_roles

;

quit;


/* add default users to new workgroups */

proc sql noprint;

create table work.add_def_users_to_workgroups as 

select

catx("_", w.workgroup_id, p.keyid) as id

, w.workgroup_id as grpkeyid

, p.keyid as memkeyid

from impc.person as p

inner join (select workgroup_id from work.create_workgroups) as w

on 1 = 1

where

name in (select user_name from rfw_sec.default_users) /*"sasdemo"*/

;

/* add users to workgroups */

proc sql noprint;

create table work.add_users_to_workgroups as 

select distinct

catx("_", w.workgroup_id, p.keyid) as id

, w.workgroup_id as grpkeyid

, p.keyid as memkeyid

from impc.person as p

inner join work.user_workgroups as w

on w.user_id = person.name

;


/* remove already existing relationships */

delete from work.add_users_to_workgroups

where

id in (select catx("_", grpkeyid, memkeyid) from impc.grpmems)

;


/* finalize */

insert into impc.grpmems

( grpkeyid

, memkeyid

)

select 

grpkeyid

, memkeyid

from work.add_users_to_workgroups

;

quit;


%end;


/* compare master and updated metadata libraries */

%mducmp(master=impc, target=extr, change=updates);


/* check for errors */

%mduchgv(change=updates, target=extr, temp=work, errorsds=work.mduchgverrors);


/* submit changes */

%if (&testing eq 0) %then

%do;

%exec_mduchglb(change=updates);


/* free library references */

libname extr clear;

libname impc clear;

libname updates clear;

libname rfw_sec clear;


%end; /* %if (&testing eq 0) %then %do; */

%end;

%mend;


%ewst_security_update(SOURCE_DS=ura_users, testing=0);


%macro grp_map;


proc sql noprint;

create table u2g as 

select distinct compress(scan(a.project_name,3,'_')) as metuser , strip(b.group) as group 

from work.source as a inner join work.smcgrp as b

on scan(upcase(a.project_name),1,'_')=upcase(b.model)

where b.group ne " ";

select  count(metuser) ,strip(metuser), strip(group) into :cnt, :ur1 -, :grp1 -

from u2g;

select count(distinct demogp), demogp into :ek, :dou1 - from ura_users;

quit;


%if &cnt >  0 %then

%do;

%do i= 1 %to &cnt;

%adduser_group(user=%str(&&ur&i),group=%str(&&grp&i));

%end;

%end;



%if &ek >  0 %then

%do;

%do j= 1 %to &ek;

%adduser_group(user=sasdemo,group=%str(&&dou&j));

%end;

%end;

%mend;



%grp_map;


%macro control;


proc sort data=u2g;

by metuser;

quit;


proc transpose data=u2g out=g2u(drop=_NAME_) prefix=Group;

by metuser;

var group;

quit;


data source2;

set source;

userid=upcase(scan(project_name,3,'_'));

run;


proc sort data=source2;

by userid;

quit;


proc transpose data=source2 out=s2(drop=_name_) prefix=Project;

by userid;

var  project_name;

quit;


proc sql;

create table control_URA as

select "&sysdate9" as datestamp,"&SYSTIME" as timestamp, a.*,b.*

from s2 as a left join g2u as b

on strip(a.userid)=strip(b.metuser);

quit;


data control_URA(drop=metuser);

set control_URA;

run;


libname twk "@staging_dir@/data/rfw";


%if %sysfunc(exist(twk.control_URA)) > 0 %then

%do;


data twk.control_URA;

set twk.control_URA control_URA;

run;


%end;

%else

%do;


data twk.control_URA;

set control_URA;

run;


%end;

%mend;


%control;


%macro Create_Report_Template;

proc sql;

create table work.project_settings as 

select *,

(case 

when Project_name is not null then scan(Project_name,3,"_") 

end)

as user,

(case 

when Project_name is not null then catx("_","RFW", calculated user) 

end)

as workgroup,

(case 

when Project_name is not null then "risk and finance workbench administrators" 

end)

as workgroup1,

(case 

when Project_name is not null then (put(today(),mmddyyd10.)) 

end)

as process_start_date,

(case 

when Project_name is not null then " "  

end)

as description,

(case 

when Project_name is not null then 0 

end)

as process_notification,

(case 

when Project_name is not null then "2017-12-31" 

end)

as as_of_date,

(case 

when Project_name is not null then scan(Project_name,1,"_") 

end)

as model,

(case 

when Project_name is not null then scan(Project_name,2,"_") 

end)

as exercise,

(case 

when Project_name is not null then scan(Project_name,4,"_") 

end)

as entity

from 

work.source

where PD_name <> "" and upcase(action) ne " ";

quit;


%let cnt=0;


proc sql noprint;

select count(*) into :cnt from work.project_settings;

quit;


%if &cnt > 0 %then

%do;


proc sql;

create table work.project_exercise as

select distinct exercise,

model,

(case

when upcase(model) = "MASTERRUN" then "MASTER"

else model

end)

as rpt_model,

entity

from work.project_settings;

quit;


data _null_;

set work.project_exercise nobs=nobs;

call symputx('nobs',nobs);

call symputx(compress('exercise'||_n_),compress(exercise));

call symputx(compress('model'||_n_),compress(model));

call symputx(compress('rpt_model'||_n_),compress(rpt_model));

call symputx(compress('entity'||_n_),compress(entity));

run;


%do i=1 %to &nobs;

%let filenm = REPORT_%sysfunc(upcase(&&model&i.))_&&exercise&i.._&&entity&i.._INPUTS.sas;


%if %sysfunc(fileexist(&envroot./AppData/SASRiskWorkGroup/groups/Public/SASRiskandFinanceWorkbench/report_templates/&filenm)) 

or %upcase("&&model&i..") = "MASTER" or %upcase("&&model&i..") = "LOCAL" %then

%put Model is MASTER or file already exist: &filenm;

%else

%do;


data _null_;

file "&envroot./AppData/SASRiskWorkGroup/groups/Public/SASRiskandFinanceWorkbench/report_templates/&filenm";

put '%ewst_generate_input_report(modelname='"&&rpt_model&i.."', exercise='"&&exercise&i.."', entity='"&&entity&i.."');';

run;


%end;

%end;

%end;

%mend;


%Create_Report_Template;

]],nil,nil,4) 

             

        

        local delp = "work.del"   

        if (sas.exists(delp)) then

                               

            local pjdel_tbl = sas.read_ds(delp)

            local i,v 

            for i, v in ipairs(pjdel_tbl) do

            local projd=v["project_name"]

              --rfw.project_delete(projd)

                    sas.print("%3zCreating the Project")

            end --for i, v in ipairs(pjdel_tbl) do

        end --if (sas.exists(delp)) then    

        

        local pd = "work.project_settings"   

        if (sas.exists(pd)) then

                               

            local pd_tbl = sas.read_ds(pd)

            local i,v 

            

            for i, v in ipairs(pd_tbl) do 

          

                local pd_name=v["pd_name"]

                local proj=v["project_name"]

                local model=v["model"]

                local exercise=v["exercise"]

                local entity=v["entity"]

                local as_of_date=v["as_of_date"]

                                                        

                --LUA code starts for report template upload

                -- Get the rest api information from metadata

                local hostname, port, protocol, appName, URL = metadata.get_rest_end_point_dtls("SASRiskandFinanceWorkbench REST")

                if not URL then

                 sas.print("%1zWas unable to get the metadata information - check that the server is running and that you have the proper permissions")

                 return

                end

                sas.print("%3z Got the following information from metadata:")

                sas.print("  Hostname: "..hostname)

                sas.print("  Port: "..port)

                sas.print("  Protocol: "..protocol)

                sas.print("  Application Name: "..appName)

                sas.print("  URL: "..URL)

                

                --defining a function for file exist status

                function file_exist(name)

                local f=io.open(name,"r")

                if f~=nil then io.close(f) return true else return false end

                end

            

                categoryname = "ViewActuals"

                    sas.print("Category Name "..categoryname)

                reportname = 'View '..string.upper(model)..' Input'

                    sas.print("Report Name "..reportname)

                reporttemplate = 'REPORT_'..string.upper(model)..'_'..exercise..'_'..entity..'_INPUTS.sas'

                    sas.print("Report Template "..reporttemplate)

                fullfile = appdata..'/SASRiskWorkGroup/groups/Public/SASRiskandFinanceWorkbench/report_templates/'..reporttemplate

          

                sas.print("Full Path ".. fullfile)

          

                local exist=file_exist(fullfile)

            

                ------------------------------------------------------------------------------

                --                 PROJECT & PROCESS DEFINITION CREATION                    --

                ------------------------------------------------------------------------------

                           

                rfw.project_delete(proj)

                    sas.print("%3zCreating the Project") 

                local proj_key = rfw.project_key_get(proj)

                

                    if not proj_key then

                        sas.print("%3zNew project "..proj)

                        rfw.project_create(proj,"Auto project",pd_name,as_of_date)

                            if exist then

                                rfw.report_category_create(categoryname,proj)

                                rc = rfw.report_load_into_project(reportname, reporttemplate,proj,categoryname)

                                if rc >= 300 and password ~= '' then 

                                    local proj_id = rfw.project_key_get(proj)

                                

                                    sas.submit([[

                                        proc http

                                        AUTH_BASIC webusername="&usr" webpassword="&pwd"       

                                        url="%nrstr(@url@config/projects/@proj_id@/reportConfigs)"  

                                        headerin = hin 

                                        headerout=hout 

                                        in = in 

                                        out = out

                                        ct = 'application/json;charset=UTF-8'

                                        method='POST';

                                        run;

                                    ]], {url= rest.url})

                                    rc = tonumber(sas.scan(sas.scan(utils.read_fileref("hout"),1,'\n\r'),2,' '))

                                end --rc >= 300 and password ~= '' then

                                if rc >= 300 then

                                    sas.print("%1z was not able to create the report "..name or "<nil>")

                                end --rc >= 300 then

                            else

                                if model ~= 'MASTER' and model ~= 'SOLO' and model ~= 'LOCAL' then

                                    sas.print("%1zReport Template "..reporttemplate.." does not exist.")

                                end

                            end --exist then

                    else

                        sas.print("%1zAproject with the name "..proj.." already exists.")

                    end --not proj_key then                     

            end --for i, v in ipairs(pd_tbl) do

        end --if (sas.exists(pd)) then

endsubmit;

run;


filename LUAPATH ( '!SASROOT/lua/stresssvr' '!SASROOT/misc/stresssvr/lua/sas' '!SASROOT/stresssvr/sasmisc/lua/sas' );

proc lua restart;

submit;

local rest       = require 'risk.stress.rest_service'

local Json       = require 'risk.common.json'

local metadata   = require 'risk.common.metadata'

local rfw        = require 'risk.stress.rfw_api'

local utils      = require 'risk.common.rest_utils'

local file       = require 'risk.common.file_utils'

local content    = require 'risk.stress.rfw_content_utils'

local urausr = sas.symget('usr')

local password = sas.symget('pwd')

Json.strictTypes = true

local file_sep = utils.get_file_sep()

local pass = rfw.url_set()

if not pass then sas.print("%1zUnable to set the rest url.") return end

pass = rest.set_auth('ticket',urausr,password)

    pass = rest.set_tgt() 

   

   

---Clear user group cache.

--  @return a table with one entry; httpStatusCode.

--  @usage

--  local resp=rfw.rfw_flush_cache()

--  print(resp['httpStatusCode'])

function rfw.rfw_flush_cache()

   if not rfw.url_set() then  

      sas.print(sas.sasmsg('sashelp.stressluamsg',  'sst_url_not_set', 'NOQUOTE'))

      return 

   end

   local response={}

   local hpass, hout_str, hcode  = rest.request( 'POST', "config/clearUserGroupCache", nil, "Accept:*/*; q=0.01",'application/json;charset=UTF-8')

   if not hpass then

      sas.print("%1z"..tostring(hout_str))

   else     

      sas.print("%3z"..tostring(hcode))

   end

   response.httpStatusCode=hcode   

   return response

end

local resp=rfw.rfw_flush_cache()

print(resp['httpStatusCode'])

endsubmit;

run;

proc lua restart; 

submit;

    local rest    = require 'risk.common.rest_service'

    local rfw     = require 'risk.stress.rfw_api'

    local json    = require 'risk.common.json'

     

      

    -- Set the url for rest calls

    local url = rfw.url_set()

    if not url then sas.print("%1zUnable to set the rest url.") return end


               

        p_aut = {}

        local p_aut = sas.read_ds("project_settings")

        i=1

        while(p_aut[i] ~= nil) do

        local project_settings = p_aut[i]

 

        local proj_key = rfw.project_key_get(project_settings.project_name)

        sas.print("%3zProject Key is : "..proj_key)

        request_txt = 'config/projects/'..proj_key..'/accessControls'

   

        --Get all the workgroups

        pass, json_out, code = rest.request("GET",request_txt) 

        wrkgroup = json:decode(json_out)

        

        --Set the ones we want to have selected=true

        for i,v in ipairs(wrkgroup.workgroups) do

        

                if string.lower(tostring(v.name)) == string.lower(tostring(project_settings.workgroup)) then

                       v.selected = true

                end

                if string.lower(tostring(v.name)) == string.lower(tostring(project_settings.workgroup1)) then

                      v.selected = true

                end

            end

         local bdy = json:encode(wrkgroup)

     

           

         --Now send this to the server to change the settings for the workgroup permissions

         pass, json_out, code = rest.request("PUT",request_txt,bdy,nil,'application/json;charset=UTF-8')

   

   

        i=i+1

        end --while(p_aut[i] ~= nil) do

    


endsubmit;

run;

 

/* Stop timer */

data _null_;

dur = datetime() - &_timer_start;

put 30*'-' / ' TOTAL DURATION:' dur time13.2 / 30*'-';

run;

 

 


Comments

  1. Dear Sir/Ma'am,
    Today I came across your blogs. Its a treasure for those who aspire to become a SAS Admin. Can you please share your mail Id/name so that we can follow your content on other social media platforms as well if available

    ReplyDelete

Post a Comment

Popular posts from this blog

Insufficient authorization to access PIPE error in SAS EG

Issue: When I tried to run SAS code in SAS Enterprise Guide it throws following errors: ERROR: Insufficient authorization to access PIPE. ERROR: Error in the FILENAME statement. Screenshot of error: Solution: This error occurs when you try to run OS commands in SAS code. To run the OS commands in SAS code you need to enable XCMD option. You check it in SAS Management Console by following below steps.   Open SMC -> Expand Servers -> Expand   In SASApp , expand Logical Workspace Server -> right click on Workspace Server. Click properties -> option tab -> advanced options -> launch properties. Check whether Allow XCMD is checked. The issue arises if the Allow XCMD is not checked. In above image, Allow XCMD option is not checked. It should be checked to run OS commands from SAS code. In Unix /Linux machines, this XCMD option can be enabled by using system option XCMD in sasv9 config file or workspaceserver.sh script f...

The authentication server is not SETUID ROOT error in SAS

Question: When validating the SAS Server from SAS Management Console, I received the following error: The authentication server is not SETUID ROOT.  So, I ran the setuid.sh utility and restarted the services many times. I just checked the elssrv sasauth sasperm setuid bit. There were no error in sasauth-debug.log, sasauth-access.log, sasauth-error.log.  Any suggestions? Answer: Please do the following:    1) Run /<SASConfig>/Lev<X>/ObjectSpawner/ObjectSpawner.sh stop  2) Edit /<SASConfig>/Lev<X>/ObjectSpawner/ObjectSpawner.sh and add the code shown below right after SCRIPT=`basename $0`:  if [ -n ""$TKPATH"" ]; then  unset TKPATH  fi   if [ -n ""$TK_PATHLIST"" ]; then  unset TK_PATHLIST  fi    3) Run /<SASConfig>/Lev<X>/ObjectSpawner/ObjectSpawner.sh start  The above code change in ObjectSpawner.sh should fix the issue.

SAS - CLI error trying to establish connection

Issue: User asked me to make a database connectivity to SQL Server. They provided following details SQL server hostname and ip address Database/DSN name Username Password I made entry in ODBC.ini file. You know, SQL Server entries were made in ODBC.ini and Oracle entries were made in TNS.ora file. Everything went fine, took back up of odbc.ini, made entry and saved the file. So to test this connection I ran the libname statement in SAS Enterprise Guide 6.1. It throwed following error. Error Message: My DB team showed that they are able to login   14 GOPTIONS ACCESSIBLE; 15 LIBNAME test ODBC DATASRC=SGE_DS SCHEMA=VST USER=sales PASSWORD=XXXXXXXXX; ERROR: CLI error trying to establish connection: [SAS/ACCESS to SQL Server][ODBC SQL Server Legacy Driver][SQL Server]Login failed for user 'sales'. Solution: First I suspected that Login failed for user 'sales' meant the password provided by DB team was wrong. They responded that they were able to login wi...