Skip to content

Commit 2ac05da

Browse files
committed
Updated models swapping logic
1 parent 4a7b203 commit 2ac05da

34 files changed

Lines changed: 694 additions & 303 deletions

DSL/CronManager/DSL/delete_from_vault.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ delete_secrets:
22
trigger: off
33
type: exec
44
command: "/app/scripts/delete_secrets_from_vault.sh"
5-
allowedEnvs: ['cookie', 'connectionId','llmPlatform', 'llmModel','embeddingModel','embeddingPlatform','deploymentEnvironment']
5+
allowedEnvs: ['cookie', 'connectionId','vaultUuid','llmPlatform', 'llmModel','embeddingModel','embeddingPlatform']

DSL/CronManager/DSL/store_in_vault.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ store_secrets:
22
trigger: off
33
type: exec
44
command: "/app/scripts/store_secrets_in_vault.sh"
5-
allowedEnvs: ['cookie', 'connectionId','llmPlatform', 'llmModel','secretKey','accessKey','deploymentName','targetUrl','apiKey','embeddingModel','embeddingPlatform','embeddingAccessKey','embeddingSecretKey','embeddingDeploymentName','embeddingTargetUri','embeddingAzureApiKey','deploymentEnvironment']
5+
allowedEnvs: ['cookie', 'connectionId','vaultUuid','llmPlatform', 'llmModel','secretKey','accessKey','deploymentName','targetUrl','apiKey','embeddingModel','embeddingPlatform','embeddingAccessKey','embeddingSecretKey','embeddingDeploymentName','embeddingTargetUri','embeddingAzureApiKey','deploymentEnvironment']

DSL/CronManager/script/delete_secrets_from_vault.sh

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,19 @@ log "=== Starting Vault Secrets Deletion ==="
2020
# Debug: Print received parameters
2121
log "Received parameters:"
2222
log " connectionId: $connectionId"
23+
log " vaultUuid: $vaultUuid"
2324
log " llmPlatform: $llmPlatform"
2425
log " llmModel: $llmModel"
2526
log " embeddingModel: $embeddingModel"
2627
log " embeddingPlatform: $embeddingPlatform"
27-
log " deploymentEnvironment: $deploymentEnvironment"
2828
log " Vault Address: $VAULT_ADDR"
2929

30+
# Validate required vaultUuid parameter
31+
if [ -z "$vaultUuid" ]; then
32+
log "ERROR: vaultUuid is required but not provided"
33+
exit 1
34+
fi
35+
3036
# Note: No token required - vault agent proxy automatically injects authentication
3137

3238
# Function to determine platform name
@@ -49,17 +55,13 @@ get_model_name() {
4955
echo "$model_array" | sed 's/\[//g' | sed 's/\]//g' | sed 's/"//g' | cut -d',' -f1 | xargs
5056
}
5157

52-
# Function to build vault path
58+
# Function to build vault path (uses vaultUuid as stable path terminal)
5359
build_vault_path() {
5460
local secret_type=$1 # "llm" or "embeddings"
5561
local platform_name=$2
56-
local model_name=$3
5762

58-
if [ "$deploymentEnvironment" = "testing" ]; then
59-
echo "secret/$secret_type/connections/$platform_name/$deploymentEnvironment/$connectionId"
60-
else
61-
echo "secret/$secret_type/connections/$platform_name/$deploymentEnvironment/$model_name"
62-
fi
63+
# UUID-based path: no environment in path, swap is DB-only
64+
echo "secret/$secret_type/connections/$platform_name/$vaultUuid"
6365
}
6466

6567
# Function to delete vault secret (both data and metadata)
@@ -125,27 +127,26 @@ delete_vault_secret() {
125127

126128
# Function to delete LLM secrets
127129
delete_llm_secrets() {
128-
if [ -z "$llmPlatform" ] || [ -z "$llmModel" ]; then
129-
log "No LLM platform or model specified, skipping LLM secrets deletion"
130+
if [ -z "$llmPlatform" ]; then
131+
log "No LLM platform specified, skipping LLM secrets deletion"
130132
return 0
131133
fi
132134

133135
local platform_name=$(get_platform_name "$llmPlatform")
134-
local model_name=$(get_model_name "$llmModel")
135-
local vault_path=$(build_vault_path "llm" "$platform_name" "$model_name")
136+
local vault_path=$(build_vault_path "llm" "$platform_name")
136137

137138
delete_vault_secret "$vault_path" "LLM secrets"
138139
}
139140

140141
# Function to delete embedding secrets
141142
delete_embedding_secrets() {
142-
if [ -z "$embeddingPlatform" ] || [ -z "$embeddingModel" ]; then
143-
log "No embedding platform or model specified, skipping embedding secrets deletion"
143+
if [ -z "$embeddingPlatform" ]; then
144+
log "No embedding platform specified, skipping embedding secrets deletion"
144145
return 0
145146
fi
146147

147148
local platform_name=$(get_platform_name "$embeddingPlatform")
148-
local vault_path=$(build_vault_path "embeddings" "$platform_name" "$embeddingModel")
149+
local vault_path=$(build_vault_path "embeddings" "$platform_name")
149150

150151
delete_vault_secret "$vault_path" "Embedding secrets"
151152
}

DSL/CronManager/script/store_secrets_in_vault.sh

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,18 @@ setup_python_environment() {
165165
log "=== Starting Vault Secrets Storage ==="
166166
log "Received parameters:"
167167
log " connectionId: $connectionId"
168+
log " vaultUuid: $vaultUuid"
168169
log " llmPlatform: $llmPlatform"
169170
log " llmModel: $llmModel"
170171
log " deploymentEnvironment: $deploymentEnvironment"
171172
log " Vault Address: $VAULT_ADDR"
172173

174+
# Validate required vaultUuid parameter
175+
if [ -z "$vaultUuid" ]; then
176+
log "ERROR: vaultUuid is required but not provided"
177+
exit 1
178+
fi
179+
173180
# Redirect stderr to stdout so cron-manager can capture all logs
174181
exec 2>&1
175182

@@ -197,24 +204,13 @@ get_model_name() {
197204
echo "$llmModel" | sed 's/\[//g' | sed 's/\]//g' | sed 's/"//g' | cut -d',' -f1 | xargs
198205
}
199206

200-
# Function to build vault path
207+
# Function to build vault path (uses vaultUuid as stable path terminal)
201208
build_vault_path() {
202209
local secret_type=$1 # "llm" or "embeddings"
203210
local platform=$(get_platform_name)
204211

205-
# Use appropriate model based on secret type
206-
local model
207-
if [ "$secret_type" = "embeddings" ]; then
208-
model="$embeddingModel"
209-
else
210-
model=$(get_model_name)
211-
fi
212-
213-
if [ "$deploymentEnvironment" = "testing" ]; then
214-
echo "secret/$secret_type/connections/$platform/$deploymentEnvironment/$connectionId"
215-
else
216-
echo "secret/$secret_type/connections/$platform/$deploymentEnvironment/$model"
217-
fi
212+
# UUID-based path: no environment in path, swap is DB-only
213+
echo "secret/$secret_type/connections/$platform/$vaultUuid"
218214
}
219215

220216
# Function to store LLM secrets
@@ -275,15 +271,13 @@ store_aws_llm_secrets() {
275271
--arg conn_id "$connectionId" \
276272
--arg access_key "$decrypted_access_key" \
277273
--arg secret_key "$decrypted_secret_key" \
278-
--arg env "$deploymentEnvironment" \
279274
--arg model "$model" \
280275
'{data: {
281276
connection_id: $conn_id,
282277
access_key: $access_key,
283278
secret_key: $secret_key,
284-
environment: $env,
285279
model: $model,
286-
tags: "aws,bedrock,\($env),\($model)"
280+
tags: "aws,bedrock,\($model)"
287281
}}')
288282

289283
log "Storing secrets at path: $vault_path"
@@ -337,17 +331,15 @@ store_azure_llm_secrets() {
337331
--arg endpoint "$targetUrl" \
338332
--arg api_key "$decrypted_api_key" \
339333
--arg deploy_name "$deploymentName" \
340-
--arg env "$deploymentEnvironment" \
341334
--arg model "$model" \
342335
'{data: {
343336
connection_id: $conn_id,
344337
endpoint: $endpoint,
345338
api_key: $api_key,
346339
deployment_name: $deploy_name,
347-
environment: $env,
348340
model: $model,
349341
api_version: "2024-05-01-preview",
350-
tags: "azure,\($env),\($model)"
342+
tags: "azure,\($model)"
351343
}}')
352344

353345
log "Storing secrets at path: $vault_path"
@@ -405,15 +397,13 @@ store_aws_embedding_secrets() {
405397
--arg conn_id "$connectionId" \
406398
--arg access_key "$decrypted_embedding_access_key" \
407399
--arg secret_key "$decrypted_embedding_secret_key" \
408-
--arg env "$deploymentEnvironment" \
409400
--arg model "$embeddingModel" \
410401
'{data: {
411402
connection_id: $conn_id,
412403
access_key: $access_key,
413404
secret_key: $secret_key,
414-
environment: $env,
415405
model: $model,
416-
tags: "aws,bedrock,embedding,\($env),\($model)"
406+
tags: "aws,bedrock,embedding,\($model)"
417407
}}')
418408

419409
log "Storing secrets at path: $vault_path"
@@ -466,17 +456,15 @@ store_azure_embedding_secrets() {
466456
--arg endpoint "$embeddingTargetUri" \
467457
--arg api_key "$decrypted_embedding_api_key" \
468458
--arg deploy_name "$embeddingDeploymentName" \
469-
--arg env "$deploymentEnvironment" \
470459
--arg model "$embeddingModel" \
471460
'{data: {
472461
connection_id: $conn_id,
473462
endpoint: $endpoint,
474463
api_key: $api_key,
475464
deployment_name: $deploy_name,
476-
environment: $env,
477465
model: $model,
478466
api_version: "2024-12-01-preview",
479-
tags: "azure,embedding,\($env),\($model)"
467+
tags: "azure,embedding,\($model)"
480468
}}')
481469

482470
log "Storing secrets at path: $vault_path"
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-- liquibase formatted sql
2+
3+
-- changeset uuid-vault-path:rag-script-v8-changeset1
4+
-- Add UUID column to llm_connections for stable Vault secret paths
5+
ALTER TABLE rag_search.llm_connections
6+
ADD COLUMN IF NOT EXISTS vault_uuid UUID DEFAULT gen_random_uuid();
7+
8+
-- Backfill existing rows with unique UUIDs
9+
UPDATE rag_search.llm_connections SET vault_uuid = gen_random_uuid() WHERE vault_uuid IS NULL;
10+
11+
-- Make it NOT NULL after backfill
12+
ALTER TABLE rag_search.llm_connections ALTER COLUMN vault_uuid SET NOT NULL;
13+
14+
-- Add unique constraint
15+
ALTER TABLE rag_search.llm_connections ADD CONSTRAINT llm_connections_vault_uuid_unique UNIQUE (vault_uuid);
16+
-- rollback ALTER TABLE rag_search.llm_connections DROP CONSTRAINT IF EXISTS llm_connections_vault_uuid_unique; ALTER TABLE rag_search.llm_connections DROP COLUMN IF EXISTS vault_uuid;

DSL/Liquibase/master.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ databaseChangeLog:
1212
- include:
1313
file: changelog/rag-search-script-v6-endpoints.sql
1414
- include:
15-
file: changelog/rag-search-script-v7-schema-migration.sql
15+
file: changelog/rag-search-script-v7-schema-migration.sql
16+
- include:
17+
file: changelog/rag-search-script-v8-uuid-vault-path.sql
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-- liquibase formatted sql
2+
3+
-- changeset uuid-vault-path:rag-script-v8-changeset1
4+
-- Add UUID column to llm_connections for stable Vault secret paths
5+
ALTER TABLE rag_search.llm_connections
6+
ADD COLUMN IF NOT EXISTS vault_uuid UUID DEFAULT gen_random_uuid();
7+
8+
-- Backfill existing rows with unique UUIDs
9+
UPDATE rag_search.llm_connections SET vault_uuid = gen_random_uuid() WHERE vault_uuid IS NULL;
10+
11+
-- Make it NOT NULL after backfill
12+
ALTER TABLE rag_search.llm_connections ALTER COLUMN vault_uuid SET NOT NULL;
13+
14+
-- Add unique constraint
15+
ALTER TABLE rag_search.llm_connections ADD CONSTRAINT llm_connections_vault_uuid_unique UNIQUE (vault_uuid);
16+
-- rollback ALTER TABLE rag_search.llm_connections DROP CONSTRAINT IF EXISTS llm_connections_vault_uuid_unique; ALTER TABLE rag_search.llm_connections DROP COLUMN IF EXISTS vault_uuid;

DSL/Resql/rag-search/POST/get-llm-connection.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
SELECT
22
id,
3+
vault_uuid,
34
connection_name,
45
llm_platform,
56
llm_model,

DSL/Resql/rag-search/POST/get-llm-connections-paginated.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
SELECT
22
id,
3+
vault_uuid,
34
connection_name,
45
llm_platform,
56
llm_model,

DSL/Resql/rag-search/POST/get-production-connection-filtered.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
SELECT
22
id,
3+
vault_uuid,
34
connection_name,
45
llm_platform,
56
llm_model,

0 commit comments

Comments
 (0)