009 cfflush

This commit is contained in:
msyu
2025-10-04 22:46:10 +03:00
parent 1f1f88fc65
commit 6d47dfad0a
2 changed files with 60 additions and 52 deletions
+21 -21
View File
@@ -15,28 +15,27 @@
<cfset this.mappings = structNew() />
<cfset this.mappings["/mod"] = getDirectoryFromPath(getCurrentTemplatePath()) & "mod/" />
<cfset this.customTagPaths = expandPath(getDirectoryFromPath(getCurrentTemplatePath()) & "mod")/>
<cfset this.datasource = "rpt"/>
<!--- SSO --->
<cfset this.client_id = "payg-report.deck.nubes.ru"/>
<cfset this.auth_endpoint = "https://keycloak.nubes.ru/realms/cloud/protocol/openid-connect/auth" />
<cfset this.access_token_endpoint = "https://keycloak.nubes.ru/realms/cloud/protocol/openid-connect/token" />
<cfset this.idpCertUrl = "https://keycloak.nubes.ru/realms/cloud/protocol/openid-connect/certs" />
<cfset this.client_secret = createObject("java", "java.lang.System").getEnv("IDP_CLIENT_SECRET")/>
<!--- <cfset this.client_secret = this.client_secret ?: ""/> --->
<cfset this.datasource = "rpt"/>
<cfset this.defaultdatasource = this.datasource/>
<cfset request.DS = "#this.datasource#">
<cfset request.language="">
<cfset getDS(this.datasource)/>
<!--- кажется, нужно инициализировать датасорцы в псевдоконструкторе - onRequest не получается --->
<!--- *** проверить, что есть - если есть, не создавать --->
<!--- не тут-то было: так не работает --->
<!--- <cfif NOT structKeyExists(this.datasources,this.datasource)>
</cfif> --->
<!--- это работает с административно заданным датасорцем, хотя, казалось бы, не должно
(без окружения фунекция вернет пустую структуру). Видимо, административный датасорц обнаруживается раньше.
(без окружения функция вернет пустую структуру). Видимо, административный датасорц обнаруживается раньше.
Проверять на пустоту не хочется, чтобы не плодить в псевдоконструкторе переменные --->
<cfset this.datasources["#this.datasource#"]=getDS("#this.datasource#","ds_#this.datasource#")/>
<!--- <cfdump var=#variables#/> --->
@@ -48,7 +47,7 @@
hint="Fires when the application is first created.">
<!--- *** мы не проверяем срок жизни сертификата и его отзыв--->
Obtain idp certificate OnApplicationStart
<!--- Obtain idp certificate OnApplicationStart --->
<cfset application.idpCertificate = getIdpCertificate(this.idpCertUrl)/>
<cfreturn true />
@@ -79,7 +78,7 @@
<!--- global settings --->
<cfset request.RECORDS_PER_PAGE=500/>
<cfset request.APP_VERSION="0.00.008"/>
<cfset request.APP_VERSION="0.00.009"/>
<cfset request.STAND=getStand()/>
<!--- application constants --->
@@ -153,7 +152,7 @@
<!--- <cfoutput>onRequest:check for cert finished #(getTickCount()-request.startTickCount)#</cfoutput> --->
<cfset this.redirect_uri = "https://#CGI.SERVER_NAME#/#CGI.SCRIPT_NAME#" />
<cfset this.redirect_uri = "https://#CGI.SERVER_NAME##CGI.SCRIPT_NAME#" />
<cfinclude template="inc/functions.cfm"/>
@@ -336,25 +335,24 @@
</cffunction>
<cffunction
<cffunction
name="getDS"
access="private"
returntype="struct"
returntype="void"
output="true"
hint="Configure data source from environment variables. Convention: data source name is an environment varialble prefix">
hint="Configure data source from environment variables (if datasource with the name provided already exists, does nothing). Convention: data source name is an environment varialble prefix">
<cfargument name="dsname" type="string" required="true"/>
<cfargument name="prefix" type="string" default=#dsname#/>
<cfset var ds={}/>
<cfargument name="prefix" type="string" default=#dsname#/>
<cftry>
<cfquery name="qTestDs" datasource=#arguments.dsname#>
select 1;
</cfquery>
<cfcatch type="any">
<cfset system = createObject("java", "java.lang.System")/>
<cfcatch type="any">
<cfset var ds={}/>
<cfset var system = createObject("java", "java.lang.System")/>
<cfloop list="class,connectionString,database,driver,dbdriver,host,port,type,url,username,password,bundleName,bundleVersion,connectionLimit,liveTimeout,validate" item="field"><!--- driver vs dbdriver --->
<cfset var value=system.getEnv("#arguments.prefix#_#field#")/>
@@ -368,8 +366,8 @@
<!--- test datasource (just to get exception if invalid) --->
<cftry>
<cfquery name="qTestDs" datasource=#ds#>
select 1;
<cfquery name="qTestDsNextTry" datasource=#ds#>
select 2;
</cfquery>
<cfcatch type="any">
@@ -379,10 +377,12 @@
<cfrethrow/>
</cfcatch>
</cftry>
<cfset this.datasources["#arguments.dsname#"]=#ds#/> <!--- Интересно, доступен ли здесь this --->
</cfcatch>
</cftry>
<!--- <cfdump var=#ds#/> --->
<cfreturn ds/>
<cfreturn/>
</cffunction>
<cfscript>