diff --git a/requests/Switcher API.postman_collection.json b/requests/Switcher API.postman_collection.json index 9d80119..2bae3a3 100644 --- a/requests/Switcher API.postman_collection.json +++ b/requests/Switcher API.postman_collection.json @@ -5271,7 +5271,7 @@ "header": [], "body": { "mode": "raw", - "raw": "{\r\n \"environment\": \"default\",\r\n \"changes\": [\r\n {\r\n \"action\": \"CHANGED\",\r\n \"diff\": \"CONFIG\",\r\n \"path\": [\r\n \"Group Test\",\r\n \"NEW_SWITCHER_2\"\r\n ],\r\n \"content\": {\r\n \"relay\": {\r\n \"relay_type\": \"NOTIFICATION\",\r\n \"relay_method\": \"POST\",\r\n \"relay_endpoint\": \"https://localhost:3000\",\r\n \"description\": \"Push message to log\",\r\n \"activated\": true\r\n }\r\n }\r\n }\r\n ]\r\n}", + "raw": "{\r\n \"environment\": \"default\",\r\n \"changes\": [\r\n {\r\n \"action\": \"CHANGED\",\r\n \"diff\": \"CONFIG\",\r\n \"path\": [\r\n \"Group Test\",\r\n \"NEW_SWITCHER_2\"\r\n ],\r\n \"content\": {\r\n \"relay\": {\r\n \"type\": \"NOTIFICATION\",\r\n \"method\": \"POST\",\r\n \"endpoint\": \"https://localhost:3000\",\r\n \"description\": \"Push message to log\",\r\n \"activated\": true\r\n }\r\n }\r\n }\r\n ]\r\n}", "options": { "raw": { "language": "json" @@ -5461,7 +5461,7 @@ "header": [], "body": { "mode": "raw", - "raw": "{\r\n \"environment\": \"default\",\r\n \"changes\": [\r\n {\r\n \"action\": \"NEW\",\r\n \"diff\": \"CONFIG\",\r\n \"path\": [\r\n \"New Group\"\r\n ],\r\n \"content\": {\r\n \"key\": \"NEW_SWITCHER_RELAY\",\r\n \"description\": \"New Switcher Relay\",\r\n \"activated\": true,\r\n \"components\": [\r\n \"switcher-playground\"\r\n ],\r\n \"relay\": {\r\n \"relay_type\": \"NOTIFICATION\",\r\n \"relay_method\": \"POST\",\r\n \"relay_endpoint\": \"https://localhost:3000\",\r\n \"description\": \"Push message to log\",\r\n \"activated\": true\r\n }\r\n }\r\n }\r\n ]\r\n}", + "raw": "{\r\n \"environment\": \"default\",\r\n \"changes\": [\r\n {\r\n \"action\": \"NEW\",\r\n \"diff\": \"CONFIG\",\r\n \"path\": [\r\n \"New Group\"\r\n ],\r\n \"content\": {\r\n \"key\": \"NEW_SWITCHER_RELAY\",\r\n \"description\": \"New Switcher Relay\",\r\n \"activated\": true,\r\n \"components\": [\r\n \"switcher-playground\"\r\n ],\r\n \"relay\": {\r\n \"type\": \"NOTIFICATION\",\r\n \"method\": \"POST\",\r\n \"endpoint\": \"https://localhost:3000\",\r\n \"description\": \"Push message to log\",\r\n \"activated\": true\r\n }\r\n }\r\n }\r\n ]\r\n}", "options": { "raw": { "language": "json" @@ -6032,7 +6032,7 @@ "body": { "mode": "graphql", "graphql": { - "query": "query Domain(\r\n $_id: String, \r\n $name: String, \r\n $activated: Boolean, \r\n $environment: String, \r\n $_component: String) {\r\n domain(\r\n _id: $_id, \r\n name: $name, \r\n activated: $activated, \r\n environment: $environment,\r\n _component: $_component\r\n ) {\r\n _id\r\n name\r\n version\r\n description\r\n statusByEnv {\r\n env\r\n value\r\n }\r\n activated\r\n group {\r\n _id\r\n name\r\n description\r\n activated\r\n statusByEnv {\r\n env\r\n value\r\n }\r\n config {\r\n _id\r\n key\r\n description\r\n activated\r\n statusByEnv {\r\n env\r\n value\r\n }\r\n strategies {\r\n _id\r\n strategy\r\n activated\r\n statusByEnv {\r\n env\r\n value\r\n }\r\n operation\r\n values\r\n }\r\n relay {\r\n relay_type\r\n relay_method\r\n relay_endpoint\r\n description\r\n activated\r\n statusByEnv {\r\n env\r\n value\r\n }\r\n }\r\n components\r\n }\r\n }\r\n }\r\n}", + "query": "query Domain(\r\n $_id: String, \r\n $name: String, \r\n $activated: Boolean, \r\n $environment: String, \r\n $_component: String) {\r\n domain(\r\n _id: $_id, \r\n name: $name, \r\n activated: $activated, \r\n environment: $environment,\r\n _component: $_component\r\n ) {\r\n _id\r\n name\r\n version\r\n description\r\n statusByEnv {\r\n env\r\n value\r\n }\r\n activated\r\n group {\r\n _id\r\n name\r\n description\r\n activated\r\n statusByEnv {\r\n env\r\n value\r\n }\r\n config {\r\n _id\r\n key\r\n description\r\n activated\r\n statusByEnv {\r\n env\r\n value\r\n }\r\n strategies {\r\n _id\r\n strategy\r\n activated\r\n statusByEnv {\r\n env\r\n value\r\n }\r\n operation\r\n values\r\n }\r\n relay {\r\n type\r\n method\r\n endpoint\r\n description\r\n activated\r\n statusByEnv {\r\n env\r\n value\r\n }\r\n }\r\n components\r\n }\r\n }\r\n }\r\n}", "variables": "{\r\n \"_id\": \"5e44eb76916dd10048d72542\",\r\n \"activated\": true,\r\n \"environment\": \"\",\r\n \"_component\": \"\"\r\n}" } }, diff --git a/src/client/configuration-type.js b/src/client/configuration-type.js index f2ff27f..7e0516c 100644 --- a/src/client/configuration-type.js +++ b/src/client/configuration-type.js @@ -56,15 +56,13 @@ export const strategyType = new GraphQLObjectType({ export const relayType = new GraphQLObjectType({ name: 'Relay', fields: { - relay_type: { - type: GraphQLString, - resolve: (source) => source.type + type: { + type: GraphQLString }, - relay_method: { - type: GraphQLString, - resolve: (source) => source.method + method: { + type: GraphQLString }, - relay_endpoint: { + endpoint: { type: GraphQLString, resolve: (source, _args, { environment }) => { return source.endpoint[`${environment}`] === undefined ? diff --git a/src/services/config.js b/src/services/config.js index 137aee7..c993d74 100644 --- a/src/services/config.js +++ b/src/services/config.js @@ -331,7 +331,7 @@ export async function verifyRelay(id, env, admin) { export function isRelayValid(relay) { const bypass = process.env.RELAY_BYPASS_HTTPS === 'true' || false; - if (bypass || !relay.endpoint) { + if (bypass || !relay?.endpoint) { return; } diff --git a/src/services/gitops/push-changed.js b/src/services/gitops/push-changed.js index 4bfab6a..1bc7575 100644 --- a/src/services/gitops/push-changed.js +++ b/src/services/gitops/push-changed.js @@ -36,9 +36,9 @@ async function processChangedConfig(domain, change, environment) { if (content.relay) { await updateConfigRelay(config._id, processRelay({ - type: content.relay.relay_type, - method: content.relay.relay_method, - endpoint: content.relay.relay_endpoint, + type: content.relay.type, + method: content.relay.method, + endpoint: content.relay.endpoint, description: content.relay.description, activated: content.relay.activated }, config.relay, environment), admin); diff --git a/src/services/gitops/push-new.js b/src/services/gitops/push-new.js index 8df85a8..b35559a 100644 --- a/src/services/gitops/push-new.js +++ b/src/services/gitops/push-new.js @@ -58,10 +58,10 @@ async function processNewConfig(domain, change, environment) { if (content.relay) { newConfig.relay = { - type: content.relay.relay_type, - method: content.relay.relay_method, + type: content.relay.type, + method: content.relay.method, endpoint: { - [environment]: content.relay.relay_endpoint + [environment]: content.relay.endpoint }, description: content.relay.description, activated: { diff --git a/tests/gitops.test.js b/tests/gitops.test.js index 3b6e15d..7debf72 100644 --- a/tests/gitops.test.js +++ b/tests/gitops.test.js @@ -208,9 +208,9 @@ describe('GitOps - Push New', () => { key: 'NEW_SWITCHER_RELAY', activated: true, relay: { - relay_type: RelayTypes.NOTIFICATION, - relay_method: RelayMethods.POST, - relay_endpoint: 'https://localhost:3000', + type: RelayTypes.NOTIFICATION, + method: RelayMethods.POST, + endpoint: 'https://localhost:3000', description: 'New Relay', activated: true } @@ -475,9 +475,9 @@ describe('GitOps - Push Changed', () => { path: ['Group Test', 'TEST_CONFIG_KEY_PRD_QA'], content: { relay: { - relay_type: RelayTypes.NOTIFICATION, - relay_method: RelayMethods.POST, - relay_endpoint: 'https://localhost:3000', + type: RelayTypes.NOTIFICATION, + method: RelayMethods.POST, + endpoint: 'https://localhost:3000', description: 'New Relay', activated: true } @@ -523,7 +523,7 @@ describe('GitOps - Push Changed', () => { path: ['Group Test', 'TEST_CONFIG_KEY'], content: { relay: { - relay_endpoint: 'http://localhost:3001', + endpoint: 'http://localhost:3001', activated: false } } diff --git a/tests/graphql-utils/index.js b/tests/graphql-utils/index.js index 4f412fe..da88778 100644 --- a/tests/graphql-utils/index.js +++ b/tests/graphql-utils/index.js @@ -43,9 +43,9 @@ export const domainQuery = (where, group, config, strategy) => { strategy activated operation values statusByEnv { env value } } relay { - relay_type - relay_method - relay_endpoint + type + method + endpoint description activated statusByEnv { @@ -185,9 +185,9 @@ export const expected102 = ` ] }], "relay": { - "relay_type": "NOTIFICATION", - "relay_method": "POST", - "relay_endpoint": "http://localhost:3000", + "type": "NOTIFICATION", + "method": "POST", + "endpoint": "http://localhost:3000", "description": "Test Relay", "activated": true }