plugins: migrate usage of deprecated IdentityApi methods

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2022-01-04 23:08:05 +01:00
parent 2916a83b9c
commit 51fbedc445
38 changed files with 221 additions and 195 deletions
+2 -4
View File
@@ -40,9 +40,6 @@ describe('TechDocsStorageClient', () => {
} as Partial<Config>;
const discoveryApi = UrlPatternDiscovery.compile(mockBaseUrl);
const identityApi: jest.Mocked<IdentityApi> = {
getIdToken: jest.fn(),
getProfile: jest.fn(),
getUserId: jest.fn(),
signOut: jest.fn(),
getProfileInfo: jest.fn(),
getBackstageIdentity: jest.fn(),
@@ -51,6 +48,7 @@ describe('TechDocsStorageClient', () => {
beforeEach(() => {
jest.resetAllMocks();
identityApi.getCredentials.mockResolvedValue({ token: undefined });
});
it('should return correct base url based on defined storage', async () => {
@@ -122,7 +120,7 @@ describe('TechDocsStorageClient', () => {
},
);
identityApi.getIdToken.mockResolvedValue('token');
identityApi.getCredentials.mockResolvedValue({ token: 'token' });
await storageApi.syncEntityDocs(mockEntity);
+4 -4
View File
@@ -65,7 +65,7 @@ export class TechDocsClient implements TechDocsApi {
const apiOrigin = await this.getApiOrigin();
const requestUrl = `${apiOrigin}/metadata/techdocs/${namespace}/${kind}/${name}`;
const token = await this.identityApi.getIdToken();
const { token } = await this.identityApi.getCredentials();
const request = await fetch(`${requestUrl}`, {
headers: token ? { Authorization: `Bearer ${token}` } : {},
@@ -93,7 +93,7 @@ export class TechDocsClient implements TechDocsApi {
const apiOrigin = await this.getApiOrigin();
const requestUrl = `${apiOrigin}/metadata/entity/${namespace}/${kind}/${name}`;
const token = await this.identityApi.getIdToken();
const { token } = await this.identityApi.getCredentials();
const request = await fetch(`${requestUrl}`, {
headers: token ? { Authorization: `Bearer ${token}` } : {},
@@ -160,7 +160,7 @@ export class TechDocsStorageClient implements TechDocsStorageApi {
const storageUrl = await this.getStorageUrl();
const url = `${storageUrl}/${namespace}/${kind}/${name}/${path}`;
const token = await this.identityApi.getIdToken();
const { token } = await this.identityApi.getCredentials();
const request = await fetch(
`${url.endsWith('/') ? url : `${url}/`}index.html`,
@@ -207,7 +207,7 @@ export class TechDocsStorageClient implements TechDocsStorageApi {
const apiOrigin = await this.getApiOrigin();
const url = `${apiOrigin}/sync/${namespace}/${kind}/${name}`;
const token = await this.identityApi.getIdToken();
const { token } = await this.identityApi.getCredentials();
return new Promise((resolve, reject) => {
// Polyfill is used to add support for custom headers and auth