Skip to content

Commit

Permalink
Remove deprecated accept_enterprise query param from licence API (ela…
Browse files Browse the repository at this point in the history
  • Loading branch information
rudolf authored and TinLe committed Dec 22, 2021
1 parent b4f2b0d commit d3e1741
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 18 deletions.
5 changes: 1 addition & 4 deletions x-pack/plugins/licensing/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,7 @@ export class LicensingPlugin implements Plugin<LicensingPluginSetup, LicensingPl
private fetchLicense = async (clusterClient: MaybePromise<IClusterClient>): Promise<ILicense> => {
const client = isPromise(clusterClient) ? await clusterClient : clusterClient;
try {
const { body: response } = await client.asInternalUser.xpack.info({
// @ts-expect-error `accept_enterprise` is not present in the client definition
accept_enterprise: true,
});
const { body: response } = await client.asInternalUser.xpack.info();
const normalizedLicense =
response.license && response.license.type !== 'missing'
? normalizeServerLicense(response.license)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,6 @@ export class TelemetryReceiver {
path: '/_license',
querystring: {
local: true,
// For versions >= 7.6 and < 8.0, this flag is needed otherwise 'platinum' is returned for 'enterprise' license.
accept_enterprise: 'true',
},
})
).body as Promise<{ license: ESLicense }>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('getLicenseFromLocalOrMaster', () => {
const license = await getLicenseFromLocalOrMaster(esClient);

expect(license).toBeUndefined();
expect(esClient.license.get).toHaveBeenCalledWith({ local: true, accept_enterprise: true });
expect(esClient.license.get).toHaveBeenCalledWith({ local: true });
expect(esClient.license.get).toHaveBeenCalledTimes(1);
});

Expand All @@ -30,7 +30,7 @@ describe('getLicenseFromLocalOrMaster', () => {
const license = await getLicenseFromLocalOrMaster(esClient);

expect(license).toStrictEqual({ type: 'basic' });
expect(esClient.license.get).toHaveBeenCalledWith({ local: true, accept_enterprise: true });
expect(esClient.license.get).toHaveBeenCalledWith({ local: true });
expect(esClient.license.get).toHaveBeenCalledTimes(1);
});

Expand All @@ -42,8 +42,8 @@ describe('getLicenseFromLocalOrMaster', () => {

await expect(getLicenseFromLocalOrMaster(esClient)).rejects.toStrictEqual(error);

expect(esClient.license.get).toHaveBeenCalledWith({ local: true, accept_enterprise: true });
expect(esClient.license.get).toHaveBeenCalledWith({ local: false, accept_enterprise: true });
expect(esClient.license.get).toHaveBeenCalledWith({ local: true });
expect(esClient.license.get).toHaveBeenCalledWith({ local: false });
expect(esClient.license.get).toHaveBeenCalledTimes(2);
});

Expand All @@ -58,8 +58,8 @@ describe('getLicenseFromLocalOrMaster', () => {
const license = await getLicenseFromLocalOrMaster(esClient);

expect(license).toStrictEqual({ type: 'basic' });
expect(esClient.license.get).toHaveBeenCalledWith({ local: true, accept_enterprise: true });
expect(esClient.license.get).toHaveBeenCalledWith({ local: false, accept_enterprise: true });
expect(esClient.license.get).toHaveBeenCalledWith({ local: true });
expect(esClient.license.get).toHaveBeenCalledWith({ local: false });
expect(esClient.license.get).toHaveBeenCalledTimes(2);
});

Expand All @@ -72,14 +72,14 @@ describe('getLicenseFromLocalOrMaster', () => {
const license = await getLicenseFromLocalOrMaster(esClient);

expect(license).toBeUndefined();
expect(esClient.license.get).toHaveBeenCalledWith({ local: true, accept_enterprise: true });
expect(esClient.license.get).toHaveBeenCalledWith({ local: false, accept_enterprise: true });
expect(esClient.license.get).toHaveBeenCalledWith({ local: true });
expect(esClient.license.get).toHaveBeenCalledWith({ local: false });
expect(esClient.license.get).toHaveBeenCalledTimes(2);

// Now the cached license is cleared, next request only goes for local and gives up when failed
esClient.license.get.mockClear();
await expect(getLicenseFromLocalOrMaster(esClient)).resolves.toBeUndefined();
expect(esClient.license.get).toHaveBeenCalledWith({ local: true, accept_enterprise: true });
expect(esClient.license.get).toHaveBeenCalledWith({ local: true });
expect(esClient.license.get).toHaveBeenCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ let cachedLicense: ESLicense | undefined;
async function fetchLicense(esClient: ElasticsearchClient, local: boolean) {
const { body } = await esClient.license.get({
local,
// For versions >= 7.6 and < 8.0, this flag is needed otherwise 'platinum' is returned for 'enterprise' license.
accept_enterprise: true,
});
return body;
}
/**
* Get the cluster's license from the connected node.
*
* This is the equivalent of GET /_license?local=true&accept_enterprise=true.
* This is the equivalent of GET /_license?local=true.
*
* Like any X-Pack related API, X-Pack must installed for this to work.
*
Expand Down

0 comments on commit d3e1741

Please sign in to comment.