diff --git a/frontend/server/handlers/artifacts.ts b/frontend/server/handlers/artifacts.ts index b32a27c591c..64710a771b4 100644 --- a/frontend/server/handlers/artifacts.ts +++ b/frontend/server/handlers/artifacts.ts @@ -68,8 +68,10 @@ export function getArtifactsHandler(artifactsConfigs: { if (minio.useV3IO) { const protocol = minio.useSSL ? 'https' : 'http'; const baseUrl = minio.endPoint + ':' + minio.port; - console.log('Using V3IO minio, redirecting to ', protocol.toUpperCase()); - getHttpArtifactsHandler(getHttpUrl(protocol, baseUrl, bucket, key), http.auth)(req, res); + console.log(`Using V3IO minio, redirecting to ${protocol.toUpperCase()}`); + + // forceDefaultAuth - do not use the personalized header when trying to get metadata artifacts + getHttpArtifactsHandler(getHttpUrl(protocol, baseUrl, bucket, key), http.auth, true)(req, res); } else { getMinioArtifactHandler({ bucket, @@ -89,7 +91,8 @@ export function getArtifactsHandler(artifactsConfigs: { case 'http': case 'https': - getHttpArtifactsHandler(getHttpUrl(source, http.baseUrl || '', bucket, key), http.auth)( + console.log(`Getting artifact from webapi with: ${http.auth} path: ${key}`); + getHttpArtifactsHandler(getHttpUrl(source, http.baseUrl || '', bucket, key), http.auth, false)( req, res, ); @@ -121,15 +124,22 @@ function getHttpArtifactsHandler( key: string; defaultValue: string; } = { key: '', defaultValue: '' }, + forceDefaultAuth: boolean, ) { return async (req: Request, res: Response) => { const headers = {}; // add authorization header to fetch request if key is non-empty if (auth.key.length > 0) { - // inject original request's value if exists, otherwise default to provided default value - headers[auth.key] = - req.headers[auth.key] || req.headers[auth.key.toLowerCase()] || auth.defaultValue; + if (forceDefaultAuth) { + + // force using default auth + headers[auth.key] = auth.defaultValue; + } else { + + // inject original request's value if exists, otherwise default to provided default value + headers[auth.key] = req.headers[auth.key] || req.headers[auth.key.toLowerCase()] || auth.defaultValue; + } } const response = await fetch(url, { headers }); const content = await response.buffer(); diff --git a/frontend/src/lib/Apis.ts b/frontend/src/lib/Apis.ts index 540a783abdc..c614056d9bf 100644 --- a/frontend/src/lib/Apis.ts +++ b/frontend/src/lib/Apis.ts @@ -329,13 +329,22 @@ export class Apis { `Path: ${path} is a compressed file. Decompressing`, ); const responseBuffer = await response.arrayBuffer(); - let responseUint8array = gzip.unzip(Buffer.from(responseBuffer)); - responseText = new TextDecoder("utf-8").decode(Buffer.from(responseUint8array)); - - // cleanup and extract contents only - let startIndex = responseText.indexOf("{"); - let endIndex = responseText.lastIndexOf("}"); - responseText = responseText.substring(startIndex, endIndex + 1); + try { + let responseUint8array = gzip.unzip(Buffer.from(responseBuffer)); + responseText = new TextDecoder("utf-8").decode(Buffer.from(responseUint8array)); + + // cleanup and extract contents only + let startIndex = responseText.indexOf("{"); + let endIndex = responseText.lastIndexOf("}"); + responseText = responseText.substring(startIndex, endIndex + 1); + } catch (e) { + responseText = new TextDecoder("utf-8").decode(Buffer.from(responseBuffer)); + + // just log and return the response text + Utils.logger.error( + `Failed to decompress file: ${path}. \nError: ${e}\nContents: ${responseText}`, + ); + } } else { responseText = await response.text(); } diff --git a/frontend/src/lib/GkeMetadata.tsx b/frontend/src/lib/GkeMetadata.tsx index 9b237fea009..2bee939116e 100644 --- a/frontend/src/lib/GkeMetadata.tsx +++ b/frontend/src/lib/GkeMetadata.tsx @@ -1,6 +1,4 @@ -import React, { FC, useState, useEffect } from 'react'; -import { logger, extendError } from './Utils'; -import { Apis } from './Apis'; +import React, { FC, useState } from 'react'; export interface GkeMetadata { projectId?: string; @@ -9,13 +7,13 @@ export interface GkeMetadata { export const GkeMetadataContext = React.createContext({}); export const GkeMetadataProvider: FC<{}> = props => { const [metadata, setMetadata] = useState({}); - useEffect(() => { - Apis.getClusterName() - .then(clusterName => setMetadata(metadata => ({ ...metadata, clusterName }))) - .catch(err => logger.warn(extendError(err, 'Failed getting GKE cluster name'))); - Apis.getProjectId() - .then(projectId => setMetadata(metadata => ({ ...metadata, projectId }))) - .catch(err => logger.warn(extendError(err, 'Failed getting GKE project ID'))); - }, []); + // useEffect(() => { + // Apis.getClusterName() + // .then(clusterName => setMetadata(metadata => ({ ...metadata, clusterName }))) + // .catch(err => logger.warn(extendError(err, 'Failed getting GKE cluster name'))); + // Apis.getProjectId() + // .then(projectId => setMetadata(metadata => ({ ...metadata, projectId }))) + // .catch(err => logger.warn(extendError(err, 'Failed getting GKE project ID'))); + // }, []); return ; };