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

Allow remoteType to be overridden at the Version level #1230

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions app/apollo/resolvers/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ const channelResolvers = {
}

// Validate remote.remoteType
if( !remote.remoteType || !Object.values(CHANNEL_CONSTANTS.REMOTE.TYPES).includes( remote.remoteType ) ) {
if( remote.remoteType && !Object.values(CHANNEL_CONSTANTS.REMOTE.TYPES).includes( remote.remoteType ) ) {
throw new RazeeValidationError( context.req.t( 'The remote type {{remoteType}} is not valid. Allowed values: [{{remoteTypes}}]', { remoteType: remote.remoteType, 'remoteTypes': Array.from( Object.values(CHANNEL_CONSTANTS.REMOTE.TYPES) ).join(' ') } ), context );
}

Expand Down Expand Up @@ -335,7 +335,7 @@ const channelResolvers = {
// Keep version uuid for later use when creating subscriptions
v.uuid = versionObj.uuid;

// Attempt to update Version references the channel (the duplication is unfortunate and should be eliminated in the future)
// Attempt to update Version references in the channel (the duplication is unfortunate and should be eliminated in the future)
try {
const channelVersionObj = {
uuid: versionObj.uuid,
Expand Down Expand Up @@ -672,6 +672,11 @@ const channelResolvers = {
// Validate REMOTE-specific values
if( channel.contentType === CHANNEL_CONSTANTS.CONTENTTYPES.REMOTE ) {
if( remote ) {
// Validate remote.remoteType
if( remote.remoteType && !Object.values(CHANNEL_CONSTANTS.REMOTE.TYPES).includes( remote.remoteType ) ) {
throw new RazeeValidationError( context.req.t( 'The remote type {{remoteType}} is not valid. Allowed values: [{{remoteTypes}}]', { remoteType: remote.remoteType, 'remoteTypes': Array.from( Object.values(CHANNEL_CONSTANTS.REMOTE.TYPES) ).join(' ') } ), context );
}

// Validate remote.parameters (length)
if( remote.parameters && JSON.stringify(remote.parameters).length > MAX_REMOTE_PARAMETERS_LENGTH ) {
throw new RazeeValidationError( context.req.t( 'The remote version parameters are too large. The string representation must be less than {{MAX_REMOTE_PARAMETERS_LENGTH}} characters long', { MAX_REMOTE_PARAMETERS_LENGTH } ), context );
Expand All @@ -681,7 +686,7 @@ const channelResolvers = {
metadata: {
type: 'remote',
},
remote: { parameters: remote.parameters },
remote: { remoteType: remote.remoteType, parameters: remote.parameters },
};
}
}
Expand Down
4 changes: 3 additions & 1 deletion app/apollo/schema/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const channelSchema = gql`
parameters: [ParameterInput]
}
input VersionRemoteInput {
remoteType: String
parameters: [ParameterInput]
}
input VersionInput {
Expand Down Expand Up @@ -60,10 +61,11 @@ const channelSchema = gql`
location: String
}
type ChannelRemoteSource {
remoteType: String!
remoteType: String
parameters: [ParameterTuple]
}
type VersionRemoteSource {
remoteType: String
parameters: [ParameterTuple]
}
type Channel {
Expand Down
1 change: 1 addition & 0 deletions app/apollo/schema/subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const { gql } = require('apollo-server-express');

const subscriptionSchema = gql`
input VersionRemoteInput {
remoteType: String
parameters: [ParameterInput]
}
input VersionInput {
Expand Down
5 changes: 3 additions & 2 deletions app/apollo/test/channel.remote.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ describe('channel remote graphql test suite', () => {
}
});

it('add a subscription and version under the remote channel', async () => {
it('add a subscription and version under the remote channel, with a different remoteType', async () => {
try {
const result = await subscriptionApi.addSubscription(userRootToken, {
orgId: org01._id,
Expand All @@ -715,6 +715,7 @@ describe('channel remote graphql test suite', () => {
description: 'version created with a subscription at the same time (swv means subscription with version)',
type: 'yaml',
remote: {
remoteType: 'gitlab',
parameters: [
{
key: 'orig-swv-key1',
Expand Down Expand Up @@ -753,7 +754,7 @@ describe('channel remote graphql test suite', () => {
const sub01 = subscriptions.find( s => s.subscriptionName == 'swv-sub-name' );
expect(sub01).to.be.an('object');
expect(sub01.remote).to.be.an('object');
expect(sub01.remote.remoteType).to.equal('github');
expect(sub01.remote.remoteType).to.equal('gitlab');
expect(sub01.remote.parameters.length).to.equal(2); // One from the Config merged with one from the Version
} catch (error) {
if (error.response) {
Expand Down
7 changes: 6 additions & 1 deletion app/apollo/utils/versionUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,12 @@ const validateNewVersions = async ( org_id, { channel, newVersions }, context )
}

// Normalize (ensure no extra attributes)
v.remote = { parameters: v.remote.parameters };
v.remote = { remoteType: v.remote.remoteType, parameters: v.remote.parameters };

// Validate remote.remoteType
if( v.remote.remoteType && !Object.values(CHANNEL_CONSTANTS.REMOTE.TYPES).includes( v.remote.remoteType ) ) {
throw new RazeeValidationError( context.req.t( 'The remote type {{remoteType}} is not valid. Allowed values: [{{remoteTypes}}]', { remoteType: v.remote.remoteType, 'remoteTypes': Array.from( Object.values(CHANNEL_CONSTANTS.REMOTE.TYPES) ).join(' ') } ), context );
}

// Validate remote.parameters (length)
if( v.remote.parameters && JSON.stringify(v.remote.parameters).length > MAX_REMOTE_PARAMETERS_LENGTH ) {
Expand Down
4 changes: 4 additions & 0 deletions app/utils/subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ const getSubscriptionDetails = async(orgId, matchingSubscriptions, cluster) => {
};
if(versionRefs.length > 0) {
const version = await models.DeployableVersion.findOne( { org_id: orgId, uuid: versionRefs[0].uuid } );
// Combine channel and version remoteType
if( version && version.content.remote.remoteType ) {
sub.remote.remoteType = version.content.remote.remoteType;
}
// Combine channel and version remote params
if( version && version.content.remote.parameters ) {
version.content.remote.parameters.forEach( vp => {
Expand Down