Skip to content

Commit ae0619c

Browse files
authored
Fixes Relay validation for HTTPS requirement (#547)
1 parent af01009 commit ae0619c

File tree

7 files changed

+28
-30
lines changed

7 files changed

+28
-30
lines changed

requests/Switcher API.postman_collection.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5271,7 +5271,7 @@
52715271
"header": [],
52725272
"body": {
52735273
"mode": "raw",
5274-
"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}",
5274+
"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}",
52755275
"options": {
52765276
"raw": {
52775277
"language": "json"
@@ -5461,7 +5461,7 @@
54615461
"header": [],
54625462
"body": {
54635463
"mode": "raw",
5464-
"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}",
5464+
"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}",
54655465
"options": {
54665466
"raw": {
54675467
"language": "json"
@@ -6032,7 +6032,7 @@
60326032
"body": {
60336033
"mode": "graphql",
60346034
"graphql": {
6035-
"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}",
6035+
"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}",
60366036
"variables": "{\r\n \"_id\": \"5e44eb76916dd10048d72542\",\r\n \"activated\": true,\r\n \"environment\": \"\",\r\n \"_component\": \"\"\r\n}"
60376037
}
60386038
},

src/client/configuration-type.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,13 @@ export const strategyType = new GraphQLObjectType({
5656
export const relayType = new GraphQLObjectType({
5757
name: 'Relay',
5858
fields: {
59-
relay_type: {
60-
type: GraphQLString,
61-
resolve: (source) => source.type
59+
type: {
60+
type: GraphQLString
6261
},
63-
relay_method: {
64-
type: GraphQLString,
65-
resolve: (source) => source.method
62+
method: {
63+
type: GraphQLString
6664
},
67-
relay_endpoint: {
65+
endpoint: {
6866
type: GraphQLString,
6967
resolve: (source, _args, { environment }) => {
7068
return source.endpoint[`${environment}`] === undefined ?

src/services/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ export async function verifyRelay(id, env, admin) {
331331
export function isRelayValid(relay) {
332332
const bypass = process.env.RELAY_BYPASS_HTTPS === 'true' || false;
333333

334-
if (bypass || !relay.endpoint) {
334+
if (bypass || !relay?.endpoint) {
335335
return;
336336
}
337337

src/services/gitops/push-changed.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ async function processChangedConfig(domain, change, environment) {
3636

3737
if (content.relay) {
3838
await updateConfigRelay(config._id, processRelay({
39-
type: content.relay.relay_type,
40-
method: content.relay.relay_method,
41-
endpoint: content.relay.relay_endpoint,
39+
type: content.relay.type,
40+
method: content.relay.method,
41+
endpoint: content.relay.endpoint,
4242
description: content.relay.description,
4343
activated: content.relay.activated
4444
}, config.relay, environment), admin);

src/services/gitops/push-new.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ async function processNewConfig(domain, change, environment) {
5858

5959
if (content.relay) {
6060
newConfig.relay = {
61-
type: content.relay.relay_type,
62-
method: content.relay.relay_method,
61+
type: content.relay.type,
62+
method: content.relay.method,
6363
endpoint: {
64-
[environment]: content.relay.relay_endpoint
64+
[environment]: content.relay.endpoint
6565
},
6666
description: content.relay.description,
6767
activated: {

tests/gitops.test.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,9 @@ describe('GitOps - Push New', () => {
208208
key: 'NEW_SWITCHER_RELAY',
209209
activated: true,
210210
relay: {
211-
relay_type: RelayTypes.NOTIFICATION,
212-
relay_method: RelayMethods.POST,
213-
relay_endpoint: 'https://localhost:3000',
211+
type: RelayTypes.NOTIFICATION,
212+
method: RelayMethods.POST,
213+
endpoint: 'https://localhost:3000',
214214
description: 'New Relay',
215215
activated: true
216216
}
@@ -475,9 +475,9 @@ describe('GitOps - Push Changed', () => {
475475
path: ['Group Test', 'TEST_CONFIG_KEY_PRD_QA'],
476476
content: {
477477
relay: {
478-
relay_type: RelayTypes.NOTIFICATION,
479-
relay_method: RelayMethods.POST,
480-
relay_endpoint: 'https://localhost:3000',
478+
type: RelayTypes.NOTIFICATION,
479+
method: RelayMethods.POST,
480+
endpoint: 'https://localhost:3000',
481481
description: 'New Relay',
482482
activated: true
483483
}
@@ -523,7 +523,7 @@ describe('GitOps - Push Changed', () => {
523523
path: ['Group Test', 'TEST_CONFIG_KEY'],
524524
content: {
525525
relay: {
526-
relay_endpoint: 'http://localhost:3001',
526+
endpoint: 'http://localhost:3001',
527527
activated: false
528528
}
529529
}

tests/graphql-utils/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ export const domainQuery = (where, group, config, strategy) => {
4343
strategy activated operation values statusByEnv { env value }
4444
}
4545
relay {
46-
relay_type
47-
relay_method
48-
relay_endpoint
46+
type
47+
method
48+
endpoint
4949
description
5050
activated
5151
statusByEnv {
@@ -185,9 +185,9 @@ export const expected102 = `
185185
]
186186
}],
187187
"relay": {
188-
"relay_type": "NOTIFICATION",
189-
"relay_method": "POST",
190-
"relay_endpoint": "http://localhost:3000",
188+
"type": "NOTIFICATION",
189+
"method": "POST",
190+
"endpoint": "http://localhost:3000",
191191
"description": "Test Relay",
192192
"activated": true
193193
}

0 commit comments

Comments
 (0)