From 355925b85e2f8dfd7793c108d3bd2e2cb16afd11 Mon Sep 17 00:00:00 2001 From: Cleve Stuart Date: Mon, 27 Jan 2025 09:56:34 -0500 Subject: [PATCH] Get rid of artificial destionation_uri. --- src/commands/export/list.mjs | 2 +- src/lib/account-api.mjs | 22 ++-------------------- test/commands/export/create.mjs | 22 +++++++++++++++++++--- test/commands/export/get.mjs | 4 ++-- test/lib/account-api/account-api.mjs | 17 ++++------------- 5 files changed, 28 insertions(+), 39 deletions(-) diff --git a/src/commands/export/list.mjs b/src/commands/export/list.mjs index 276ffda5..be1cd484 100644 --- a/src/commands/export/list.mjs +++ b/src/commands/export/list.mjs @@ -27,7 +27,7 @@ async function listExports(argv) { r.id, r.database, (r.collections ?? []).join(COLLECTION_SEPARATOR), - r.destination_uri, + r.destination.uri, r.state, ]; logger.stdout( diff --git a/src/lib/account-api.mjs b/src/lib/account-api.mjs index 20ccc835..9f282650 100644 --- a/src/lib/account-api.mjs +++ b/src/lib/account-api.mjs @@ -402,15 +402,6 @@ async function createKey({ path, role, ttl, name }) { return await responseHandler(response); } -const getExportUri = (data) => { - const { destination, state } = data; - if (!destination || !state) { - return ""; - } - const path = destination.s3.path.replace(/^\/+/, ""); - return `s3://${destination.s3.bucket}/${path}`; -}; - /** * Creates an export for a given database. * @@ -446,7 +437,7 @@ async function createExport({ }); const data = await responseHandler(response); - return { ...data.response, destination: data.response.destination.uri }; + return data.response; } /** @@ -477,12 +468,6 @@ async function listExports({ maxResults = 100, nextToken, state } = {}) { }); const { response: data } = await responseHandler(response); - if (data.results && Array.isArray(data.results)) { - data.results.forEach((r) => { - r.destination_uri = getExportUri(r); // eslint-disable-line camelcase - }); - } - return data; } @@ -501,10 +486,7 @@ async function getExport({ exportId }) { }); const response = await fetchWithAccountKey(url, { method: "GET" }); const data = await responseHandler(response); - return { - ...data.response, - destination_uri: getExportUri(data.response), // eslint-disable-line camelcase - }; + return data.response; } /** diff --git a/test/commands/export/create.mjs b/test/commands/export/create.mjs index c7d1d064..1fe52085 100644 --- a/test/commands/export/create.mjs +++ b/test/commands/export/create.mjs @@ -37,13 +37,25 @@ describe("export create s3", () => { { description: "using --destination", args: "--destination 's3://test-bucket/test/key'", - expectedDestination: "s3://test-bucket/test/key", + expectedDestination: { + s3: { + bucket: "test-bucket", + path: "/test/key", + }, + uri: "s3://test-bucket/test/key", + }, expectedDestArgs: "s3://test-bucket/test/key", }, { description: "using --bucket and --path", args: "--bucket 'test-bucket' --path '/test/key'", - expectedDestination: "s3://test-bucket/test/key", + expectedDestination: { + s3: { + bucket: "test-bucket", + path: "/test/key", + }, + uri: "s3://test-bucket/test/key", + }, expectedDestArgs: { s3: { bucket: "test-bucket", path: "/test/key" } }, }, ]; @@ -69,7 +81,11 @@ describe("export create s3", () => { state: Pending database: us-std/example format: simple -destination: s3://test-bucket/test/key +destination: + s3: + bucket: test-bucket + path: /test/key + uri: s3://test-bucket/test/key created_at: 2025-01-02T22:59:51 updated_at: 2025-01-02T22:59:51 `); diff --git a/test/commands/export/get.mjs b/test/commands/export/get.mjs index 90f52689..37341ac0 100644 --- a/test/commands/export/get.mjs +++ b/test/commands/export/get.mjs @@ -13,10 +13,10 @@ const getExportStub = (opts) => ({ bucket: "test-bucket", path: "some/key/prefix", }, + uri: "s3://test-bucket/some/key/prefix", }, created_at: "2025-01-09T19:07:25.642703Z", updated_at: "2025-01-09T19:07:25.642703Z", - destination_uri: "", ...opts, }); @@ -51,9 +51,9 @@ destination: s3: bucket: test-bucket path: some/key/prefix + uri: s3://test-bucket/some/key/prefix created_at: 2025-01-09T19:07:25.642703Z updated_at: 2025-01-09T19:07:25.642703Z -destination_uri: "" failure: code: validation_error message: "failed to get bucket region: bucket not found" diff --git a/test/lib/account-api/account-api.mjs b/test/lib/account-api/account-api.mjs index 30e3e96b..7957cf76 100644 --- a/test/lib/account-api/account-api.mjs +++ b/test/lib/account-api/account-api.mjs @@ -134,7 +134,6 @@ describe("accountAPI", () => { { description: "using destination URI", destination: "s3://test-bucket/test/key", - expectedDestination: "s3://test-bucket/test/key", }, { description: "using bucket and path", @@ -144,11 +143,10 @@ describe("accountAPI", () => { path: "test/key", }, }, - expectedDestination: "s3://test-bucket/test/key", }, ]; - scenarios.forEach(({ description, destination, expectedDestination }) => { + scenarios.forEach(({ description, destination }) => { describe(`createExport ${description}`, () => { const testExport = { id: "419633606504219216", @@ -194,10 +192,7 @@ describe("accountAPI", () => { }), }), ); - expect(data).to.deep.equal({ - ...testExport, - destination: expectedDestination, - }); + expect(data).to.deep.equal(testExport); }); }); }); @@ -254,11 +249,10 @@ describe("accountAPI", () => { expect(data).to.deep.equal({ results: [ - { ...testExport, destination_uri: "s3://test-bucket/some/key" }, + testExport, { ...testExport, state: "Complete", - destination_uri: "s3://test-bucket/some/key", }, ], next_token: "456", @@ -341,10 +335,7 @@ describe("accountAPI", () => { }, }), ); - expect(data).to.deep.equal({ - ...testExport, - destination_uri: "s3://test-bucket/some/key", - }); + expect(data).to.deep.equal(testExport); }); }); });