Skip to content

Commit 5b0bbef

Browse files
committed
eu support for api toolkit
1 parent f608bd4 commit 5b0bbef

2 files changed

Lines changed: 55 additions & 32 deletions

File tree

recipe-portal/app/api/execute/route.ts

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -155,21 +155,43 @@ export async function POST(request: Request) {
155155
const currentTokenInfo = getCurrentTokenInfo();
156156
console.log('Current token info:', currentTokenInfo);
157157

158-
// Auto-populate authentication variables from current token if not explicitly provided or empty
159-
if (currentTokenInfo && (!envVariables || !envVariables.CLIENT_ID || envVariables.CLIENT_ID.trim() === '')) {
160-
// Replace empty CLIENT_ID with the populated one
161-
envContent = envContent.replace(/^CLIENT_ID=\s*$/m, `CLIENT_ID=${currentTokenInfo.clientId}`);
162-
console.log('Auto-populated CLIENT_ID from token:', currentTokenInfo.clientId?.substring(0,8) + '...');
163-
}
164-
if (currentTokenInfo && (!envVariables || !envVariables.baseURL || envVariables.baseURL.trim() === '')) {
165-
// Replace empty baseURL with the populated one
166-
envContent = envContent.replace(/^baseURL=\s*$/m, `baseURL=${currentTokenInfo.baseURL}`);
167-
console.log('Auto-populated baseURL from token:', currentTokenInfo.baseURL);
168-
}
169-
if (currentTokenInfo && (!envVariables || !envVariables.authURL || envVariables.authURL.trim() === '')) {
170-
// Replace empty authURL with the populated one
171-
envContent = envContent.replace(/^authURL=\s*$/m, `authURL=${currentTokenInfo.authURL}`);
172-
console.log('Auto-populated authURL from token:', currentTokenInfo.authURL);
158+
// --- Auto-populate authentication variables from current token ---
159+
if (currentTokenInfo) {
160+
const BASE_URL_DEFAULT = 'https://aws-api.sigmacomputing.com/v2';
161+
const AUTH_URL_DEFAULT = 'https://aws-api.sigmacomputing.com/v2/auth/token';
162+
163+
// 1. CLIENT_ID: Check for missing or empty value
164+
const isClientIdMissingOrEmpty = !envVariables || !envVariables.CLIENT_ID || (typeof envVariables.CLIENT_ID === 'string' && envVariables.CLIENT_ID.trim() === '');
165+
166+
if (isClientIdMissingOrEmpty && currentTokenInfo.clientId) {
167+
// FIX: Use appending (last value wins) instead of fragile replace.
168+
envContent += `CLIENT_ID=${currentTokenInfo.clientId}\n`;
169+
console.log('Auto-populated CLIENT_ID from token:', currentTokenInfo.clientId?.substring(0,8) + '...');
170+
}
171+
172+
// 2. baseURL: Check for missing/empty OR if the generic default was provided but the token has a specific URL.
173+
const isBaseUrlMissingOrDefault = !envVariables || // envVariables is null/undefined
174+
envVariables.baseURL === undefined || // baseURL key is missing
175+
(typeof envVariables.baseURL === 'string' && envVariables.baseURL.trim() === '') || // baseURL is empty string
176+
(envVariables.baseURL === BASE_URL_DEFAULT && currentTokenInfo.baseURL !== BASE_URL_DEFAULT); // Default but token has regional
177+
178+
if (isBaseUrlMissingOrDefault && currentTokenInfo.baseURL) {
179+
// FIX: Use appending (last value wins) to ensure the token's regional URL is used.
180+
envContent += `baseURL=${currentTokenInfo.baseURL}\n`;
181+
console.log('Auto-populated baseURL from token:', currentTokenInfo.baseURL);
182+
}
183+
184+
// 3. authURL: Check for missing/empty OR if the generic default was provided but the token has a specific URL.
185+
const isAuthUrlMissingOrDefault = !envVariables || // envVariables is null/undefined
186+
envVariables.authURL === undefined ||
187+
(typeof envVariables.authURL === 'string' && envVariables.authURL.trim() === '') || // authURL is empty string
188+
(envVariables.authURL === AUTH_URL_DEFAULT && currentTokenInfo.authURL !== AUTH_URL_DEFAULT); // Default but token has regional
189+
190+
if (isAuthUrlMissingOrDefault && currentTokenInfo.authURL) {
191+
// FIX: Use appending (last value wins) to ensure the token's regional URL is used.
192+
envContent += `authURL=${currentTokenInfo.authURL}\n`;
193+
console.log('Auto-populated authURL from token:', currentTokenInfo.authURL);
194+
}
173195
}
174196

175197
fs.writeFileSync(tempEnvPath, envContent);

recipe-portal/components/CodeViewer.tsx

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,31 +1175,32 @@ export function CodeViewer({ isOpen, onClose, filePath, fileName, envVariables =
11751175
Server Endpoint <span className="text-red-600">*</span>
11761176
</label>
11771177
<select
1178-
value={envValues['baseURL'] || 'https://aws-api.sigmacomputing.com/v2'}
1178+
id="server-endpoint-select" // Added id for A11y
1179+
value={envValues['baseURL'] || 'https://aws-api.sigmacomputing.com'}
11791180
onChange={(e) => {
11801181
const baseURL = e.target.value;
1181-
let authURL;
1182-
if (baseURL === 'https://api.sigmacomputing.com') {
1183-
authURL = baseURL + '/v2/auth/token';
1184-
} else {
1185-
authURL = baseURL + '/auth/token';
1186-
}
1182+
1183+
// ✅ SIMPLIFIED LOGIC: All endpoints now use /v2/auth/token
1184+
const AUTH_TOKEN_PATH = '/auth/token';
1185+
const authURL = baseURL + AUTH_TOKEN_PATH;
1186+
11871187
handleEnvChange('baseURL', baseURL);
11881188
handleEnvChange('authURL', authURL);
11891189
}}
11901190
className="w-full px-3 py-2 border border-gray-300 rounded-md text-sm focus:border-blue-500 focus:ring-1 focus:ring-blue-500"
11911191
>
1192-
<option value="https://api.sigmacomputing.com">GCP hosted organizations</option>
1192+
1193+
<option value="https://api.sigmacomputing.com/v2">GCP hosted organizations</option>
11931194
<option value="https://aws-api.sigmacomputing.com/v2">AWS US (West) hosted organizations</option>
1194-
<option value="https://api.us-a.aws.sigmacomputing.com">AWS US (East) hosted organizations</option>
1195-
<option value="https://api.ca.aws.sigmacomputing.com">AWS Canada hosted organizations</option>
1196-
<option value="https://api.eu.aws.sigmacomputing.com">AWS Europe hosted organizations</option>
1197-
<option value="https://api.au.aws.sigmacomputing.com">AWS Australia hosted organizations</option>
1198-
<option value="https://api.uk.aws.sigmacomputing.com">AWS UK hosted organizations</option>
1199-
<option value="https://api.us.azure.sigmacomputing.com">Azure US hosted organizations</option>
1200-
<option value="https://api.eu.azure.sigmacomputing.com">Azure Europe hosted organizations</option>
1201-
<option value="https://api.ca.azure.sigmacomputing.com">Azure Canada hosted organizations</option>
1202-
<option value="https://api.uk.azure.sigmacomputing.com">Azure UK hosted organizations</option>
1195+
<option value="https://api.us-a.aws.sigmacomputing.com/v2">AWS US (East) hosted organizations</option>
1196+
<option value="https://api.ca.aws.sigmacomputing.com/v2">AWS Canada hosted organizations</option>
1197+
<option value="https://api.eu.aws.sigmacomputing.com/v2">AWS Europe hosted organizations</option>
1198+
<option value="https://api.au.aws.sigmacomputing.com/v2">AWS Australia hosted organizations</option>
1199+
<option value="https://api.uk.aws.sigmacomputing.com/v2">AWS UK hosted organizations</option>
1200+
<option value="https://api.us.azure.sigmacomputing.com/v2">Azure US hosted organizations</option>
1201+
<option value="https://api.eu.azure.sigmacomputing.com/v2">Azure Europe hosted organizations</option>
1202+
<option value="https://api.ca.azure.sigmacomputing.com/v2">Azure Canada hosted organizations</option>
1203+
<option value="https://api.uk.azure.sigmacomputing.com/v2">Azure UK hosted organizations</option>
12031204
</select>
12041205
</div>
12051206

0 commit comments

Comments
 (0)