diff --git a/x-pack/plugins/snapshot_restore/server/routes/api/repositories.test.ts b/x-pack/plugins/snapshot_restore/server/routes/api/repositories.test.ts index e5779b118eb00..8b23bb8e3d6bb 100644 --- a/x-pack/plugins/snapshot_restore/server/routes/api/repositories.test.ts +++ b/x-pack/plugins/snapshot_restore/server/routes/api/repositories.test.ts @@ -158,12 +158,7 @@ describe('[Snapshot and Restore API Routes] Repositories', () => { [name]: { type: '', settings: {} }, }; const mockEsSnapshotResponse = { - responses: [ - { - repository: name, - snapshots: [{}, {}], - }, - ], + snapshots: [{}, {}], }; router.callAsCurrentUserResponses = [ diff --git a/x-pack/plugins/snapshot_restore/server/routes/api/repositories.ts b/x-pack/plugins/snapshot_restore/server/routes/api/repositories.ts index 7d30e1f8f77fd..bb6ce65aeb9af 100644 --- a/x-pack/plugins/snapshot_restore/server/routes/api/repositories.ts +++ b/x-pack/plugins/snapshot_restore/server/routes/api/repositories.ts @@ -122,22 +122,11 @@ export function registerRepositoriesRoutes({ return res.internalError({ body: e }); } - const { - responses: snapshotResponses, - }: { - responses: Array<{ - repository: string; - snapshots: any[]; - }>; - } = await callAsCurrentUser('snapshot.get', { + const { snapshots } = await callAsCurrentUser('snapshot.get', { repository: name, snapshot: '_all', }).catch(e => ({ - responses: [ - { - snapshots: null, - }, - ], + snapshots: null, })); if (repositoryByName[name]) { @@ -152,10 +141,7 @@ export function registerRepositoriesRoutes({ }, isManagedRepository: managedRepository === name, snapshots: { - count: - snapshotResponses && snapshotResponses[0] && snapshotResponses[0].snapshots - ? snapshotResponses[0].snapshots.length - : null, + count: snapshots ? snapshots.length : null, }, }, }); diff --git a/x-pack/plugins/snapshot_restore/server/routes/api/snapshots.test.ts b/x-pack/plugins/snapshot_restore/server/routes/api/snapshots.test.ts index 61b3f5a4d1ca1..a12d213b0584c 100644 --- a/x-pack/plugins/snapshot_restore/server/routes/api/snapshots.test.ts +++ b/x-pack/plugins/snapshot_restore/server/routes/api/snapshots.test.ts @@ -59,21 +59,11 @@ describe('[Snapshot and Restore API Routes] Snapshots', () => { }; const mockGetSnapshotsFooResponse = Promise.resolve({ - responses: [ - { - repository: 'fooRepository', - snapshots: [{ snapshot: 'snapshot1' }], - }, - ], + snapshots: [{ snapshot: 'snapshot1' }], }); const mockGetSnapshotsBarResponse = Promise.resolve({ - responses: [ - { - repository: 'barRepository', - snapshots: [{ snapshot: 'snapshot2' }], - }, - ], + snapshots: [{ snapshot: 'snapshot2' }], }); router.callAsCurrentUserResponses = [ @@ -168,12 +158,7 @@ describe('[Snapshot and Restore API Routes] Snapshots', () => { test('returns snapshot object with repository name if returned from ES', async () => { const mockSnapshotGetEsResponse = { - responses: [ - { - repository, - snapshots: [{ snapshot }], - }, - ], + snapshots: [{ snapshot }], }; router.callAsCurrentUserResponses = [ diff --git a/x-pack/plugins/snapshot_restore/server/routes/api/snapshots.ts b/x-pack/plugins/snapshot_restore/server/routes/api/snapshots.ts index 35eb0463cc7e7..ed4053f6878c6 100644 --- a/x-pack/plugins/snapshot_restore/server/routes/api/snapshots.ts +++ b/x-pack/plugins/snapshot_restore/server/routes/api/snapshots.ts @@ -70,12 +70,9 @@ export function registerSnapshotsRoutes({ try { // If any of these repositories 504 they will cost the request significant time. const { - responses: fetchedResponses, + snapshots: fetchedSnapshots, }: { - responses: Array<{ - repository: 'string'; - snapshots: SnapshotDetailsEs[]; - }>; + snapshots: SnapshotDetailsEs[]; } = await callAsCurrentUser('snapshot.get', { repository, snapshot: '_all', @@ -83,10 +80,9 @@ export function registerSnapshotsRoutes({ }); // Decorate each snapshot with the repository with which it's associated. - fetchedResponses.forEach(({ snapshots: fetchedSnapshots }) => { - fetchedSnapshots.forEach(snapshot => { - snapshots.push(deserializeSnapshotDetails(repository, snapshot, managedRepository)); - }); + + fetchedSnapshots.forEach((snapshot: SnapshotDetailsEs) => { + snapshots.push(deserializeSnapshotDetails(repository, snapshot, managedRepository)); }); repositories.push(repository); @@ -128,22 +124,16 @@ export function registerSnapshotsRoutes({ try { const { - responses: snapshotsResponse, + snapshots: fetchedSnapshots, }: { - responses: Array<{ - repository: string; - snapshots: SnapshotDetailsEs[]; - error?: any; - }>; + snapshots: SnapshotDetailsEs[]; } = await callAsCurrentUser('snapshot.get', { repository, snapshot: '_all', ignore_unavailable: true, }); - const snapshotsList = - snapshotsResponse && snapshotsResponse[0] && snapshotsResponse[0].snapshots; - const selectedSnapshot = snapshotsList.find( + const selectedSnapshot = fetchedSnapshots.find( ({ snapshot: snapshotName }) => snapshot === snapshotName ) as SnapshotDetailsEs; @@ -152,7 +142,7 @@ export function registerSnapshotsRoutes({ return res.notFound({ body: 'Snapshot not found' }); } - const successfulSnapshots = snapshotsList + const successfulSnapshots = fetchedSnapshots .filter(({ state }) => state === 'SUCCESS') .sort((a, b) => { return +new Date(b.end_time) - +new Date(a.end_time);