Skip to content

Commit

Permalink
0.2.5 Fixes (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Oded Messer authored Apr 3, 2020
1 parent 1b5c72f commit bdd313d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 24 deletions.
22 changes: 16 additions & 6 deletions frontend/server/handlers/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
);
Expand Down Expand Up @@ -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();
Expand Down
23 changes: 16 additions & 7 deletions frontend/src/lib/Apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
20 changes: 9 additions & 11 deletions frontend/src/lib/GkeMetadata.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -9,13 +7,13 @@ export interface GkeMetadata {
export const GkeMetadataContext = React.createContext<GkeMetadata>({});
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 <GkeMetadataContext.Provider value={metadata} {...props} />;
};

0 comments on commit bdd313d

Please sign in to comment.