adds a x-goog-api-client header to existing API requests in this plugin to clearly identify API requests from this GKE plugin
Signed-off-by: armandocomellas1 <cgarmando@google.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-kubernetes-backend': minor
|
||||
'@backstage/plugin-kubernetes-backend': patch
|
||||
---
|
||||
|
||||
At Line 91, in the second parameter enter a value for the property `libName` and `libVersion` to post headers to the key `x-goog-api-client`
|
||||
adds a x-goog-api-client header to existing API requests in this plugin to clearly identify API requests from this GKE plugin. headers are formatted as follows where `libVersion` represents the current dotted version number of the Backstage GKE plugin and `libName` represent the current Google API used at backstage.
|
||||
|
||||
@@ -18,9 +18,18 @@ import { ANNOTATION_KUBERNETES_AUTH_PROVIDER } from '@backstage/plugin-kubernete
|
||||
import '@backstage/backend-common';
|
||||
import { ConfigReader, Config } from '@backstage/config';
|
||||
import { GkeClusterLocator } from './GkeClusterLocator';
|
||||
import { Duration } from 'luxon';
|
||||
import * as container from '@google-cloud/container';
|
||||
|
||||
const mockedListClusters = jest.fn();
|
||||
jest.mock('@google-cloud/container', () => {
|
||||
return {
|
||||
v1: {
|
||||
ClusterManagerClient: jest.fn().mockImplementation(() => {
|
||||
mockedListClusters();
|
||||
}),
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
describe('GkeClusterLocator', () => {
|
||||
beforeEach(() => {
|
||||
@@ -486,20 +495,18 @@ describe('GkeClusterLocator', () => {
|
||||
},
|
||||
]);
|
||||
});
|
||||
it('Check if new container.v1.ClusterManagerClient has key and values as parameter', async () => {
|
||||
it('constructs ClusterManagerClient with identifying metadata', async () => {
|
||||
const configs: Config = new ConfigReader({
|
||||
type: 'gke',
|
||||
projectId: 'some-project',
|
||||
});
|
||||
|
||||
const refreshIntervals: Duration | undefined = undefined;
|
||||
const getHeaders: GkeClusterLocator = GkeClusterLocator.fromConfig(
|
||||
configs,
|
||||
refreshIntervals,
|
||||
);
|
||||
GkeClusterLocator.fromConfig(configs);
|
||||
|
||||
expect(getHeaders).toHaveProperty('client._opts.libName');
|
||||
expect(getHeaders).toHaveProperty('client._opts.libVersion');
|
||||
expect(container.v1.ClusterManagerClient).toHaveBeenCalledWith({
|
||||
libName: 'backstage/kubernetes-backend.GkeClusterLocator',
|
||||
libVersion: expect.any(String),
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -81,7 +81,7 @@ export class GkeClusterLocator implements KubernetesClustersSupplier {
|
||||
return gkeClusterLocator;
|
||||
}
|
||||
|
||||
// At Line 91, in the second parameter enter a value for the property libName and libVersion to post headers to the key 'x-goog-api-client'
|
||||
// Added an `x-goog-api-client` header to API requests made by the GKE cluster locator to clearly identify API requests from this plugin.
|
||||
static fromConfig(
|
||||
config: Config,
|
||||
refreshInterval: Duration | undefined = undefined,
|
||||
@@ -89,7 +89,7 @@ export class GkeClusterLocator implements KubernetesClustersSupplier {
|
||||
return GkeClusterLocator.fromConfigWithClient(
|
||||
config,
|
||||
new container.v1.ClusterManagerClient({
|
||||
libName: 'backstage/gke',
|
||||
libName: `backstage/kubernetes-backend.GkeClusterLocator`,
|
||||
libVersion: packageinfo.version,
|
||||
}),
|
||||
refreshInterval,
|
||||
|
||||
Reference in New Issue
Block a user