023 vault

This commit is contained in:
msyu
2024-11-18 13:31:17 +03:00
parent 34e914fd7e
commit 6a4ef90c67
6 changed files with 135 additions and 31 deletions
+1 -1
View File
@@ -71,7 +71,7 @@
//variables.framework.docs={}; //variables.framework.docs={};
variables.framework.docs.APIName="Deck API"; variables.framework.docs.APIName="Deck API";
variables.framework.docs.APIVersion="0.021"; variables.framework.docs.APIVersion="0.023";
variables.framework.globalHeaders = structNew(); variables.framework.globalHeaders = structNew();
variables.framework.globalHeaders["Access-Control-Expose-Headers"] = "Location"; variables.framework.globalHeaders["Access-Control-Expose-Headers"] = "Location";
View File
+65
View File
@@ -144,6 +144,71 @@
<cfset var out=structNew("linked")/> <cfset var out=structNew("linked")/>
<cftry><!--- *** надо бы такие вещи делать асинхронно --->
<cfset vaultUrl=""/>
<cfset instanceData="#deserializeJson(qCurrentState.instance_data)#"/>
<cfset vaultUrl=instanceData.vaultUrl/>
<cfhttp method="post"
url="https://vault.adl.nubes.ru:8200/v1/auth/approle/login"
timeout="3"
charset="utf-8"
result="res"
>
<cfhttpparam type="BODY" value='{"role_id":"df05e620-f3a3-8c6a-361d-a96e3b0adeac","secret_id":"585fbb48-ef97-b845-d414-b8831a27d5b6"}'/>
</cfhttp>
<cfset resData=#deserializeJson(res.filecontent)#/>
<!--- <cfdump var=#res#/> --->
<cfset client_token=#resData.auth.client_token#/>
<cftry>
<cfhttp method="get"
url="#vaultUrl#"
timeout="3"
charset="utf-8"
result="cred"
>
<cfhttpparam type="HEADER" name="X-Vault-Token" value="#client_token#">
</cfhttp>
<cfset "out.vaultData" = #deserializeJson(cred.filecontent).data.data#/>
<cfcatch type="ANY">
<!--- <cfreturn representationOf(cfcatch).withStatus(500)/> --->
<!--- <span class="err">#cfcatch.message# #cfcatch.detail#</span> ---></cfcatch>
</cftry>
<cftry>
<cfif structKeyExists(instanceData,"subusers")>
<cfloop collection=#instanceData.subusers# item="i">
<cfset vaultUrl=#instanceData.subusers[i].vaultUrl#/>
<cfhttp method="get"
url="#vaultUrl#"
timeout="3"
charset="utf-8"
result="cred"
>
<cfhttpparam type="HEADER" name="X-Vault-Token" value="#client_token#">
</cfhttp>
<!--- <cfdump var=#deserializeJson(cred.filecontent)#/> --->
<cfset "out.vaultData.subusers[i].userName"=#instanceData.subusers[i].userName#/>
<cfset "out.vaultData.subusers[i].subUserAccess"=#instanceData.subusers[i].subUserAccess#/>
<cfset "out.vaultData.subusers[i].vaultData"=#deserializeJson(cred.filecontent).data.data#/>
<!--- #instanceData.subusers[i].userName# (#instanceData.subusers[i].subUserAccess#)
<cfdump var=#deserializeJson(cred.filecontent).data.data#/> --->
</cfloop>
</cfif>
<cfcatch type="ANY"><!--- <cfreturn representationOf(cfcatch).withStatus(500)/> ---> </cfcatch>
</cftry>
<cfcatch type="any">
<!--- <cfrethrow/> ---><!--- <cfreturn representationOf(cfcatch).withStatus(500)/> --->
</cfcatch>
</cftry>
<cfset "out.queryDurationMs"=getTickCount() - request.startTickCount/> <cfset "out.queryDurationMs"=getTickCount() - request.startTickCount/>
<cfset "out.isCreated"=local.isCreated/> <cfset "out.isCreated"=local.isCreated/>
<cfset "out.isDeleted"=qCurrentState.is_deleted GT 0/><!--- он все время пытается привести true к 1 <cfset "out.isDeleted"=qCurrentState.is_deleted GT 0/><!--- он все время пытается привести true к 1
+26 -1
View File
@@ -99,6 +99,14 @@
<cfargument name="instanceOperationCfsParamUid" type="string" required=true hint="type:guid"/> <cfargument name="instanceOperationCfsParamUid" type="string" required=true hint="type:guid"/>
<cfargument name="paramValue" type="string" required=true/> <cfargument name="paramValue" type="string" required=true/>
<cfset var local={}/>
<cftry>
<cfset checkInstanceParam(arguments.instanceOperationCfsParamUid,arguments.paramValue)/>
<cfcatch type="invalidParamValue">
<cfreturn representationOf(this.helper.formatBadRequestError(cfcatch)).withStatus(400)/>
</cfcatch>
</cftry>
<cfquery name="local.qSave" result="local.result"> <cfquery name="local.qSave" result="local.result">
update instance_operation_cfs_param set update instance_operation_cfs_param set
dt_created=<cfqueryparam cfsqltype="cf_sql_timestamp" value="#Now()#" /> dt_created=<cfqueryparam cfsqltype="cf_sql_timestamp" value="#Now()#" />
@@ -106,8 +114,25 @@
,param_value=<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.paramValue#" /> ,param_value=<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.paramValue#" />
where instance_operation_cfs_param_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceOperationCfsParamUid#" null=#!isValid('guid',arguments.instanceOperationCfsParamUid)#/> where instance_operation_cfs_param_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceOperationCfsParamUid#" null=#!isValid('guid',arguments.instanceOperationCfsParamUid)#/>
</cfquery> </cfquery>
<!--- *** проверить существование - 404 --->
<cfreturn noData().withStatus(204, "No Content") /> <cfreturn noData().withStatus(204, "No Content") />
</cffunction> </cffunction>
<cffunction name="checkInstanceParam">
<cfargument name="instanceOperationCfsParamUid" type="numeric" required=true/>
<cfargument name="paramValue" required=true/>
<cfset var local={}/>
<cfquery name="local.qCheck" result="local.result">
select svc_operation_cfs_param_id
from instance_operation_cfs_param
where instance_operation_cfs_param_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceOperationCfsParamUid#" null=#!isValid('guid',arguments.instanceOperationCfsParamUid)#/>
</cfquery>
<cfif local.qCheck.recordCount GT 0>
<cfthrow type="invalidParamValue" message="Cannot find CFS parameter by instanceOperationCfsParamUid=#arguments.instanceOperationCfsParamUid#"/>
</cfif>
<cfset CreateObject("component", "instance_operation_cfs_param_ls").checkParam(local.qCheck.svc_operation_cfs_param_id, arguments.paramValue)/>
</cffunction>
</cfcomponent> </cfcomponent>
@@ -95,7 +95,8 @@
<cfreturn representationOf(out)/> <cfreturn representationOf(out)/>
</cffunction> </cffunction>
<cffunction name="post" hint="Создание нового CFS параметра операции.">
<!--- <cffunction name="post" hint="Создание нового CFS параметра операции.">
<cfargument name="instanceOperationUid" type="string" required=true hint="type:guid"/> <cfargument name="instanceOperationUid" type="string" required=true hint="type:guid"/>
<cfargument name="svcOperationCfsParamId" type="string" required=true hint="type:integer"/> <cfargument name="svcOperationCfsParamId" type="string" required=true hint="type:integer"/>
<cfargument name="paramValue" type="string" required=true hint="type:string ***Валидацию пока не проводим, а надо"/> <cfargument name="paramValue" type="string" required=true hint="type:string ***Валидацию пока не проводим, а надо"/>
@@ -137,9 +138,9 @@
.withHeaders({location: "./#local.instanceOperationCfsParamUid#"}) .withHeaders({location: "./#local.instanceOperationCfsParamUid#"})
.withStatus(201, "Created") .withStatus(201, "Created")
/> />
</cffunction> </cffunction> --->
<cffunction name="post" hint="Создание нового CFS параметра операции."> <cffunction name="post" hint="Создание нового CFS параметра операции.">
<cfargument name="instanceOperationUid" type="string" required=true hint="type:guid"/> <cfargument name="instanceOperationUid" type="string" required=true hint="type:guid"/>
<cfargument name="svcOperationCfsParamId" type="string" required=true hint="type:integer"/> <cfargument name="svcOperationCfsParamId" type="string" required=true hint="type:integer"/>
<cfargument name="paramValue" type="string" required=true hint="type:string ***Валидацию пока не проводим, а надо"/> <cfargument name="paramValue" type="string" required=true hint="type:string ***Валидацию пока не проводим, а надо"/>
@@ -148,6 +149,7 @@
<cfset this.helper.validateField(arguments, "instanceOperationUid", "guid")/> <cfset this.helper.validateField(arguments, "instanceOperationUid", "guid")/>
<cfset this.helper.validateField(arguments, "svcOperationCfsParamId", "integer")/> <cfset this.helper.validateField(arguments, "svcOperationCfsParamId", "integer")/>
<!--- Еще возможна ошибка, что мы подадим параметр не от своей операции или сервиса - он останется невидим для всех ---> <!--- Еще возможна ошибка, что мы подадим параметр не от своей операции или сервиса - он останется невидим для всех --->
<cfset checkParam(arguments.svcOperationCfsParamId, arguments.paramValue)/>
<cfcatch type="invalidParamValue"> <cfcatch type="invalidParamValue">
<cfreturn representationOf(this.helper.formatBadRequestError(cfcatch)).withStatus(400)/> <cfreturn representationOf(this.helper.formatBadRequestError(cfcatch)).withStatus(400)/>
@@ -167,15 +169,15 @@
<cfreturn representationOf(this.helper.formatMessage("Operation already started", "Parameter creation disabled for started operation")).withStatus(422)/> <cfreturn representationOf(this.helper.formatMessage("Operation already started", "Parameter creation disabled for started operation")).withStatus(422)/>
</cfif> </cfif>
<!--- Проверить: параметр от нашего ли сервиса ---> <!--- Проверка: параметр от нашего ли сервиса *** и операции --->
<cfquery name="local.qInstanceService" result="local.result"> <cfquery name="local.qInstanceService" result="local.result">
select e.service_id select e.service_id, io.operation
from instance_operation io from instance_operation io
join instance e on (io.instance_uid=e.instance_uid) join instance e on (io.instance_uid=e.instance_uid)
where io.instance_operation_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceOperationUid#"/> where io.instance_operation_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceOperationUid#"/>
</cfquery> </cfquery>
<cfquery name="local.qTemplateSvc" result="local.result"> <cfquery name="local.qTemplateSvc" result="local.result">
select so.svc_id select so.svc_id, so.operation
from svc_operation_cfs_param sop from svc_operation_cfs_param sop
join svc_operation so on (sop.svc_operation_id=so.svc_operation_id) join svc_operation so on (sop.svc_operation_id=so.svc_operation_id)
where sop.svc_operation_cfs_param_id=<cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.svcOperationCfsParamId#"/> where sop.svc_operation_cfs_param_id=<cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.svcOperationCfsParamId#"/>
@@ -183,11 +185,14 @@
<cfif local.qInstanceService.service_id NEQ local.qTemplateSvc.svc_id> <cfif local.qInstanceService.service_id NEQ local.qTemplateSvc.svc_id>
<cfreturn representationOf(this.helper.formatMessage("Invalid CFS parameter", "Parameter specified does not belong to this service")).withStatus(400)/> <cfreturn representationOf(this.helper.formatMessage("Invalid CFS parameter", "Parameter specified does not belong to this service")).withStatus(400)/>
</cfif> </cfif>
<cfif local.qInstanceService.operation NEQ local.qTemplateSvc.operation>
<cfreturn representationOf(this.helper.formatMessage("Invalid CFS parameter", "Parameter specified does not belong to this operation")).withStatus(400)/>
</cfif>
<cfset var msg=checkParam(arguments.svcOperationCfsParamId, arguments.paramValue)/> <!--- <cfset var msg=checkParam(arguments.svcOperationCfsParamId, arguments.paramValue)/>
<cfif len(msg)> <cfif len(msg)>
<cfreturn representationOf(this.helper.formatMessage("Invalid CFS parameter value", msg)).withStatus(400)/> <cfreturn representationOf(this.helper.formatMessage("Invalid CFS parameter value", msg)).withStatus(400)/>
</cfif> </cfif> --->
<cfquery name="local.qSave"> <cfquery name="local.qSave">
insert into instance_operation_cfs_param ( insert into instance_operation_cfs_param (
@@ -201,9 +206,11 @@
,<cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.usrId#" /> ,<cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.usrId#" />
); );
</cfquery> </cfquery>
<!--- <cfcatch type="invalidParamValue">
<cfcatch type="any"><!--- <cfrethrow/> ---> <cfreturn representationOf(this.helper.formatBadRequestError(cfcatch)).withStatus(400)/>
<cfreturn representationOf(this.helper.formatException(cfcatch, "Internal Error")).withStatus(500)/><!--- это не нужно показывать в продуктиве ---> </cfcatch> --->
<cfcatch type="any">
<cfreturn representationOf(this.helper.formatException(cfcatch, "Internal Error")).withStatus(500)/>
</cfcatch> </cfcatch>
</cftry> </cftry>
@@ -217,7 +224,7 @@
<cfargument name="svcOperationCfsParamId" type="numeric" required=true/> <cfargument name="svcOperationCfsParamId" type="numeric" required=true/>
<cfargument name="paramValue" required=true/> <cfargument name="paramValue" required=true/>
<!--- *** Вероятно, стоит возвращать конкретную ругань ---> <!--- *** Вероятно, стоит возвращать конкретную ругань --->
<!--- принадлежит ли параметр к данному сервису, проверяется выше --->
<cfquery name="qSvcOperationCfsParam"> <cfquery name="qSvcOperationCfsParam">
select sop.svc_operation_cfs_param select sop.svc_operation_cfs_param
,sop.value_list ,sop.value_list
@@ -232,24 +239,31 @@
</cfquery> </cfquery>
<cfif qSvcOperationCfsParam.is_required AND len(arguments.paramValue) EQ 0> <cfif qSvcOperationCfsParam.is_required AND len(arguments.paramValue) EQ 0>
<cfreturn "Missing required parameter (#qSvcOperationCfsParam.svc_operation_cfs_param#)"/> <!--- <cfreturn "Missing required parameter (#qSvcOperationCfsParam.svc_operation_cfs_param#)"/> --->
<cfthrow type="invalidParamValue" message="Missing required parameter (#qSvcOperationCfsParam.svc_operation_cfs_param#)"/>
<cfelseif len(arguments.paramValue) AND NOT checkValue(arguments.paramValue,qSvcOperationCfsParam.data_type)> <cfelseif len(arguments.paramValue) AND NOT checkValue(arguments.paramValue,qSvcOperationCfsParam.data_type)>
<cfreturn "Invalid format (#qSvcOperationCfsParam.svc_operation_cfs_param#)"/> <!--- <cfreturn "Invalid format (#qSvcOperationCfsParam.svc_operation_cfs_param#)"/> --->
<cfthrow type="invalidParamValue" message="Invalid format (#qSvcOperationCfsParam.svc_operation_cfs_param#)"/>
</cfif> </cfif>
<cfif len(arguments.paramValue) AND listLen(qSvcOperationCfsParam.value_list) GT 0 AND NOT listFind(qSvcOperationCfsParam.value_list, arguments.paramValue)> <cfif len(arguments.paramValue) AND listLen(qSvcOperationCfsParam.value_list) GT 0 AND NOT listFind(qSvcOperationCfsParam.value_list, arguments.paramValue)>
<cfreturn "Значение параметра #qSvcOperationCfsParam.svc_operation_cfs_param# отсутствует в списке #qSvcOperationCfsParam.value_list#"/> <!--- <cfreturn "Значение параметра #qSvcOperationCfsParam.svc_operation_cfs_param# отсутствует в списке #qSvcOperationCfsParam.value_list#"/> --->
<cfthrow type="invalidParamValue" message="Значение параметра #qSvcOperationCfsParam.svc_operation_cfs_param# отсутствует в списке #qSvcOperationCfsParam.value_list#"/>
</cfif> </cfif>
<cfif len(arguments.paramValue) AND qSvcOperationCfsParam.maxlength GT 0 AND len(arguments.paramValue) GT qSvcOperationCfsParam.maxlength> <cfif len(arguments.paramValue) AND qSvcOperationCfsParam.maxlength GT 0 AND len(arguments.paramValue) GT qSvcOperationCfsParam.maxlength>
<cfreturn "Длина #qSvcOperationCfsParam.svc_operation_cfs_param# превышает #qSvcOperationCfsParam.maxlength#"/> <!--- <cfreturn "Длина #qSvcOperationCfsParam.svc_operation_cfs_param# превышает #qSvcOperationCfsParam.maxlength#"/> --->
<cfthrow type="invalidParamValue" message="Длина #qSvcOperationCfsParam.svc_operation_cfs_param# превышает #qSvcOperationCfsParam.maxlength#"/>
</cfif> </cfif>
<cfif len(arguments.paramValue) AND qSvcOperationCfsParam.minlength GT 0 AND len(arguments.paramValue) LT qSvcOperationCfsParam.minlength> <cfif len(arguments.paramValue) AND qSvcOperationCfsParam.minlength GT 0 AND len(arguments.paramValue) LT qSvcOperationCfsParam.minlength>
<cfreturn "Длина #qSvcOperationCfsParam.svc_operation_cfs_param# меньше #qSvcOperationCfsParam.minlength#"/> <!--- *** попробовать cfparam type="regex" ---> <!--- <cfreturn "Длина #qSvcOperationCfsParam.svc_operation_cfs_param# меньше #qSvcOperationCfsParam.minlength#"/> ---> <!--- *** попробовать cfparam type="regex" --->
<cfthrow type="invalidParamValue" message="Длина #qSvcOperationCfsParam.svc_operation_cfs_param# меньше #qSvcOperationCfsParam.minlength#"/>
</cfif> </cfif>
<cfif len(arguments.paramValue) AND len(qSvcOperationCfsParam.regex) AND reFind(qSvcOperationCfsParam.regex,arguments.paramValue) EQ 0> <cfif len(arguments.paramValue) AND len(qSvcOperationCfsParam.regex) AND reFind(qSvcOperationCfsParam.regex,arguments.paramValue) EQ 0>
<cfreturn 'Pattern "#qSvcOperationCfsParam.regex#" does not match "#arguments.paramValue#"'/> <!--- <cfreturn 'Pattern "#qSvcOperationCfsParam.regex#" does not match "#arguments.paramValue#"'/> --->
<cfthrow type="invalidParamValue" message='Pattern "#qSvcOperationCfsParam.regex#" does not match "#arguments.paramValue#"'/>
</cfif> </cfif>
<!--- *** интересно, как мы ухитряемся проверить уникальность параметра, если он относится к операции, а не к экземпляру. Нам-то нужна уникальность для стейта (и то, скорее, единовременная, и интересовать будут только успешные операции) --->
<cfswitch expression=#qSvcOperationCfsParam.unique_scope#> <cfswitch expression=#qSvcOperationCfsParam.unique_scope#>
<cfcase value="provider"> <cfcase value="provider">
<cfquery name="qUnique"> <cfquery name="qUnique">
@@ -263,7 +277,8 @@
</cfquery> </cfquery>
<!--- <cfdump var=#qUnique#/> ---> <!--- <cfdump var=#qUnique#/> --->
<cfif qUnique.cnt GT 0> <cfif qUnique.cnt GT 0>
<cfreturn '#qSvcOperationCfsParam.svc_operation_cfs_param# = "#arguments.paramValue#" is not unique in the provider scope'/> <!--- <cfreturn '#qSvcOperationCfsParam.svc_operation_cfs_param# = "#arguments.paramValue#" is not unique in the provider scope'/> --->
<cfthrow type="invalidParamValue" message='#qSvcOperationCfsParam.svc_operation_cfs_param# = "#arguments.paramValue#" is not unique in the provider scope'/>
</cfif> </cfif>
</cfcase> </cfcase>
<cfcase value="tenant"> <cfcase value="tenant">
@@ -286,14 +301,13 @@
</cfquery> </cfquery>
<!--- <cfdump var=#qUnique#/> ---> <!--- <cfdump var=#qUnique#/> --->
<cfif qUnique.cnt GT 0> <cfif qUnique.cnt GT 0>
<cfreturn '#qSvcOperationCfsParam.svc_operation_cfs_param# = "#arguments.paramValue#" is not unique in the tenant scope'/> <!--- <cfreturn '#qSvcOperationCfsParam.svc_operation_cfs_param# = "#arguments.paramValue#" is not unique in the tenant scope'/> --->
<cfthrow type="invalidParamValue" message='#qSvcOperationCfsParam.svc_operation_cfs_param# = "#arguments.paramValue#" is not unique in the tenant scope'/>
</cfif> </cfif>
</cfcase> </cfcase>
<cfdefaultcase></cfdefaultcase> <cfdefaultcase></cfdefaultcase>
</cfswitch> </cfswitch>
<!--- <cfreturn ""/> --->
<cfreturn ""/>
</cffunction> </cffunction>
<cffunction name="checkValue" returnType="boolean"> <cffunction name="checkValue" returnType="boolean">
+1 -1
View File
@@ -6,7 +6,7 @@
</cfsilent> </cfsilent>
<cffunction name="post" hint="(ТЕСТИРОВАНИЕ)"> <cffunction name="post" hint="Запуск выполнения операции">
<cfargument name="instanceOperationUid" type="string" required=true hint="type:guid"/> <cfargument name="instanceOperationUid" type="string" required=true hint="type:guid"/>
<cfset local={}/> <cfset local={}/>