Skip to content

Commit

Permalink
fix: update AWS ACL before uploading screenshots (#959)
Browse files Browse the repository at this point in the history
  • Loading branch information
bapmrl authored May 3, 2023
1 parent 765b770 commit d652d5f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
6 changes: 4 additions & 2 deletions packages/init/test/__testutils__/mockAWSACLAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ export const mockAWSACLAPI = (
rest.post(
new URL("delete-folder", endpoint).toString(),
async (req, res, ctx) => {
const { sliceId } = await req.json<{ sliceId: string }>();
if (config.deleteFolderEndpoint?.expectedSliceIDs.includes(sliceId)) {
const { sliceName: sliceID } = await req.json<{
sliceName: string;
}>();
if (config.deleteFolderEndpoint?.expectedSliceIDs.includes(sliceID)) {
return res(ctx.status(200));
} else {
return res(ctx.status(401));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,9 @@ export class PrismicRepositoryManager extends BaseManager {
}

try {
// Update the AWS ACL before uploading screenshots as it might have expired
await this.screenshots.initS3ACL();

const allChanges: AllChangeTypes[] = await Promise.all(
args.changes.map(async (change) => {
if (change.type === "Slice") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,10 @@ export class ScreenshotsManager extends BaseManager {
}

async initS3ACL(): Promise<void> {
if (this._s3ACL) {
return;
}
// TODO: we need to find a way to create a new AWS ACL only when necessary (e.g., when it has expired).
// if (this._s3ACL) {
// return;
// }

const awsACLURL = new URL("create", API_ENDPOINTS.AwsAclProvider);
const awsACLRes = await this._fetch({ url: awsACLURL });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { expect, it } from "vitest";
import { createPrismicAuthLoginResponse } from "./__testutils__/createPrismicAuthLoginResponse";
import { createTestPlugin } from "./__testutils__/createTestPlugin";
import { createTestProject } from "./__testutils__/createTestProject";
import { mockAWSACLAPI } from "./__testutils__/mockAWSACLAPI";
import { mockCustomTypesAPI } from "./__testutils__/mockCustomTypesAPI";
import { mockPrismicAuthAPI } from "./__testutils__/mockPrismicAuthAPI";
import { mockPrismicUserAPI } from "./__testutils__/mockPrismicUserAPI";
Expand Down Expand Up @@ -64,6 +65,17 @@ it("pushes changes using the bulk delete API", async (ctx) => {
});

await manager.user.login(createPrismicAuthLoginResponse());

const authenticationToken = await manager.user.getAuthenticationToken();
const sliceMachineConfig = await manager.project.getSliceMachineConfig();

mockAWSACLAPI(ctx, {
createEndpoint: {
expectedPrismicRepository: sliceMachineConfig.repositoryName,
expectedAuthenticationToken: authenticationToken,
},
});

await manager.prismicRepository.pushChanges(
pushChangesPayload([sharedSliceModel.id], [customTypeModel.id]),
);
Expand Down
6 changes: 4 additions & 2 deletions packages/slice-machine/test/__testutils__/mockAWSACLAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,10 @@ export const mockAWSACLAPI = (
rest.post(
new URL("delete-folder", endpoint).toString(),
async (req, res, ctx) => {
const { sliceId } = await req.json<{ sliceId: string }>();
if (config.deleteFolderEndpoint?.expectedSliceIDs.includes(sliceId)) {
const { sliceName: sliceID } = await req.json<{
sliceName: string;
}>();
if (config.deleteFolderEndpoint?.expectedSliceIDs.includes(sliceID)) {
return res(ctx.status(200));
} else {
return res(ctx.status(401));
Expand Down

0 comments on commit d652d5f

Please sign in to comment.