Skip to content

Commit fa9d536

Browse files
authored
feat: added api for gradual rollout (#575)
1 parent 635eba2 commit fa9d536

3 files changed

+44
-0
lines changed

src/DomainFeaturesService.test.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import nock from "nock";
2+
import LensPlatformClient from "./LensPlatformClient";
3+
import { minimumOptions as options, apiEndpointAddress } from "./LensPlatformClient.test";
4+
5+
describe(".domain/features.*", () => {
6+
const domain = "mirantis.com";
7+
8+
nock(apiEndpointAddress).get(`/domain/features?domain=${domain}`).reply(200, {
9+
domainMatchingEnabled: true,
10+
});
11+
12+
const lensPlatformClient = new LensPlatformClient(options);
13+
14+
it("can call get", async () => {
15+
const features = await lensPlatformClient.domainFeatures.get({ domain });
16+
17+
expect(features.domainMatchingEnabled).toBeTruthy();
18+
});
19+
});

src/DomainFeaturesService.ts

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Base } from "./Base";
2+
import { UnauthorizedException, throwExpected } from "./exceptions";
3+
4+
export interface DomainFeatures {
5+
domainMatchingEnabled: boolean;
6+
}
7+
8+
class DomainFeaturesService extends Base {
9+
async get({ domain }: { domain: string }): Promise<DomainFeatures> {
10+
const { apiEndpointAddress, fetch } = this.lensPlatformClient;
11+
const url = `${apiEndpointAddress}/domain/features?domain=${encodeURIComponent(domain)}`;
12+
13+
const json = await throwExpected(async () => fetch.get(url), {
14+
401: (error) => new UnauthorizedException(error?.body.message),
15+
});
16+
17+
return json as unknown as DomainFeatures;
18+
}
19+
}
20+
21+
export { DomainFeaturesService };

src/LensPlatformClient.ts

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import https from "https";
1717
import { LensDesktopKubeService } from "./LensDesktopKubeService";
1818
import { DemoClusterService } from "./DemoClusterService";
1919
import { SSOService } from "./SSOService";
20+
import { DomainFeaturesService } from "./DomainFeaturesService";
2021

2122
// Axios defaults to xhr adapter if XMLHttpRequest is available.
2223
// LensPlatformClient supports using the http adapter if httpAdapter
@@ -188,6 +189,8 @@ class LensPlatformClient {
188189

189190
sso: SSOService;
190191

192+
domainFeatures: DomainFeaturesService;
193+
191194
constructor(options: LensPlatformClientOptions) {
192195
if (!options) {
193196
throw new Error(`Options can not be ${options}`);
@@ -228,6 +231,7 @@ class LensPlatformClient {
228231
this.sso = new SSOService(this);
229232
this.openIDConnect = new OpenIdConnect(this);
230233
this.notification = new NotificationService(this);
234+
this.domainFeatures = new DomainFeaturesService(this);
231235
}
232236

233237
async getToken(url?: string) {

0 commit comments

Comments
 (0)