Skip to content

Commit 98d01d9

Browse files
committed
Merge branch 'main' into fb/service-credentials
2 parents c165201 + f3c1c7b commit 98d01d9

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
99

1010
## v0.11.2 - tbd
1111

12+
### ADDED
13+
14+
- svm: add client headers `Client-Name` and `Client-Version` for all calls to service-manager.
15+
1216
## v0.11.1 - 2025-12-10
1317

1418
### ADDED

src/submodules/serviceManager.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
"use strict";
77

8+
const packageInfo = require("../../package.json");
89
const {
910
parseIntWithFallback,
1011
compareFor,
@@ -107,7 +108,17 @@ const _serviceManagerRequest = async (context, reqOptions = {}) => {
107108
} = await context.getHdiInfo();
108109
const url = credentials.sm_url;
109110
const auth = { token: await context.getCachedUaaTokenFromCredentials(credentials) };
110-
const response = await request({ url, auth, ...reqOptions });
111+
const response = await request({
112+
url,
113+
auth,
114+
...reqOptions,
115+
headers: {
116+
// NOTE: service-manager uses this client information for better consumption reporting and rate-limiting
117+
"Client-Name": packageInfo.name,
118+
"Client-Version": packageInfo.version,
119+
...reqOptions?.headers,
120+
},
121+
});
111122

112123
if (reqOptions.method) {
113124
return response;

test/submodules/serviceManager.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"use strict";
22

3+
const packageInfo = require("../../package.json");
34
const mockRequest = require("../../src/shared/request");
45
jest.mock("../../src/shared/request", () => {
56
const { RETRY_MODE } = jest.requireActual("../../src/shared/request");
@@ -120,6 +121,29 @@ describe("svm tests", () => {
120121
mockRequest.request.mockClear();
121122
});
122123

124+
describe("svm basics", () => {
125+
test("client headers", async () => {
126+
mockRequest.request.mockReturnValueOnce(mockOfferingResponse);
127+
mockRequest.request.mockReturnValueOnce(mockPlanResponse);
128+
mockRequest.request.mockReturnValueOnce(mockInstanceResponse(6));
129+
mockRequest.request.mockReturnValueOnce({
130+
json: () => ({
131+
items: [mockBindingFactory(2), mockBindingFactory(5)],
132+
}),
133+
});
134+
135+
await expect(svm.serviceManagerList(mockContext, [], [false, false])).resolves.toBeDefined();
136+
137+
expect(mockRequest.request.mock.calls).toMatchObject(
138+
mockRequest.request.mock.calls.map(() => [
139+
{
140+
headers: { "Client-Name": packageInfo.name, "Client-Version": packageInfo.version },
141+
},
142+
])
143+
);
144+
});
145+
});
146+
123147
describe("svm repair bindings", () => {
124148
test("all-services", async () => {
125149
mockRequest.request.mockReturnValueOnce(mockOfferingResponse);

0 commit comments

Comments
 (0)