diff --git a/app/apollo/resolvers/channel.js b/app/apollo/resolvers/channel.js index 19c156560..521f637ba 100644 --- a/app/apollo/resolvers/channel.js +++ b/app/apollo/resolvers/channel.js @@ -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 ); } @@ -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, @@ -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 ); @@ -681,7 +686,7 @@ const channelResolvers = { metadata: { type: 'remote', }, - remote: { parameters: remote.parameters }, + remote: { remoteType: remote.remoteType, parameters: remote.parameters }, }; } } diff --git a/app/apollo/schema/channel.js b/app/apollo/schema/channel.js index 78448e437..4ca0b80b0 100644 --- a/app/apollo/schema/channel.js +++ b/app/apollo/schema/channel.js @@ -32,6 +32,7 @@ const channelSchema = gql` parameters: [ParameterInput] } input VersionRemoteInput { + remoteType: String parameters: [ParameterInput] } input VersionInput { @@ -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 { diff --git a/app/apollo/schema/subscription.js b/app/apollo/schema/subscription.js index 65528f880..b2e22927a 100644 --- a/app/apollo/schema/subscription.js +++ b/app/apollo/schema/subscription.js @@ -18,6 +18,7 @@ const { gql } = require('apollo-server-express'); const subscriptionSchema = gql` input VersionRemoteInput { + remoteType: String parameters: [ParameterInput] } input VersionInput { diff --git a/app/apollo/test/channel.remote.spec.js b/app/apollo/test/channel.remote.spec.js index d38463d54..823828032 100644 --- a/app/apollo/test/channel.remote.spec.js +++ b/app/apollo/test/channel.remote.spec.js @@ -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, @@ -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', @@ -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) { diff --git a/app/apollo/utils/versionUtils.js b/app/apollo/utils/versionUtils.js index f7ce8c59f..c891a4ac5 100644 --- a/app/apollo/utils/versionUtils.js +++ b/app/apollo/utils/versionUtils.js @@ -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 ) { diff --git a/app/utils/subscriptions.js b/app/utils/subscriptions.js index b54850a4a..f16c705e3 100644 --- a/app/utils/subscriptions.js +++ b/app/utils/subscriptions.js @@ -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 => {