Parcourir la source

Read Abacus API key from server env var

master
Nano il y a 6 jours
Parent
révision
ad6caa909c
2 fichiers modifiés avec 41 ajouts et 2 suppressions
  1. +2
    -2
      app/controllers/AdminController.asp
  2. +39
    -0
      core/helpers.asp

+ 2
- 2
app/controllers/AdminController.asp Voir le fichier

@@ -151,8 +151,8 @@ Class AdminController_Class
End Sub

Private Sub GeneratePostContentFromAI(ByRef post, ByRef generatedSummary, ByRef generatedBody)
Dim apiKey : apiKey = Trim(CStr(GetAppSetting("AbacusApiKey")))
If Len(apiKey) = 0 Or LCase(apiKey) = "nothing" Then
Dim apiKey : apiKey = Trim(CStr(GetSecureSetting("AbacusApiKey", "ABACUS_API_KEY")))
If Len(apiKey) = 0 Then
Err.Raise 1, "AdminController.GeneratePostContentFromAI", "Abacus API key is not configured."
End If



+ 39
- 0
core/helpers.asp Voir le fichier

@@ -56,6 +56,45 @@ Public Function GetAppSetting(key)
GetAppSetting = "nothing"
End Function

Public Function GetEnvironmentValue(name)
Dim shell, env, value
value = ""

On Error Resume Next
Set shell = Server.CreateObject("WScript.Shell")
Set env = shell.Environment("PROCESS")
If Err.Number = 0 Then
value = env(name)
If Err.Number <> 0 Then
Err.Clear
value = ""
End If
Else
Err.Clear
End If
On Error GoTo 0

GetEnvironmentValue = Trim(CStr(value))
End Function

Public Function GetSecureSetting(key, envName)
Dim value

value = Trim(CStr(GetAppSetting(key)))
If Len(value) > 0 And LCase(value) <> "nothing" Then
GetSecureSetting = value
Exit Function
End If

value = Trim(CStr(GetEnvironmentValue(envName)))
If Len(value) > 0 Then
GetSecureSetting = value
Exit Function
End If

GetSecureSetting = ""
End Function

Public Sub ShowServerVariables
Dim varName, htmlTable
htmlTable = "<table border='1' cellspacing='0' cellpadding='5'>"


Chargement…
Annuler
Enregistrer

Powered by TurnKey Linux.