Skip to content

Commit

Permalink
Get rid of artificial destionation_uri.
Browse files Browse the repository at this point in the history
  • Loading branch information
cleve-fauna committed Jan 27, 2025
1 parent 9cb62fc commit 355925b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/commands/export/list.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
22 changes: 2 additions & 20 deletions src/lib/account-api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -446,7 +437,7 @@ async function createExport({
});

const data = await responseHandler(response);
return { ...data.response, destination: data.response.destination.uri };
return data.response;
}

/**
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

/**
Expand Down
22 changes: 19 additions & 3 deletions test/commands/export/create.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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" } },
},
];
Expand All @@ -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
`);
Expand Down
4 changes: 2 additions & 2 deletions test/commands/export/get.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});

Expand Down Expand Up @@ -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"
Expand Down
17 changes: 4 additions & 13 deletions test/lib/account-api/account-api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -194,10 +192,7 @@ describe("accountAPI", () => {
}),
}),
);
expect(data).to.deep.equal({
...testExport,
destination: expectedDestination,
});
expect(data).to.deep.equal(testExport);
});
});
});
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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);
});
});
});

0 comments on commit 355925b

Please sign in to comment.