this.name = hash(getCurrentTemplatePath());
variables.framework.debugKey = "debug";
variables.framework.reloadKey = "reload";
variables.framework.reloadPassword = "true";
variables.framework.reloadOnEveryRequest = true;
variables.framework.serializer = "taffy.core.nativeJsonSerializer";
variables.framework.dashboardKey = "dashboard";
variables.framework.disableDashboard = false;
variables.framework.unhandledPaths = "/flex2gateway";
variables.framework.allowCrossDomain = true;
variables.framework.docs.APIName="svc-api";
variables.framework.docs.APIVersion="0.234";
variables.framework.globalHeaders = structNew();
variables.framework.globalHeaders["Access-Control-Expose-Headers"] = "Location";
variables.framework.globalHeaders["Access-Control-Allow-Credentials"] = "true";
variables.framework.globalHeaders["X-Application-Version"] = variables.framework.docs.APIVersion;
request.UNDEFINED_USR_ID=-1;
request.ANONYMOUS_USR_ID=2;
request.GUEST_USR_ID=3;
request.USER_AGENT="#variables.framework.docs.APIName# #variables.framework.docs.APIVersion# stand:#this.getStand()#";
request.ORCHESTRATOR_AUTH = createObject("java", "java.lang.System").getEnv("ORCHESTRATOR_AUTH");
if (isNull(request.ORCHESTRATOR_AUTH)) {
request.ORCHESTRATOR_AUTH = "Basic ...no data";
}
request.vault_login_url="https://vault.lk.adl.nubes.ru/v1/auth/approle/login";
request.vault_role_id=createObject("java", "java.lang.System").getEnv("VAULT_ROLE_ID");
request.vault_secret_id=createObject("java", "java.lang.System").getEnv("VAULT_SECRET_ID");
request.auth_header="";
select value as stand from config
where name='STAND'
select value as stand from config
where name='STAND'
function onTaffyRequest(verb, cfc, requestArguments, mimeExt, headers){
request.stand=this.getStand();
request.iam_service_url=this.iamServiceUrl;
if (uCase(arguments.verb) EQ 'OPTIONS') return true;
if (lCase(arguments.cfc) EQ 'err') return true;
if (lCase(arguments.cfc) EQ 'throw') return true;
if (structKeyExists(headers,"Authorization")) {
request.auth_header=headers.Authorization;
} else {
return representationOf("Authorization header expected").withStatus(401);
}
var result="";
try {
var authUrl = "#this.iamServiceUrl#/auth/user";
var httpService = new http(method = "GET", charset = "utf-8", url = #authUrl#, timeout="5");
httpService.addParam(type = "HEADER", name = "Accept", value = "application/json");
httpService.addParam(type = "HEADER", name = "Authorization", value = "#request.auth_header#");
var resp = httpService.send();
var prefix = resp.getPrefix();
if (prefix.status_code NEQ 200) {
var iamStatusCode = (isValid("integer", prefix.status_code)) ? val(prefix.status_code) : 500;
return representationOf( {"IAM URL"=#authUrl#, "idpResponse"=resp} ).withStatus(iamStatusCode);
}
result = prefix.filecontent;
} catch (e) {
return representationOf( {"exception"=e, "idpResponse"=result} ).withStatus(200);
}
try {
var idpUserData=deserializeJson(result);
"arguments.requestArguments.companyUid"=idpUserData.userInfo.companyId;
"arguments.requestArguments.usrUid"=idpUserData.userInfo.contactId;
var usrCustomerInfo=getUsrCustomerInfo(idpUserData.userInfo.contactId, idpUserData.userInfo.companyId);
} catch (e) {
return representationOf( {"exception.Message"=e.Message, "exception.Detail"=e.Detail, "idpResponse"=result} ).withStatus(422);
}
if (lCase(arguments.cfc) EQ 'user') {
if (structIsEmpty(usrCustomerInfo)) return representationOf("User information not found").withStatus(404);
}
if (lCase(arguments.cfc) EQ 'notification_ls') {
if (structIsEmpty(usrCustomerInfo)) {
"arguments.requestArguments.usrId"=-1;
"arguments.requestArguments.contragentId"=-1;
"arguments.requestArguments.contractId"=-1;
"arguments.requestArguments.specificationId"=-1;
"arguments.requestArguments.isImpersonated"=false;
"arguments.requestArguments.clientID"="";
"arguments.requestArguments.login"="";
return true;
}
}
if (structIsEmpty(usrCustomerInfo)) return representationOf("Cannot find default specification for current user #result#").withStatus(422);
"arguments.requestArguments.usrId"=usrCustomerInfo.usrId;
"arguments.requestArguments.contragentId"=usrCustomerInfo.contragentId;
"arguments.requestArguments.contractId"=usrCustomerInfo.contractId;
"arguments.requestArguments.specificationId"=usrCustomerInfo.specificationId;
try {
"arguments.requestArguments.isImpersonated"=idpUserData.impersonation.is_impersonated;
} catch (e) {
"arguments.requestArguments.isImpersonated"=false;
}
try {
"arguments.requestArguments.clientID"=idpUserData.userInfo.clientID;
} catch (e) {
"arguments.requestArguments.clientID"="";
}
try {
"arguments.requestArguments.login"=idpUserData.userInfo.login;
} catch (e) {
"arguments.requestArguments.login"="";
}
return true;
}
select usr_id from usr where login=
#cfcatch.message# : #cfcatch.detail#
#cfcatch.message# : #cfcatch.detail#
при этом если имперсонируется компания, то спецификацию и контракт нужно брать по компании
Кстати, зачем нужен вообще юзер, если компания всегда доступна, а вся информация висит на ней
Для того, чтобы разрешить ключ в целочисленный ключ CMDB--->
select z.contragent_id, c.contract_id, s.specification_id
from contragent z
join contract c on (z.contragent_id=c.contragent_id)
join specification s on (c.contract_id=s.contract_id)
where z.external_uid=
order by s.specification_id desc
limit 1;
select z.contragent_id
from contragent z
where z.external_uid=
select z.contragent_id, c.contract_id
from contragent z
join contract c on (z.contragent_id=c.contragent_id)
where z.external_uid=
select u.usr_id, u.contragent_id, k.contragent_id as c_contragent_id
from usr u
left outer join contragent k on (u.contragent_id=k.contragent_id)
where u.idp_usr_uid=
limit 1;
Now we know everything we need to know to service the request. let's service it!
--->
This way we can directly return the object instead of a serializer from resource actions. --->
#local.resultSerialized#
Request Details: