@defra/grants-config-utils 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/config/config.js
CHANGED
|
@@ -72,6 +72,14 @@ export const config = convict({
|
|
|
72
72
|
env: "GRANTS_CONFIG_BROKER_API_ENDPOINT",
|
|
73
73
|
},
|
|
74
74
|
},
|
|
75
|
+
configPublish: {
|
|
76
|
+
status: {
|
|
77
|
+
doc: "Config publish status",
|
|
78
|
+
format: String,
|
|
79
|
+
default: "active",
|
|
80
|
+
env: "GRANTS_CONFIG_PUBLISH_STATUS",
|
|
81
|
+
},
|
|
82
|
+
},
|
|
75
83
|
});
|
|
76
84
|
|
|
77
85
|
config.validate({ allowed: "strict" });
|
|
@@ -101,22 +101,26 @@ const notifyConfigBrokerServiceVersionAvailable = async (
|
|
|
101
101
|
logger,
|
|
102
102
|
) => {
|
|
103
103
|
const configBrokerEndpoint = config.get("configBroker.apiEndpoint");
|
|
104
|
+
const configPublishStatus = config.get("configPublish.status");
|
|
104
105
|
|
|
105
106
|
// iterate each grant configuration, notify config available at current service version
|
|
106
107
|
for (const configAtServiceVersion of configsAtServiceVersion) {
|
|
107
|
-
await
|
|
108
|
+
await sendConfigMessageToBroker(
|
|
108
109
|
configBrokerEndpoint,
|
|
109
110
|
configAtServiceVersion,
|
|
111
|
+
configPublishStatus,
|
|
110
112
|
logger,
|
|
111
113
|
);
|
|
112
114
|
}
|
|
113
115
|
};
|
|
114
116
|
|
|
115
|
-
const
|
|
117
|
+
const sendConfigMessageToBroker = async (
|
|
116
118
|
configBrokerEndpoint,
|
|
117
119
|
configAtServiceVersion,
|
|
120
|
+
configPublishStatus,
|
|
118
121
|
logger,
|
|
119
122
|
) => {
|
|
123
|
+
// TODO BH check service topic set instead
|
|
120
124
|
if (!configBrokerEndpoint?.length) {
|
|
121
125
|
logger.warn(
|
|
122
126
|
`config broker endpoint not set, so skipping release config call`,
|
|
@@ -132,7 +136,7 @@ const callReleaseConfigEndpoint = async (
|
|
|
132
136
|
grant,
|
|
133
137
|
version,
|
|
134
138
|
files: s3Paths,
|
|
135
|
-
status:
|
|
139
|
+
status: configPublishStatus,
|
|
136
140
|
};
|
|
137
141
|
|
|
138
142
|
const url = new URL(`/api/release-config`, configBrokerEndpoint);
|
|
@@ -16,6 +16,7 @@ vi.mock("../config/config.js", () => ({
|
|
|
16
16
|
serviceVersion: "1.2.3",
|
|
17
17
|
serviceName: "grants-config-playground",
|
|
18
18
|
"configBroker.apiEndpoint": "https://broker.unit.test",
|
|
19
|
+
"configPublish.status": "active",
|
|
19
20
|
};
|
|
20
21
|
return values[key];
|
|
21
22
|
},
|
|
@@ -105,7 +106,22 @@ describe("storeConfigVersionAndInformBroker", () => {
|
|
|
105
106
|
expect(listFiles).toHaveBeenCalledTimes(1);
|
|
106
107
|
expect(readFileSync).toHaveBeenCalledTimes(1);
|
|
107
108
|
expect(uploadBlob).toHaveBeenCalledTimes(1);
|
|
108
|
-
expect(fetch).
|
|
109
|
+
expect(fetch).toHaveBeenCalledWith(
|
|
110
|
+
"https://broker.unit.test/api/release-config",
|
|
111
|
+
{
|
|
112
|
+
method: "POST",
|
|
113
|
+
headers: {
|
|
114
|
+
"Content-Type": "application/json",
|
|
115
|
+
authorization: "Bearer token",
|
|
116
|
+
},
|
|
117
|
+
body: JSON.stringify({
|
|
118
|
+
grant: "grant-1",
|
|
119
|
+
version: "1.2.3",
|
|
120
|
+
files: ["grant-1/1.2.3/main.json"],
|
|
121
|
+
status: "active",
|
|
122
|
+
}),
|
|
123
|
+
},
|
|
124
|
+
);
|
|
109
125
|
});
|
|
110
126
|
|
|
111
127
|
it("should not store or inform when already published by config broker", async () => {
|