@defra/grants-config-utils 0.2.0 → 0.3.0
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/.github/workflows/check-pull-request.yml +6 -3
- package/.github/workflows/release.yml +5 -5
- package/.husky/pre-commit +16 -0
- package/CHANGELOG.md +15 -0
- package/README.md +10 -0
- package/package.json +1 -1
- package/src/config/config.js +8 -0
- package/src/service/config-store-and-inform.js +48 -10
- package/src/service/config-store-and-inform.test.js +182 -115
|
@@ -18,8 +18,11 @@ jobs:
|
|
|
18
18
|
name: Run Pull Request Checks
|
|
19
19
|
runs-on: ubuntu-latest
|
|
20
20
|
steps:
|
|
21
|
-
- uses: actions/checkout@v6
|
|
22
|
-
|
|
21
|
+
- uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 #v6
|
|
22
|
+
with:
|
|
23
|
+
fetch-depth: 0
|
|
24
|
+
|
|
25
|
+
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e #v6.4.0
|
|
23
26
|
with:
|
|
24
27
|
node-version-file: .nvmrc
|
|
25
28
|
registry-url: "https://registry.npmjs.org/"
|
|
@@ -43,7 +46,7 @@ jobs:
|
|
|
43
46
|
- name: SonarCloud Scan
|
|
44
47
|
if: github.actor != 'dependabot[bot]' &&
|
|
45
48
|
!startsWith(github.head_ref, 'changeset-release/')
|
|
46
|
-
uses: SonarSource/sonarqube-scan-action@
|
|
49
|
+
uses: SonarSource/sonarqube-scan-action@7006c4492b2e0ee0f816d36501671557c97f5995 #8.1.0
|
|
47
50
|
env:
|
|
48
51
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
49
52
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
|
@@ -25,13 +25,13 @@ jobs:
|
|
|
25
25
|
|
|
26
26
|
steps:
|
|
27
27
|
- name: Checkout repository
|
|
28
|
-
uses: actions/checkout@v6
|
|
28
|
+
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 #v6
|
|
29
29
|
with:
|
|
30
30
|
fetch-depth: 0
|
|
31
31
|
fetch-tags: true
|
|
32
32
|
|
|
33
33
|
- name: Set up Node.js
|
|
34
|
-
uses: actions/setup-node@v6
|
|
34
|
+
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e #v6.4.0
|
|
35
35
|
with:
|
|
36
36
|
node-version-file: .nvmrc
|
|
37
37
|
registry-url: "https://registry.npmjs.org/"
|
|
@@ -44,7 +44,7 @@ jobs:
|
|
|
44
44
|
|
|
45
45
|
- name: SonarCloud Scan
|
|
46
46
|
if: github.actor != 'dependabot[bot]' && github.actor != 'github-actions[bot]' && !contains(github.event.head_commit.message, 'Create new config version')
|
|
47
|
-
uses: SonarSource/sonarqube-scan-action@
|
|
47
|
+
uses: SonarSource/sonarqube-scan-action@7006c4492b2e0ee0f816d36501671557c97f5995 #8.1.0
|
|
48
48
|
env:
|
|
49
49
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
50
50
|
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
|
|
@@ -54,7 +54,7 @@ jobs:
|
|
|
54
54
|
|
|
55
55
|
- name: Create Release Pull Request or Release
|
|
56
56
|
id: changesets
|
|
57
|
-
uses: changesets/action@v1
|
|
57
|
+
uses: changesets/action@a45c4d594aa4e2c509dc14a9f2b3b67ba3780d0d #v1.9.0
|
|
58
58
|
with:
|
|
59
59
|
commitMode: 'github-api'
|
|
60
60
|
publish: npm run github:release
|
|
@@ -63,7 +63,7 @@ jobs:
|
|
|
63
63
|
|
|
64
64
|
- name: Trigger required checks on release PR, then merge to main, and delete release branch
|
|
65
65
|
if: ${{ !startsWith(github.event_name == 'push' && github.event.head_commit.message || inputs.commit_message, 'Create new config version') }}
|
|
66
|
-
uses: actions/github-script@
|
|
66
|
+
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 #v9.0.0
|
|
67
67
|
with:
|
|
68
68
|
script: |
|
|
69
69
|
const prNumber = Number("${{ steps.changesets.outputs.pullRequestNumber }}");
|
package/.husky/pre-commit
CHANGED
|
@@ -1 +1,17 @@
|
|
|
1
1
|
npx lint-staged
|
|
2
|
+
|
|
3
|
+
branch="$(git symbolic-ref --short HEAD)"
|
|
4
|
+
currentUser="$(git config user.name)"
|
|
5
|
+
if [ "$currentUser" != "github-actions[bot]" ]; then
|
|
6
|
+
if [ "$branch" = "main" ]; then
|
|
7
|
+
echo "❌ Pushing to main is not allowed!"
|
|
8
|
+
exit 1
|
|
9
|
+
fi
|
|
10
|
+
if git diff --name-only origin/HEAD...HEAD >/dev/null; then
|
|
11
|
+
if ! compgen -G ".changeset/*-*-*.md" > /dev/null; then
|
|
12
|
+
echo "❌ Make sure you have added a changeset file"
|
|
13
|
+
echo "Run: npm run version"
|
|
14
|
+
exit 1
|
|
15
|
+
fi
|
|
16
|
+
fi
|
|
17
|
+
fi
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @defra/grants-config-utils
|
|
2
2
|
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 3f948bf: feat(GRAN-8): Allow async contact with config-broker
|
|
8
|
+
|
|
9
|
+
Update actions versions
|
|
10
|
+
Add to pre-commit hook to ensure changeset added
|
|
11
|
+
|
|
12
|
+
## 0.2.1
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- 512774f: Status defaults to active and is now configurable
|
|
17
|
+
|
|
3
18
|
## 0.2.0
|
|
4
19
|
|
|
5
20
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -24,6 +24,16 @@ The following variables are used in this module:
|
|
|
24
24
|
- `CONFIG_BUCKET_NAME` - **Required** The S3 bucket where the config is to be stored
|
|
25
25
|
- `FORCE_PATH_STYLE` - Optional flag to force path style URLs when using S3 bucket (default true)
|
|
26
26
|
- `AWS_ENDPOINT_URL` - Optional AWS endpoint URL for local development
|
|
27
|
+
- `GRANTS_CONFIG_PUBLISH_STATUS` - Optional override for status used on publish of config versions (default 'active')
|
|
28
|
+
|
|
29
|
+
Depending on which mechanism is used to publish config versions, the following environment variables may be required:
|
|
30
|
+
|
|
31
|
+
**To publish asynchronously via SNS (Recommended)**
|
|
32
|
+
|
|
33
|
+
- `GFR__SNS__CONFIG_VERSION_ARN` - **Required** ARN of the SNS topic to publish config version events to
|
|
34
|
+
|
|
35
|
+
**To publish synchronously via REST API**
|
|
36
|
+
|
|
27
37
|
- `GRANTS_CONFIG_BROKER_AUTH_TOKEN` - **Required** Auth token for the grants config broker API
|
|
28
38
|
- `GRANTS_CONFIG_BROKER_ENCRYPTION_KEY` - **Required** Encryption key for the grants config broker API
|
|
29
39
|
- `GRANTS_CONFIG_BROKER_API_ENDPOINT` - **Required** Endpoint for the grants config broker API
|
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" });
|
|
@@ -2,6 +2,11 @@ import { readFileSync, existsSync, lstatSync, readdirSync } from "node:fs";
|
|
|
2
2
|
import { config } from "../config/config.js";
|
|
3
3
|
import { listFiles, uploadBlob } from "../s3/s3-interactions.js";
|
|
4
4
|
import { createApiHeadersForConfigBroker } from "../broker/broker-auth-helper.js";
|
|
5
|
+
import {
|
|
6
|
+
isClientSetup,
|
|
7
|
+
publishMessage,
|
|
8
|
+
setupClient,
|
|
9
|
+
} from "../sns/sns-client.js";
|
|
5
10
|
|
|
6
11
|
const configsDirectory = "configurations";
|
|
7
12
|
|
|
@@ -101,29 +106,28 @@ const notifyConfigBrokerServiceVersionAvailable = async (
|
|
|
101
106
|
logger,
|
|
102
107
|
) => {
|
|
103
108
|
const configBrokerEndpoint = config.get("configBroker.apiEndpoint");
|
|
109
|
+
const configSNSTopic = config.get("aws.sns.configVersionTopicArn");
|
|
110
|
+
const configPublishStatus = config.get("configPublish.status");
|
|
104
111
|
|
|
105
112
|
// iterate each grant configuration, notify config available at current service version
|
|
106
113
|
for (const configAtServiceVersion of configsAtServiceVersion) {
|
|
107
|
-
await
|
|
114
|
+
await sendConfigMessageToBroker(
|
|
115
|
+
configSNSTopic,
|
|
108
116
|
configBrokerEndpoint,
|
|
109
117
|
configAtServiceVersion,
|
|
118
|
+
configPublishStatus,
|
|
110
119
|
logger,
|
|
111
120
|
);
|
|
112
121
|
}
|
|
113
122
|
};
|
|
114
123
|
|
|
115
|
-
const
|
|
124
|
+
const sendConfigMessageToBroker = async (
|
|
125
|
+
configSNSTopic,
|
|
116
126
|
configBrokerEndpoint,
|
|
117
127
|
configAtServiceVersion,
|
|
128
|
+
configPublishStatus,
|
|
118
129
|
logger,
|
|
119
130
|
) => {
|
|
120
|
-
if (!configBrokerEndpoint?.length) {
|
|
121
|
-
logger.warn(
|
|
122
|
-
`config broker endpoint not set, so skipping release config call`,
|
|
123
|
-
);
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
131
|
const { grant, version, files } = configAtServiceVersion;
|
|
128
132
|
// files is an array of tuples, we only want the S3 paths here
|
|
129
133
|
const s3Paths = files.map(([_, s3Path]) => s3Path);
|
|
@@ -132,9 +136,20 @@ const callReleaseConfigEndpoint = async (
|
|
|
132
136
|
grant,
|
|
133
137
|
version,
|
|
134
138
|
files: s3Paths,
|
|
135
|
-
status:
|
|
139
|
+
status: configPublishStatus,
|
|
136
140
|
};
|
|
137
141
|
|
|
142
|
+
if (setToUseSNS(configSNSTopic)) {
|
|
143
|
+
return sendViaSNS(payload, configSNSTopic, logger);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (!configBrokerEndpoint?.length) {
|
|
147
|
+
logger.warn(
|
|
148
|
+
`config SNS topic not set, and config broker endpoint not set, so skipping release config call`,
|
|
149
|
+
);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
|
|
138
153
|
const url = new URL(`/api/release-config`, configBrokerEndpoint);
|
|
139
154
|
try {
|
|
140
155
|
const response = await fetch(url.href, {
|
|
@@ -159,3 +174,26 @@ const callReleaseConfigEndpoint = async (
|
|
|
159
174
|
logger.error("call to release config failed", err);
|
|
160
175
|
}
|
|
161
176
|
};
|
|
177
|
+
|
|
178
|
+
const sendViaSNS = async (payload, configSNSTopic, logger) => {
|
|
179
|
+
if (!isClientSetup()) {
|
|
180
|
+
setupClient(logger.child({}), {
|
|
181
|
+
region: config.get("aws.region"),
|
|
182
|
+
endpoint: config.get("aws.endpointUrl"),
|
|
183
|
+
publishToTopic: config.get("aws.sns.configVersionTopicArn"),
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
await publishMessage(payload);
|
|
188
|
+
|
|
189
|
+
logger.info(
|
|
190
|
+
`successfully notified the config broker about '${payload.grant}' at version '${payload.version}' via SNS`,
|
|
191
|
+
);
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
const setToUseSNS = (configSNSTopic) => {
|
|
195
|
+
return (
|
|
196
|
+
configSNSTopic &&
|
|
197
|
+
configSNSTopic !== config.default("aws.sns.configVersionTopicArn")
|
|
198
|
+
);
|
|
199
|
+
};
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import { storeConfigVersionAndInformBroker } from "./config-store-and-inform.js";
|
|
2
2
|
import { readFileSync, existsSync, lstatSync, readdirSync } from "node:fs";
|
|
3
3
|
import { listFiles, uploadBlob } from "../s3/s3-interactions.js";
|
|
4
|
+
import {
|
|
5
|
+
isClientSetup,
|
|
6
|
+
publishMessage,
|
|
7
|
+
setupClient,
|
|
8
|
+
} from "../sns/sns-client.js";
|
|
9
|
+
import { config } from "../config/config.js";
|
|
4
10
|
|
|
5
11
|
vi.mock("node:fs", () => ({
|
|
6
12
|
existsSync: vi.fn(),
|
|
@@ -9,19 +15,6 @@ vi.mock("node:fs", () => ({
|
|
|
9
15
|
readFileSync: vi.fn(() => "file-content"),
|
|
10
16
|
}));
|
|
11
17
|
|
|
12
|
-
vi.mock("../config/config.js", () => ({
|
|
13
|
-
config: {
|
|
14
|
-
get: (key) => {
|
|
15
|
-
const values = {
|
|
16
|
-
serviceVersion: "1.2.3",
|
|
17
|
-
serviceName: "grants-config-playground",
|
|
18
|
-
"configBroker.apiEndpoint": "https://broker.unit.test",
|
|
19
|
-
};
|
|
20
|
-
return values[key];
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
}));
|
|
24
|
-
|
|
25
18
|
vi.mock("../s3/s3-interactions.js", () => ({
|
|
26
19
|
listFiles: vi.fn(() => []),
|
|
27
20
|
uploadBlob: vi.fn(),
|
|
@@ -33,10 +26,13 @@ vi.mock("../broker/broker-auth-helper.js", () => ({
|
|
|
33
26
|
})),
|
|
34
27
|
}));
|
|
35
28
|
|
|
29
|
+
vi.mock("../sns/sns-client.js");
|
|
30
|
+
|
|
36
31
|
const mockLogger = {
|
|
37
32
|
info: vi.fn(),
|
|
38
33
|
warn: vi.fn(),
|
|
39
34
|
error: vi.fn(),
|
|
35
|
+
child: vi.fn(() => mockLogger),
|
|
40
36
|
};
|
|
41
37
|
|
|
42
38
|
describe("storeConfigVersionAndInformBroker", () => {
|
|
@@ -55,6 +51,15 @@ describe("storeConfigVersionAndInformBroker", () => {
|
|
|
55
51
|
}),
|
|
56
52
|
),
|
|
57
53
|
);
|
|
54
|
+
|
|
55
|
+
config.set("serviceVersion", "1.2.3");
|
|
56
|
+
config.set("serviceName", "grants-config-playground");
|
|
57
|
+
config.set("configBroker.apiEndpoint", "https://broker.unit.test");
|
|
58
|
+
config.set("configPublish.status", "active");
|
|
59
|
+
config.set(
|
|
60
|
+
"aws.sns.configVersionTopicArn",
|
|
61
|
+
"arn:aws:sns:us-east-1:123456789012:config-version-topic",
|
|
62
|
+
);
|
|
58
63
|
});
|
|
59
64
|
|
|
60
65
|
afterEach(() => {
|
|
@@ -78,109 +83,171 @@ describe("storeConfigVersionAndInformBroker", () => {
|
|
|
78
83
|
expect(fetch).not.toHaveBeenCalled();
|
|
79
84
|
});
|
|
80
85
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
.
|
|
116
|
-
.
|
|
117
|
-
|
|
118
|
-
name: "main.json",
|
|
119
|
-
isFile: () => true,
|
|
120
|
-
parentPath: "configurations/grant-1",
|
|
121
|
-
},
|
|
122
|
-
]);
|
|
123
|
-
listFiles.mockReturnValueOnce([{ Contents: ["fake-content-1"] }]);
|
|
124
|
-
|
|
125
|
-
await storeConfigVersionAndInformBroker(mockLogger);
|
|
126
|
-
|
|
127
|
-
expect(listFiles).toHaveBeenCalledTimes(1);
|
|
128
|
-
expect(readFileSync).not.toHaveBeenCalled();
|
|
129
|
-
expect(uploadBlob).not.toHaveBeenCalled();
|
|
130
|
-
expect(fetch).not.toHaveBeenCalled();
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it("should call config broker for each config (subdirectory) found in configurations folder", async () => {
|
|
134
|
-
existsSync.mockReturnValue(true);
|
|
135
|
-
lstatSync.mockReturnValue({ isDirectory: () => true });
|
|
136
|
-
readdirSync
|
|
137
|
-
.mockReturnValueOnce([
|
|
138
|
-
{ name: "grant-1", isDirectory: () => true },
|
|
139
|
-
{ name: "grant-2", isDirectory: () => true },
|
|
140
|
-
])
|
|
141
|
-
.mockReturnValueOnce([
|
|
86
|
+
describe("when configurations exist", () => {
|
|
87
|
+
beforeEach(() => {
|
|
88
|
+
existsSync.mockReturnValue(true);
|
|
89
|
+
lstatSync.mockReturnValue({ isDirectory: () => true });
|
|
90
|
+
readdirSync
|
|
91
|
+
.mockReturnValueOnce([{ name: "grant-1", isDirectory: () => true }])
|
|
92
|
+
.mockReturnValueOnce([
|
|
93
|
+
{
|
|
94
|
+
name: "main.json",
|
|
95
|
+
isFile: () => true,
|
|
96
|
+
parentPath: "configurations/grant-1",
|
|
97
|
+
},
|
|
98
|
+
]);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("should store config and inform config broker via REST API if SNS not setup", async () => {
|
|
102
|
+
//reset topic to default, should indicate not setup
|
|
103
|
+
config.set(
|
|
104
|
+
"aws.sns.configVersionTopicArn",
|
|
105
|
+
config.default("aws.sns.configVersionTopicArn"),
|
|
106
|
+
);
|
|
107
|
+
await storeConfigVersionAndInformBroker(mockLogger);
|
|
108
|
+
|
|
109
|
+
expect(mockLogger.info).toHaveBeenCalledWith(
|
|
110
|
+
"uploading 'grant-1/1.2.3/main.json' to S3",
|
|
111
|
+
);
|
|
112
|
+
expect(mockLogger.info).toHaveBeenCalledWith(
|
|
113
|
+
"successfully uploaded '1' files across '1' configs",
|
|
114
|
+
);
|
|
115
|
+
expect(mockLogger.info).toHaveBeenCalledWith(
|
|
116
|
+
"successfully notified the config broker about 'grant-1' at version '1.2.3'",
|
|
117
|
+
);
|
|
118
|
+
expect(listFiles).toHaveBeenCalledTimes(1);
|
|
119
|
+
expect(readFileSync).toHaveBeenCalledTimes(1);
|
|
120
|
+
expect(uploadBlob).toHaveBeenCalledTimes(1);
|
|
121
|
+
expect(fetch).toHaveBeenCalledWith(
|
|
122
|
+
"https://broker.unit.test/api/release-config",
|
|
142
123
|
{
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
124
|
+
method: "POST",
|
|
125
|
+
headers: {
|
|
126
|
+
"Content-Type": "application/json",
|
|
127
|
+
authorization: "Bearer token",
|
|
128
|
+
},
|
|
129
|
+
body: JSON.stringify({
|
|
130
|
+
grant: "grant-1",
|
|
131
|
+
version: "1.2.3",
|
|
132
|
+
files: ["grant-1/1.2.3/main.json"],
|
|
133
|
+
status: "active",
|
|
134
|
+
}),
|
|
146
135
|
},
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
.
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
136
|
+
);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("should store config and inform config broker via SNS if setup", async () => {
|
|
140
|
+
await storeConfigVersionAndInformBroker(mockLogger);
|
|
141
|
+
|
|
142
|
+
expect(mockLogger.info).toHaveBeenCalledWith(
|
|
143
|
+
"uploading 'grant-1/1.2.3/main.json' to S3",
|
|
144
|
+
);
|
|
145
|
+
expect(mockLogger.info).toHaveBeenCalledWith(
|
|
146
|
+
"successfully uploaded '1' files across '1' configs",
|
|
147
|
+
);
|
|
148
|
+
expect(mockLogger.info).toHaveBeenCalledWith(
|
|
149
|
+
"successfully notified the config broker about 'grant-1' at version '1.2.3' via SNS",
|
|
150
|
+
);
|
|
151
|
+
expect(listFiles).toHaveBeenCalledTimes(1);
|
|
152
|
+
expect(readFileSync).toHaveBeenCalledTimes(1);
|
|
153
|
+
expect(uploadBlob).toHaveBeenCalledTimes(1);
|
|
154
|
+
expect(isClientSetup).toHaveBeenCalledTimes(1);
|
|
155
|
+
expect(setupClient).toHaveBeenCalledTimes(1);
|
|
156
|
+
expect(publishMessage).toHaveBeenCalledWith({
|
|
157
|
+
grant: "grant-1",
|
|
158
|
+
version: "1.2.3",
|
|
159
|
+
files: ["grant-1/1.2.3/main.json"],
|
|
160
|
+
status: "active",
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("should not store or inform when already published by config broker", async () => {
|
|
165
|
+
listFiles.mockReturnValueOnce([{ Contents: ["fake-content-1"] }]);
|
|
166
|
+
|
|
167
|
+
await storeConfigVersionAndInformBroker(mockLogger);
|
|
168
|
+
|
|
169
|
+
expect(listFiles).toHaveBeenCalledTimes(1);
|
|
170
|
+
expect(readFileSync).not.toHaveBeenCalled();
|
|
171
|
+
expect(uploadBlob).not.toHaveBeenCalled();
|
|
172
|
+
expect(fetch).not.toHaveBeenCalled();
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it("should stop and print warning if no mechanism setup to contact config-broker", async () => {
|
|
176
|
+
config.set(
|
|
177
|
+
"aws.sns.configVersionTopicArn",
|
|
178
|
+
config.default("aws.sns.configVersionTopicArn"),
|
|
179
|
+
);
|
|
180
|
+
config.set("configBroker.apiEndpoint", "");
|
|
181
|
+
|
|
182
|
+
await storeConfigVersionAndInformBroker(mockLogger);
|
|
183
|
+
|
|
184
|
+
expect(mockLogger.warn).toHaveBeenCalledWith(
|
|
185
|
+
"config SNS topic not set, and config broker endpoint not set, so skipping release config call",
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
expect(listFiles).toHaveBeenCalledTimes(1);
|
|
189
|
+
expect(fetch).not.toHaveBeenCalled();
|
|
190
|
+
expect(isClientSetup).not.toHaveBeenCalled();
|
|
191
|
+
expect(setupClient).not.toHaveBeenCalled();
|
|
192
|
+
expect(publishMessage).not.toHaveBeenCalled();
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it("should call config broker for each config (subdirectory) found in configurations folder", async () => {
|
|
196
|
+
//reset topic to default, should indicate not setup
|
|
197
|
+
config.set(
|
|
198
|
+
"aws.sns.configVersionTopicArn",
|
|
199
|
+
config.default("aws.sns.configVersionTopicArn"),
|
|
200
|
+
);
|
|
201
|
+
readdirSync.mockRestore();
|
|
202
|
+
readdirSync
|
|
203
|
+
.mockReturnValueOnce([
|
|
204
|
+
{ name: "grant-1", isDirectory: () => true },
|
|
205
|
+
{ name: "grant-2", isDirectory: () => true },
|
|
206
|
+
])
|
|
207
|
+
.mockReturnValueOnce([
|
|
208
|
+
{
|
|
209
|
+
name: "main.json",
|
|
210
|
+
isFile: () => true,
|
|
211
|
+
parentPath: "configurations/grant-1",
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
name: "submain.json",
|
|
215
|
+
isFile: () => true,
|
|
216
|
+
parentPath: "configurations/grant-1",
|
|
217
|
+
},
|
|
218
|
+
])
|
|
219
|
+
.mockReturnValueOnce([
|
|
220
|
+
{
|
|
221
|
+
name: "main.json",
|
|
222
|
+
isFile: () => true,
|
|
223
|
+
parentPath: "configurations/grant-2",
|
|
224
|
+
},
|
|
225
|
+
]);
|
|
226
|
+
|
|
227
|
+
await storeConfigVersionAndInformBroker(mockLogger);
|
|
228
|
+
|
|
229
|
+
expect(mockLogger.info).toHaveBeenCalledWith(
|
|
230
|
+
"uploading 'grant-1/1.2.3/main.json' to S3",
|
|
231
|
+
);
|
|
232
|
+
expect(mockLogger.info).toHaveBeenCalledWith(
|
|
233
|
+
"uploading 'grant-1/1.2.3/submain.json' to S3",
|
|
234
|
+
);
|
|
235
|
+
expect(mockLogger.info).toHaveBeenCalledWith(
|
|
236
|
+
"uploading 'grant-2/1.2.3/main.json' to S3",
|
|
237
|
+
);
|
|
238
|
+
expect(mockLogger.info).toHaveBeenCalledWith(
|
|
239
|
+
"successfully uploaded '3' files across '2' configs",
|
|
240
|
+
);
|
|
241
|
+
expect(mockLogger.info).toHaveBeenCalledWith(
|
|
242
|
+
"successfully notified the config broker about 'grant-1' at version '1.2.3'",
|
|
243
|
+
);
|
|
244
|
+
expect(mockLogger.info).toHaveBeenCalledWith(
|
|
245
|
+
"successfully notified the config broker about 'grant-2' at version '1.2.3'",
|
|
246
|
+
);
|
|
247
|
+
expect(listFiles).toHaveBeenCalledTimes(2);
|
|
248
|
+
expect(readFileSync).toHaveBeenCalledTimes(3);
|
|
249
|
+
expect(uploadBlob).toHaveBeenCalledTimes(3);
|
|
250
|
+
expect(fetch).toHaveBeenCalledTimes(2);
|
|
251
|
+
});
|
|
185
252
|
});
|
|
186
253
|
});
|