Skip to content

Commit

Permalink
chore: update ec2 tests
Browse files Browse the repository at this point in the history
..and clean up imports.

Signed-off-by: Humair Khan <[email protected]>
  • Loading branch information
HumairAK committed Jun 20, 2024
1 parent 4d5ebdb commit bf809f2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 32 deletions.
10 changes: 5 additions & 5 deletions frontend/server/handlers/artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
// limitations under the License.
import fetch from 'node-fetch';
import { AWSConfigs, HttpConfigs, MinioConfigs, ProcessEnv } from '../configs';
import {Client as MinioClient} from 'minio';
import {PreviewStream, findFileOnPodVolume, parseJSONString} from '../utils';
import { Client as MinioClient } from 'minio';
import { PreviewStream, findFileOnPodVolume, parseJSONString } from '../utils';
import {createMinioClient, getObjectStream} from '../minio-helper';
import * as serverInfo from '../helpers/server-info';
import { Handler, Request, Response } from 'express';
Expand All @@ -24,9 +24,9 @@ import { HACK_FIX_HPM_PARTIAL_RESPONSE_HEADERS } from '../consts';

import * as fs from 'fs';
import { isAllowedDomain } from './domain-checker';
import {getK8sSecret} from "../k8s-helper";
import {StorageOptions} from "@google-cloud/storage/build/src/storage";
import {CredentialBody} from "google-auth-library/build/src/auth/credentials";
import { getK8sSecret } from "../k8s-helper";
import { StorageOptions } from "@google-cloud/storage/build/src/storage";
import { CredentialBody } from "google-auth-library/build/src/auth/credentials";

/**
* ArtifactsQueryStrings describes the expected query strings key value pairs
Expand Down
32 changes: 12 additions & 20 deletions frontend/server/minio-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
import * as zlib from 'zlib';
import { PassThrough } from 'stream';
import { Client as MinioClient } from 'minio';
import { awsInstanceProfileCredentials } from './aws-helper';
import { createMinioClient, isTarball, maybeTarball, getObjectStream } from './minio-helper';
import { V1beta1JobTemplateSpec } from '@kubernetes/client-node';
const { fromNodeProviderChain } = require('@aws-sdk/credential-providers');

jest.mock('minio');
jest.mock('./aws-helper');
jest.mock('@aws-sdk/credential-providers');

describe('minio-helper', () => {
const MockedMinioClient: jest.Mock = MinioClient as any;
Expand Down Expand Up @@ -57,30 +56,23 @@ describe('minio-helper', () => {
});

it('uses EC2 metadata credentials if access key are not provided.', async () => {
(awsInstanceProfileCredentials.getCredentials as jest.Mock).mockImplementation(() =>
Promise.resolve({
AccessKeyId: 'AccessKeyId',
Code: 'Success',
Expiration: new Date(Date.now() + 1000).toISOString(), // expires 1 sec later
LastUpdated: '2019-12-17T10:55:38Z',
SecretAccessKey: 'SecretAccessKey',
Token: 'SessionToken',
Type: 'AWS-HMAC',
}),
(fromNodeProviderChain as jest.Mock).mockImplementation(() =>
() =>
Promise.resolve({
accessKeyId: 'AccessKeyId',
secretAccessKey: 'SecretAccessKey',
sessionToken: 'SessionToken',
})
);
(awsInstanceProfileCredentials.ok as jest.Mock).mockImplementation(() =>
Promise.resolve(true),
);

const client = await createMinioClient({ endPoint: 's3.awsamazon.com' }, 's3');

const client = await createMinioClient({ endPoint: 's3.amazonaws.com' }, 's3');
expect(client).toBeInstanceOf(MinioClient);
expect(MockedMinioClient).toHaveBeenCalledWith({
accessKey: 'AccessKeyId',
endPoint: 's3.awsamazon.com',
endPoint: 's3.amazonaws.com',
secretKey: 'SecretAccessKey',
sessionToken: 'SessionToken',
});
expect(MockedMinioClient).toBeCalledTimes(1);
});
});

Expand Down
10 changes: 5 additions & 5 deletions frontend/server/minio-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import peek from 'peek-stream';
import gunzip from 'gunzip-maybe';
import { URL } from 'url';
import { Client as MinioClient, ClientOptions as MinioClientOptions } from 'minio';
import { awsInstanceProfileCredentials, isAWSS3Endpoint } from './aws-helper';
import { S3ProviderInfo} from "./handlers/artifacts";
import {getK8sSecret} from "./k8s-helper";
import {parseJSONString} from "./utils";
const { fromNodeProviderChain, fromEnv } = require('@aws-sdk/credential-providers');
import { isAWSS3Endpoint } from './aws-helper';
import { S3ProviderInfo } from "./handlers/artifacts";
import { getK8sSecret } from "./k8s-helper";
import { parseJSONString } from "./utils";
const { fromNodeProviderChain } = require('@aws-sdk/credential-providers');
/** MinioRequestConfig describes the info required to retrieve an artifact. */
export interface MinioRequestConfig {
bucket: string;
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/tabs/InputOutputTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import {
getArtifactName,
getArtifactTypeName,
getArtifactTypes,
getLinkedArtifactsByExecution, getStoreSessionInfoFromArtifact,
getLinkedArtifactsByExecution,
getStoreSessionInfoFromArtifact,
LinkedArtifact,
} from 'src/mlmd/MlmdUtils';
import { ArtifactType, Execution } from 'src/third_party/mlmd';
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/viewers/MetricsVisualizations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import { getMetadataValue } from 'src/mlmd/library';
import {
filterArtifactsByType,
filterLinkedArtifactsByType,
getArtifactName, getStoreSessionInfoFromArtifact,
getArtifactName,
getStoreSessionInfoFromArtifact,
LinkedArtifact,
} from 'src/mlmd/MlmdUtils';
import { Artifact, ArtifactType, Execution } from 'src/third_party/mlmd';
Expand Down

0 comments on commit bf809f2

Please sign in to comment.