cleanup: удалены закомментированные фрагменты кода (104 блока в 14 файлах)
This commit is contained in:
@@ -1,11 +1,8 @@
|
||||
<cfcomponent extends="taffy.core.resource" taffy:uri="/instances/{instanceUid}">
|
||||
|
||||
<cfsilent>
|
||||
<cfimport prefix="m" taglib="../lib"/>
|
||||
<cfset this.helper=CreateObject("component","lib.rest_api_helper")/><!---*** странно, почему мы его видим?---><!---вынести в апп?--->
|
||||
</cfsilent>
|
||||
|
||||
|
||||
<cffunction name="get" hint="Экземпляр сервиса"><!--- *** TODO проверка принадлежности тенанту --->
|
||||
<cfargument name="instanceUid" type="string" required=true hint="type:guid"/>
|
||||
<cftry>
|
||||
@@ -14,9 +11,7 @@
|
||||
<cfreturn representationOf(this.helper.formatBadRequestError(cfcatch)).withStatus(400)/>
|
||||
</cfcatch>
|
||||
</cftry>
|
||||
|
||||
<cfset var local={}/>
|
||||
|
||||
<cfquery name="local.qInstance" result="local.result">
|
||||
select
|
||||
<m:field_set titleMapOut="local.titleMap" lengthOut="local.fieldCount">
|
||||
@@ -36,7 +31,6 @@
|
||||
<m:field>v.svc</m:field>
|
||||
<m:field>v.code</m:field>
|
||||
<m:field>v.man
|
||||
|
||||
</m:field>
|
||||
<m:field>e.updater_id</m:field>
|
||||
<m:field>u.login as updater_login</m:field>
|
||||
@@ -71,7 +65,6 @@
|
||||
AND a.is_enabled)
|
||||
where r.resource_realm_type_id=v.resource_realm_type_id) as resource_realm_cnt
|
||||
</m:field>
|
||||
<!--- <m:field>st.version</m:field> --->
|
||||
</m:field_set>
|
||||
from instance e
|
||||
left outer join specification_item i on (e.specification_item_id=i.specification_item_id)
|
||||
@@ -94,16 +87,13 @@
|
||||
where e.instance_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceUid#" null=#!isValid('guid',arguments.instanceUid)#/>
|
||||
AND s.specification_id=<cfqueryparam cfsqltype="cf_sql_integer" value=#arguments.specificationId#/><!--- access protection --->
|
||||
</cfquery> <!--- *** правильнее при попытке доступа к чужому инстансу (НСД) выбрасывать 403, а тут будет 404, но так тоже делают, например, в gitea --->
|
||||
|
||||
<cfif local.qInstance.recordCount EQ 0>
|
||||
<cfreturn representationOf("Instance not found or no permission to view").withStatus(404)/>
|
||||
</cfif>
|
||||
|
||||
<!--- instanceData?.suspended
|
||||
instanceData?.out?.monitoring?.allDashboards
|
||||
instanceData?.params
|
||||
instanceData?.out --->
|
||||
|
||||
<cfquery name="local.qCurrentState" result="local.result">
|
||||
select
|
||||
<m:field_set titleMapOut="local.currentStateTitleMap" lengthOut="local.fieldCount">
|
||||
@@ -113,7 +103,6 @@
|
||||
<m:field>to_char(st.dt_state, 'YYYY-MM-DD"T"HH24:MI:SS.FF3TZHTZM') as dt_state</m:field>
|
||||
<m:field formatter=#request.castToBool#>st.is_test</m:field>
|
||||
<m:field>st.instance_operation_uid::text as instance_operation_uid</m:field>
|
||||
<!--- <m:field formatter=#function(x){return (deserializeJson(x))}#>st.instance_data::text as instance_data</m:field> --->
|
||||
<m:field formatter=#function(x){return (deserializeJson(x))}#>st.instance_data->>'out' as out</m:field>
|
||||
<m:field formatter=#function(x){return (deserializeJson(x))}#>st.instance_data->>'params' as params</m:field>
|
||||
<m:field formatter=#function(x){return (deserializeJson(x))}#>st.instance_data->>'vault' as vault</m:field>
|
||||
@@ -125,13 +114,8 @@
|
||||
order by st.version desc
|
||||
limit 1
|
||||
</cfquery><!--- берем local.qInstance.instance_uid ради изоляции (access protection) --->
|
||||
|
||||
|
||||
<cfset local.isCreated = (local.qCurrentState.recordCount GT 0)/>
|
||||
<cfset local.isDeleted = (local.qCurrentState.is_deleted GT 0)/>
|
||||
|
||||
<!--- <cfdump var=#local.qInstance#/><cfabort/> --->
|
||||
|
||||
<!--- операция, создавшая текущее состояние --->
|
||||
<!--- *** странноватый селект --->
|
||||
<cfquery name="local.qOperation" result="local.result">
|
||||
@@ -171,11 +155,7 @@
|
||||
<!--- *** А тут у нас не получится, что только операции с состояниями? Или в неправильном порядке? --->
|
||||
<!--- ?Добавить параметры к операции --->
|
||||
<!--- Разобраться в отличии текущей от последней. Может, нужна только одна? --->
|
||||
|
||||
<!--- <d:field title="Операция">(select operation from instance_state st join instance_operation io on (st.instance_operation_uid=io.instance_operation_uid) where st.instance_uid=e.instance_uid order by version desc limit 1) as operation</d:field>
|
||||
<!--- текущая операция. Она еще не создала стейта и не завершена --->
|
||||
<d:field title="Текущая операция">(select io.operation from instance_operation io where io.instance_uid=e.instance_uid order by dt_submit desc limit 1) as current_operation</d:field> --->
|
||||
|
||||
<!--- *** Отработать блокировку --->
|
||||
<cfquery name="local.qAvailableOperation" result="local.result">
|
||||
select
|
||||
@@ -204,17 +184,12 @@
|
||||
</cfif>
|
||||
order by so.svc_operation_id
|
||||
</cfquery>
|
||||
|
||||
<!--- Проблема зависимостей. Чтобы их увидеть, нам нужно состояние, а его нет в реляционном виде.
|
||||
Значит, придется парсить стейт
|
||||
но чтобы получить все сервисы, которые зависят от данного, придется им отпарсить все стейты, что нереально
|
||||
Значит, придется заняться нормализаций стейта (приведением в реляционный вид) - впрочем, ничего сильно сложного в этом нет
|
||||
А есть смысл делать это в одну строну? наверно, есть - чтобы не забираться в операцию
|
||||
--->
|
||||
|
||||
|
||||
|
||||
|
||||
<!--- *** здесь уместна параноидальная проверка прав --->
|
||||
<cfquery name="local.qDependency">
|
||||
select
|
||||
@@ -240,7 +215,6 @@
|
||||
left outer join svc_operation so on (o.operation=so.operation AND e.service_id=so.svc_id)
|
||||
left outer join svc_operation_cfs_param sop on (so.svc_operation_id=sop.svc_operation_id AND p.param=sop.svc_operation_cfs_param)
|
||||
left outer join svc s on (sop.ref_svc_id=s.svc_id)
|
||||
|
||||
join instance r on (p.param_value=r.instance_uid::text)
|
||||
left outer join specification_item si on (r.specification_item_id=si.specification_item_id)
|
||||
left outer join specification sp on (si.specification_id=sp.specification_id)
|
||||
@@ -250,7 +224,6 @@
|
||||
AND sop.ref_svc_id > 0
|
||||
order by sop.sort, p.param
|
||||
</cfquery>
|
||||
|
||||
<!--- *** здесь уместна параноидальная проверка прав
|
||||
потому что можно сослаться на чужой инстанс и увидеть какие-то лишние детали--->
|
||||
<cfquery name="local.qDependentInstance">
|
||||
@@ -289,14 +262,10 @@
|
||||
where i.instance_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceUid#" null=#!isValid('guid',arguments.instanceUid)#/>
|
||||
)
|
||||
</cfquery>
|
||||
|
||||
|
||||
|
||||
<!--- ---------------------------------------------------------------------------------- --->
|
||||
<!--- маскируем секреты *** это не очень похоже на то же самое в списке, там мы просто удаляем параметры --->
|
||||
<!--- *** подгоняем запрос под структуру из instance_operation_cfs_param --->
|
||||
<!--- а мы тут упускаем, что может быть несколько операций create, как правило из-за сломавшихся. Но параметры мы берем из текущего стейта, и операцию возьмем оттуда же --->
|
||||
|
||||
<cfquery name="local.qCfsParam" result="local.result">
|
||||
select
|
||||
p.svc_operation_cfs_param
|
||||
@@ -320,7 +289,6 @@
|
||||
where svc.svc_id=<cfqueryparam cfsqltype="cf_sql_integer" value="#qInstance.service_id#" null=#!isValid('integer',qInstance.service_id)#/>
|
||||
AND o.operation='create'
|
||||
</cfquery>
|
||||
|
||||
<!--- *** сделано не так, как в instance_operation_cfs_param (а там тоже сделано так себе) --->
|
||||
<cfset local.params = structNew("linked")/>
|
||||
<cftry>
|
||||
@@ -333,7 +301,7 @@
|
||||
<cfset local.params[paramName]="********"/>
|
||||
<cfelseif local.qCfsParam.data_type EQ "map" OR local.qCfsParam.data_type EQ "map-fixed" OR local.qCfsParam.data_type EQ "array-map-fixed">
|
||||
<!--- Не разбираем вариант "sensitive map" --->
|
||||
<!--- <cfset processMap(local.qCfsParam)/> ---><!--- query passed by reference --->
|
||||
<!--- query passed by reference --->
|
||||
<!--- маскируем секреты в map --->
|
||||
<!--- *** сделано ненадежно, с расчетом на структуру qCfsParam (ради этого ее пришлось дополнить) --->
|
||||
<!--- что характерно, мы передаем запрос (с фокусом, установленным на текущую строку) по ссылке и прямо там ее патчим --->
|
||||
@@ -341,70 +309,42 @@
|
||||
</cfif>
|
||||
</cfif>
|
||||
</cfloop>
|
||||
|
||||
<!--- грубо и цинично патчим запрос --->
|
||||
<cfset local.qCurrentState.params = serializeJson(local.params)/>
|
||||
<cfcatch type="ANY"><!--- *** <cfrethrow/>---></cfcatch>
|
||||
<cfcatch type="ANY"></cfcatch>
|
||||
</cftry>
|
||||
|
||||
<!--- ---------------------------------------------------------------------------------- --->
|
||||
|
||||
|
||||
<cfset var out=structNew("linked")/>
|
||||
|
||||
|
||||
<cfset "out.queryDurationMs"=getTickCount() - request.startTickCount/>
|
||||
|
||||
<cfset "out.instance" = this.helper.appendRecord(
|
||||
structNew("linked"), "", local.titleMap, local.qInstance, this.helper.snake2camel
|
||||
)/>
|
||||
<!--- <cfset "out.instance.uptime"=(local.qOperation.is_successful GT 0) ? local.qOperation.seconds_passed : 0/> --->
|
||||
<cfset "out.instance.isCreated"=local.isCreated/>
|
||||
<cfset "out.instance.isDeleted"=local.qCurrentState.is_deleted GT 0/>
|
||||
<!--- <cfset "out.instance.vaultData"=local.vaultData/> --->
|
||||
|
||||
<cfset "out.instance.state" = (local.qCurrentState.recordCount GT 0) ? this.helper.appendRecord(structNew("linked"), "", local.currentStateTitleMap, local.qCurrentState, this.helper.snake2camel) : {}/>
|
||||
|
||||
<cfset "out.instance.operations"=[]/>
|
||||
<cfloop query=#local.qOperation#>
|
||||
<cfset arrayAppend(out.instance.operations, this.helper.appendRecord(structNew("linked"), "", local.operationTitleMap, local.qOperation, this.helper.snake2camel))/>
|
||||
</cfloop>
|
||||
|
||||
<cfset "out.instance.availableOperations"=[]/>
|
||||
<cfloop query=#local.qAvailableOperation#>
|
||||
<cfset arrayAppend(out.instance.availableOperations, this.helper.appendRecord(structNew("linked"), "", local.availableOperationTitleMap, local.qAvailableOperation, this.helper.snake2camel))/>
|
||||
</cfloop>
|
||||
|
||||
<!--- <cfset "out.instance.dependencies0"=#dependencies#/> --->
|
||||
|
||||
<cfset "out.instance.dependentInstances"=[]/>
|
||||
<cfloop query=#local.qDependentInstance#>
|
||||
<cfset arrayAppend(out.instance.dependentInstances, this.helper.appendRecord(structNew("linked"), "", local.dependentInstanceTitleMap, local.qDependentInstance, this.helper.snake2camel))/>
|
||||
</cfloop>
|
||||
|
||||
<cfset "out.instance.dependencies"=[]/>
|
||||
<cfloop query=#local.qDependency#>
|
||||
<cfset arrayAppend(out.instance.dependencies, this.helper.appendRecord(structNew("linked"), "", local.dependencyTitleMap, local.qDependency, this.helper.snake2camel))/>
|
||||
</cfloop>
|
||||
<!--- <cfset "out.instance.availableResourceRealms"=[]/>
|
||||
<cfloop query=#local.qAvailableResourceRealm#>
|
||||
<cfset arrayAppend(out.instance.availableResourceRealms, this.helper.appendRecord(structNew("linked"), "", local.realmTitleMap, local.qAvailableResourceRealm, this.helper.snake2camel))/>
|
||||
</cfloop> --->
|
||||
|
||||
<cfset "out.runDurationMs"=getTickCount() - request.startTickCount/>
|
||||
<!--- <cfdump var=#local.qCurrentState#/>
|
||||
<cfdump var=#out#/>
|
||||
<cfabort/> --->
|
||||
<cfreturn representationOf(out) />
|
||||
</cffunction>
|
||||
|
||||
|
||||
<cffunction name="patch">
|
||||
<cfargument name="instanceUid" type="string" required=true hint="type:guid"/>
|
||||
<cfargument name="displayName" type="string" required=false hint="type:string"/>
|
||||
<!--- <cfargument name="resourceRealmId" type="string" required=false hint="type:integer"/> --->
|
||||
<cfargument name="descr" type="string" required=false default="" hint="type:varchar (no cleanup here!)"/>
|
||||
|
||||
<!--- ****** проверка уникальности --->
|
||||
<cftry>
|
||||
<cfset checkDisplayName(arguments.displayName, arguments.usrId, arguments.instanceUid)/><!--- как идея - офорить как обертку, возвращающую то же значение. Но будет соблазн еще оттримить иначе пофиксить, а это уже избыточная функция и должно усложнить название --->
|
||||
@@ -416,42 +356,28 @@
|
||||
<cfif structKeyExists(arguments,"displayName")>
|
||||
,display_name=<cfqueryparam cfsqltype="cf_sql_varchar" value="#htmlEditFormat(arguments.displayName)#" />
|
||||
</cfif>
|
||||
<!--- <cfif structKeyExists(arguments,"displayName")>
|
||||
,resource_realm_id=<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.resourceRealmId#" />
|
||||
</cfif> --->
|
||||
<cfif structKeyExists(arguments,"descr")>
|
||||
,descr=<cfqueryparam cfsqltype="cf_sql_varchar" value="#htmlEditFormat(arguments.descr)#" />
|
||||
</cfif>
|
||||
where instance_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceUid#" />;
|
||||
--select @@rowcount as cnt;
|
||||
</cfquery>
|
||||
|
||||
<!--- <cfif local.qSave.cnt EQ 0>
|
||||
<cfreturn noData().withStatus(404, "Record Not Found") />
|
||||
</cfif> --->
|
||||
|
||||
<cfcatch type="invalidParamValue">
|
||||
<cfreturn representationOf(this.helper.formatBadRequestError(cfcatch)).withStatus(400)/>
|
||||
</cfcatch>
|
||||
</cftry>
|
||||
|
||||
<cfreturn noData().withStatus(204, "No Content") />
|
||||
</cffunction>
|
||||
|
||||
<cffunction name="delete" hint="Удаление экземпляра сервиса по ключу. Допускается в статусе not configured">
|
||||
<cfargument name="instanceUid" type="string" required=true hint="type:guid"/>
|
||||
|
||||
<cftry>
|
||||
<cfset this.helper.validateField(arguments, "instanceUid", "guid")/>
|
||||
|
||||
<cfcatch type="invalidParamValue">
|
||||
<cfreturn representationOf(this.helper.formatBadRequestError(cfcatch)).withStatus(400)/>
|
||||
</cfcatch>
|
||||
</cftry>
|
||||
|
||||
<cfset local={}/>
|
||||
<cftry>
|
||||
|
||||
<cfquery name="local.qCheckAccess" result="local.result">
|
||||
select count(*) as cnt
|
||||
from instance e
|
||||
@@ -465,7 +391,6 @@
|
||||
"Instance is not accessible for the current user (possibly does not belong to the default specification)")
|
||||
).withStatus(404)/>
|
||||
</cfif>
|
||||
|
||||
<!--- халява какая-то --->
|
||||
<cfquery name="local.qCheckOperation" result="local.result">
|
||||
select count(*) as cnt
|
||||
@@ -479,7 +404,6 @@
|
||||
"Operation already started", "Instance deletion disabled when operation is started")
|
||||
).withStatus(422)/>
|
||||
</cfif>
|
||||
|
||||
<cfquery name="local.qCheckState" result="local.result">
|
||||
select count(*) as cnt
|
||||
from instance_state st
|
||||
@@ -491,7 +415,6 @@
|
||||
"Instance has a state", "Instance deletion disabled when having state")
|
||||
).withStatus(422)/>
|
||||
</cfif>
|
||||
|
||||
<!--- мы не включаем проверку доступа в саму операцию удаления, а выполняем отдельно --->
|
||||
<cfquery name="local.qSave">
|
||||
delete from instance_state
|
||||
@@ -501,26 +424,18 @@
|
||||
delete from instance
|
||||
where instance_uid=<cfqueryparam cfsqltype="cf_sql_other" value="#arguments.instanceUid#" null=#!isValid('guid',arguments.instanceUid)#/>;
|
||||
</cfquery>
|
||||
|
||||
<cfcatch type="any">
|
||||
<cfreturn representationOf(this.helper.formatException(cfcatch, "Internal Error")).withStatus(500)/><!--- это не нужно показывать в продуктиве --->
|
||||
</cfcatch>
|
||||
</cftry>
|
||||
|
||||
<cfreturn noData().withStatus(204, "No Content") />
|
||||
</cffunction><!--- delete --->
|
||||
|
||||
|
||||
|
||||
<!--- неудобно бегать из одного компонента в соседний при том, что разделение ответственности между ними получается довольно странное
|
||||
Решил, что логичнее повесить проверки уникальности и генерацию дефолтов на коллекцию, тем более и связей так меньше --->
|
||||
|
||||
<cffunction name="checkDisplayName">
|
||||
<cfargument name="displayName" required=true/>
|
||||
<cfargument name="usrId" type="numeric" required=true/>
|
||||
<cfargument name="instanceUid" type="guid" required=true/>
|
||||
|
||||
<cfset CreateObject("component", "instance_ls").checkDisplayName(arguments.displayName, arguments.usrId, arguments.instanceUid)/>
|
||||
</cffunction>
|
||||
|
||||
</cfcomponent>
|
||||
</cfcomponent>
|
||||
|
||||
Reference in New Issue
Block a user