023 vault
This commit is contained in:
+1
-1
@@ -71,7 +71,7 @@
|
||||
|
||||
//variables.framework.docs={};
|
||||
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["Access-Control-Expose-Headers"] = "Location";
|
||||
|
||||
@@ -143,6 +143,71 @@
|
||||
|
||||
|
||||
<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.isCreated"=local.isCreated/>
|
||||
|
||||
@@ -98,6 +98,14 @@
|
||||
<cffunction name="put" hint="запись CFS параметра операции инстанса">
|
||||
<cfargument name="instanceOperationCfsParamUid" type="string" required=true hint="type:guid"/>
|
||||
<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">
|
||||
update instance_operation_cfs_param set
|
||||
@@ -106,8 +114,25 @@
|
||||
,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)#/>
|
||||
</cfquery>
|
||||
<!--- *** проверить существование - 404 --->
|
||||
<cfreturn noData().withStatus(204, "No Content") />
|
||||
</cffunction>
|
||||
|
||||
<cffunction name="checkInstanceParam">
|
||||
<cfargument name="instanceOperationCfsParamUid" type="numeric" required=true/>
|
||||
<cfargument name="paramValue" required=true/>
|
||||
|
||||
<cfreturn noData().withStatus(204, "No Content") />
|
||||
<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>
|
||||
@@ -95,7 +95,8 @@
|
||||
<cfreturn representationOf(out)/>
|
||||
</cffunction>
|
||||
|
||||
<cffunction name="post" hint="Создание нового CFS параметра операции.">
|
||||
|
||||
<!--- <cffunction name="post" hint="Создание нового CFS параметра операции.">
|
||||
<cfargument name="instanceOperationUid" type="string" required=true hint="type:guid"/>
|
||||
<cfargument name="svcOperationCfsParamId" type="string" required=true hint="type:integer"/>
|
||||
<cfargument name="paramValue" type="string" required=true hint="type:string ***Валидацию пока не проводим, а надо"/>
|
||||
@@ -137,9 +138,9 @@
|
||||
.withHeaders({location: "./#local.instanceOperationCfsParamUid#"})
|
||||
.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="svcOperationCfsParamId" type="string" required=true hint="type:integer"/>
|
||||
<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, "svcOperationCfsParamId", "integer")/>
|
||||
<!--- Еще возможна ошибка, что мы подадим параметр не от своей операции или сервиса - он останется невидим для всех --->
|
||||
<cfset checkParam(arguments.svcOperationCfsParamId, arguments.paramValue)/>
|
||||
|
||||
<cfcatch type="invalidParamValue">
|
||||
<cfreturn representationOf(this.helper.formatBadRequestError(cfcatch)).withStatus(400)/>
|
||||
@@ -167,27 +169,30 @@
|
||||
<cfreturn representationOf(this.helper.formatMessage("Operation already started", "Parameter creation disabled for started operation")).withStatus(422)/>
|
||||
</cfif>
|
||||
|
||||
<!--- Проверить: параметр от нашего ли сервиса --->
|
||||
<!--- Проверка: параметр от нашего ли сервиса *** и операции --->
|
||||
<cfquery name="local.qInstanceService" result="local.result">
|
||||
select e.service_id
|
||||
select e.service_id, io.operation
|
||||
from instance_operation io
|
||||
join instance e on (io.instance_uid=e.instance_uid)
|
||||
where io.instance_operation_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceOperationUid#"/>
|
||||
</cfquery>
|
||||
<cfquery name="local.qTemplateSvc" result="local.result">
|
||||
select so.svc_id
|
||||
select so.svc_id, so.operation
|
||||
from svc_operation_cfs_param sop
|
||||
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#"/>
|
||||
</cfquery>
|
||||
<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)/>
|
||||
</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)>
|
||||
<cfreturn representationOf(this.helper.formatMessage("Invalid CFS parameter value", msg)).withStatus(400)/>
|
||||
</cfif>
|
||||
</cfif> --->
|
||||
|
||||
<cfquery name="local.qSave">
|
||||
insert into instance_operation_cfs_param (
|
||||
@@ -200,10 +205,12 @@
|
||||
,<cfqueryparam cfsqltype="cf_sql_timestamp" value="#Now()#" />
|
||||
,<cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.usrId#" />
|
||||
);
|
||||
</cfquery>
|
||||
|
||||
<cfcatch type="any"><!--- <cfrethrow/> --->
|
||||
<cfreturn representationOf(this.helper.formatException(cfcatch, "Internal Error")).withStatus(500)/><!--- это не нужно показывать в продуктиве --->
|
||||
</cfquery>
|
||||
<!--- <cfcatch type="invalidParamValue">
|
||||
<cfreturn representationOf(this.helper.formatBadRequestError(cfcatch)).withStatus(400)/>
|
||||
</cfcatch> --->
|
||||
<cfcatch type="any">
|
||||
<cfreturn representationOf(this.helper.formatException(cfcatch, "Internal Error")).withStatus(500)/>
|
||||
</cfcatch>
|
||||
</cftry>
|
||||
|
||||
@@ -211,13 +218,13 @@
|
||||
.withHeaders({location: "./#local.instanceOperationCfsParamUid#"})
|
||||
.withStatus(201, "Created")
|
||||
/>
|
||||
</cffunction>
|
||||
</cffunction>
|
||||
|
||||
<cffunction name="checkParam">
|
||||
<cfargument name="svcOperationCfsParamId" type="numeric" required=true/>
|
||||
<cfargument name="paramValue" required=true/>
|
||||
<!--- *** Вероятно, стоит возвращать конкретную ругань --->
|
||||
|
||||
<!--- принадлежит ли параметр к данному сервису, проверяется выше --->
|
||||
<cfquery name="qSvcOperationCfsParam">
|
||||
select sop.svc_operation_cfs_param
|
||||
,sop.value_list
|
||||
@@ -232,24 +239,31 @@
|
||||
</cfquery>
|
||||
|
||||
<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)>
|
||||
<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 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 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 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 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>
|
||||
|
||||
<!--- *** интересно, как мы ухитряемся проверить уникальность параметра, если он относится к операции, а не к экземпляру. Нам-то нужна уникальность для стейта (и то, скорее, единовременная, и интересовать будут только успешные операции) --->
|
||||
<cfswitch expression=#qSvcOperationCfsParam.unique_scope#>
|
||||
<cfcase value="provider">
|
||||
<cfquery name="qUnique">
|
||||
@@ -263,7 +277,8 @@
|
||||
</cfquery>
|
||||
<!--- <cfdump var=#qUnique#/> --->
|
||||
<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>
|
||||
</cfcase>
|
||||
<cfcase value="tenant">
|
||||
@@ -286,14 +301,13 @@
|
||||
</cfquery>
|
||||
<!--- <cfdump var=#qUnique#/> --->
|
||||
<cfif qUnique.cnt GT 0>
|
||||
<cfreturn '#qSvcOperationCfsParam.svc_operation_cfs_param# = "#arguments.paramValue#" is not unique in the tenant scope'/>
|
||||
</cfif>
|
||||
|
||||
<!--- <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>
|
||||
</cfcase>
|
||||
<cfdefaultcase></cfdefaultcase>
|
||||
</cfswitch>
|
||||
|
||||
<cfreturn ""/>
|
||||
</cfswitch>
|
||||
<!--- <cfreturn ""/> --->
|
||||
</cffunction>
|
||||
|
||||
<cffunction name="checkValue" returnType="boolean">
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
</cfsilent>
|
||||
|
||||
|
||||
<cffunction name="post" hint="(ТЕСТИРОВАНИЕ)">
|
||||
<cffunction name="post" hint="Запуск выполнения операции">
|
||||
<cfargument name="instanceOperationUid" type="string" required=true hint="type:guid"/>
|
||||
|
||||
<cfset local={}/>
|
||||
|
||||
Reference in New Issue
Block a user