Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate clickable artifact url for s3 URI #3531

Merged
merged 4 commits into from
May 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion frontend/src/components/ArtifactLink.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import * as React from 'react';
import { generateGcsConsoleUri, generateMinioArtifactUrl } from '../lib/Utils';
import {
generateGcsConsoleUri,
generateS3ArtifactUrl,
generateMinioArtifactUrl,
} from '../lib/Utils';

/**
* A component that renders an artifact URL as clickable link if URL is correct
Expand All @@ -12,6 +16,9 @@ export const ArtifactLink: React.FC<{ artifactUri?: string }> = ({ artifactUri }
if (gcsConsoleUrl) {
clickableUrl = gcsConsoleUrl;
}
}
if (artifactUri.startsWith('s3:')) {
clickableUrl = generateS3ArtifactUrl(artifactUri);
} else if (artifactUri.startsWith('http:') || artifactUri.startsWith('https:')) {
clickableUrl = artifactUri;
} else if (artifactUri.startsWith('minio:')) {
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/lib/Utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
enabledDisplayString,
formatDateString,
generateMinioArtifactUrl,
generateS3ArtifactUrl,
getRunDuration,
getRunDurationFromWorkflow,
logger,
Expand Down Expand Up @@ -253,4 +254,12 @@ describe('Utils', () => {
expect(generateMinioArtifactUrl('ZZZ://my-bucket/a/b/c')).toBe(undefined);
});
});

describe('generateS3ArtifactUrl', () => {
it('handles s3:// URIs', () => {
expect(generateS3ArtifactUrl('s3://my-bucket/a/b/c')).toBe(
'artifacts/get?source=s3&bucket=my-bucket&key=a%2Fb%2Fc',
);
});
});
});
20 changes: 20 additions & 0 deletions frontend/src/lib/Utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,26 @@ export function generateMinioArtifactUrl(minioUri: string, peek?: number): strin
return generateArtifactUrl('minio', matches[1], matches[2], peek);
}

const S3_URI_PREFIX = 's3://';
/**
* Generates an HTTPS API URL from s3:// uri
*
* @param s3Uri S3 uri that starts with s3://, like s3://ml-pipeline/path/file
* @returns A URL that leads to the artifact data. Returns undefined when s3Uri is not valid.
*/
export function generateS3ArtifactUrl(s3Uri: string): string | undefined {
if (!s3Uri.startsWith(S3_URI_PREFIX)) {
return undefined;
}

// eslint-disable-next-line no-useless-escape
const matches = s3Uri.match(/^s3:\/\/([^\/]+)\/(.+)$/);
if (matches == null) {
return undefined;
}
return generateArtifactUrl('s3', matches[1], matches[2]);
}

export function buildQuery(queriesMap: { [key: string]: string | number | undefined }): string {
const queryContent = Object.entries(queriesMap)
.filter((entry): entry is [string, string | number] => entry[1] != null)
Expand Down