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

Fix error creating pipeline server when data connection endpoint omits scheme #1778

Merged
merged 1 commit into from
Sep 15, 2023
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
2 changes: 1 addition & 1 deletion frontend/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = {
testEnvironment: 'jest-environment-jsdom',

// include projects from node_modules as required
transformIgnorePatterns: ['node_modules/(?!yaml)'],
transformIgnorePatterns: ['node_modules/(?!yaml|@openshift|lodash-es|uuid)'],

// A list of paths to snapshot serializer modules Jest should use for snapshot testing
snapshotSerializers: [],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import { AWS_KEYS } from '~/pages/projects/dataConnections/const';
import { PipelineServerConfigType } from '~/concepts/pipelines/content/configurePipelinesServer/types';
import { createDSPipelineResourceSpec } from '~/concepts/pipelines/content/configurePipelinesServer/utils';

describe('configure pipeline server utils', () => {
describe('createDSPipelineResourceSpec', () => {
const createPipelineServerConfig = () =>
({
database: {
useDefault: true,
value: [],
},
objectStorage: {
useExisting: true,
existingName: '',
existingValue: [],
},
} as PipelineServerConfigType);

type SecretsResponse = Parameters<typeof createDSPipelineResourceSpec>[1];

const createSecretsResponse = (
databaseSecret?: SecretsResponse[0],
objectStorageSecret?: SecretsResponse[1],
): SecretsResponse => [databaseSecret, objectStorageSecret ?? { secretName: '', awsData: [] }];

it('should create resource spec', () => {
const spec = createDSPipelineResourceSpec(
createPipelineServerConfig(),
createSecretsResponse(),
);
expect(spec).toEqual({
database: undefined,
objectStorage: {
externalStorage: {
bucket: '',
host: '',
s3CredentialsSecret: {
accessKey: 'AWS_ACCESS_KEY_ID',
secretKey: 'AWS_SECRET_ACCESS_KEY',
secretName: '',
},
scheme: 'https',
},
},
});
});

it('should parse S3 endpoint with scheme', () => {
const secretsResponse = createSecretsResponse();
secretsResponse[1].awsData = [
{ key: AWS_KEYS.S3_ENDPOINT, value: 'http://s3.amazonaws.com' },
];
const spec = createDSPipelineResourceSpec(createPipelineServerConfig(), secretsResponse);
expect(spec.objectStorage.externalStorage?.scheme).toBe('http');
expect(spec.objectStorage.externalStorage?.host).toBe('s3.amazonaws.com');
});

it('should parse S3 endpoint without scheme', () => {
const secretsResponse = createSecretsResponse();

secretsResponse[1].awsData = [{ key: AWS_KEYS.S3_ENDPOINT, value: 's3.amazonaws.com' }];
const spec = createDSPipelineResourceSpec(createPipelineServerConfig(), secretsResponse);
expect(spec.objectStorage.externalStorage?.scheme).toBe('https');
expect(spec.objectStorage.externalStorage?.host).toBe('s3.amazonaws.com');
});

it('should include bucket', () => {
const secretsResponse = createSecretsResponse();
secretsResponse[1].awsData = [{ key: AWS_KEYS.AWS_S3_BUCKET, value: 'my-bucket' }];
const spec = createDSPipelineResourceSpec(createPipelineServerConfig(), secretsResponse);
expect(spec.objectStorage.externalStorage?.bucket).toBe('my-bucket');
});

it('should create spec with database object', () => {
const config = createPipelineServerConfig();
config.database.value = [
{
key: 'Username',
value: 'test-user',
},
{
key: 'Port',
value: '8080',
},
{
key: 'Host',
value: 'test.host.com',
},
{
key: 'Database',
value: 'db-name',
},
];
const spec = createDSPipelineResourceSpec(
config,
createSecretsResponse({
key: 'password-key',
name: 'password-name',
}),
);
expect(spec).toEqual({
objectStorage: {
externalStorage: {
bucket: '',
host: '',
s3CredentialsSecret: {
accessKey: 'AWS_ACCESS_KEY_ID',
secretKey: 'AWS_SECRET_ACCESS_KEY',
secretName: '',
},
scheme: 'https',
},
},
database: {
externalDB: {
host: 'test.host.com',
passwordSecret: {
key: 'password-key',
name: 'password-name',
},
pipelineDBName: 'db-name',
port: '8080',
username: 'test-user',
},
},
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,22 @@ const createSecrets = (config: PipelineServerConfigType, projectName: string) =>
.catch(reject);
});

export const configureDSPipelineResourceSpec = (
export const createDSPipelineResourceSpec = (
config: PipelineServerConfigType,
projectName: string,
): Promise<DSPipelineKind['spec']> =>
createSecrets(config, projectName).then(([databaseSecret, objectStorageSecret]) => {
[databaseSecret, objectStorageSecret]: SecretsResponse,
): DSPipelineKind['spec'] => {
{
const awsRecord = dataEntryToRecord(objectStorageSecret.awsData);
const databaseRecord = dataEntryToRecord(config.database.value);

const [, externalStorageScheme, externalStorageHost] =
awsRecord.AWS_S3_ENDPOINT?.match(/^(\w+):\/\/(.*)/) ?? [];
awsRecord.AWS_S3_ENDPOINT?.match(/^(?:(\w+):\/\/)?(.*)/) ?? [];

return {
objectStorage: {
externalStorage: {
host: externalStorageHost.replace(/\/$/, ''),
scheme: externalStorageScheme,
host: externalStorageHost?.replace(/\/$/, '') || '',
scheme: externalStorageScheme || 'https',
bucket: awsRecord.AWS_S3_BUCKET || '',
s3CredentialsSecret: {
accessKey: AWS_KEYS.ACCESS_KEY_ID,
Expand All @@ -155,4 +155,13 @@ export const configureDSPipelineResourceSpec = (
}
: undefined,
};
});
}
};

export const configureDSPipelineResourceSpec = (
config: PipelineServerConfigType,
projectName: string,
): Promise<DSPipelineKind['spec']> =>
createSecrets(config, projectName).then((secretsResponse) =>
createDSPipelineResourceSpec(config, secretsResponse),
);