Skip to content

Commit

Permalink
fix(sdk): parameter ScheduleExpression is not valid (#7116)
Browse files Browse the repository at this point in the history
  • Loading branch information
Chriscbr authored Sep 11, 2024
1 parent dd45d4f commit cdf646c
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 21 deletions.
7 changes: 5 additions & 2 deletions docs/api/04-standard-library/cloud/bucket.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,32 +105,35 @@ By default, buckets are configured with CORS for any origin. When a bucket is pr

```js playground example
bring cloud;
bring http;

let uploads = new cloud.Bucket(
// these are the default values
public: false,
cors: true,
corsOptions: {
allowedMethods: [http.HttpMethod.GET, http.HttpMethod.POST, http.HttpMethod.PUT, http.HttpMethod.DELETE, http.HttpMethod.HEAD]
allowedMethods: [http.HttpMethod.GET, http.HttpMethod.POST, http.HttpMethod.PUT, http.HttpMethod.DELETE, http.HttpMethod.HEAD],
allowedOrigins: ["*"],
allowedHeaders: ["*"],
exposeHeaders: [],
maxAge: 0s
},
)
);
```

The CORS configuration can be disabled by passing `cors: false` to the constructor. CORS rules can also be configured after the bucket is created by calling the `addCorsRule` method:

```js playground example
bring cloud;
bring http;

let bucket = new cloud.Bucket(
cors: false, // disable any default CORS rules
);

bucket.addCorsRule({
allowedOrigins: ["https://example.com"],
allowedMethods: [http.HttpMethod.GET],
});
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ exports[`convert single dayOfWeek from Unix to AWS 1`] = `
"Resources": {
"Schedule251B1F83": {
"Properties": {
"ScheduleExpression": "cron(* * ? * 0 *)",
"ScheduleExpression": "cron(* * ? * 1 *)",
"State": "ENABLED",
"Targets": [
{
Expand Down Expand Up @@ -167,7 +167,7 @@ exports[`convert the list of dayOfWeek from Unix to AWS 1`] = `
"Resources": {
"Schedule251B1F83": {
"Properties": {
"ScheduleExpression": "cron(* * ? * 0,2,4,6 *)",
"ScheduleExpression": "cron(* * ? * 1,3,5,7 *)",
"State": "ENABLED",
"Targets": [
{
Expand Down Expand Up @@ -322,7 +322,7 @@ exports[`convert the range of dayOfWeek from Unix to AWS 1`] = `
"Resources": {
"Schedule251B1F83": {
"Properties": {
"ScheduleExpression": "cron(* * ? * 0-6 *)",
"ScheduleExpression": "cron(* * ? * 1-7 *)",
"State": "ENABLED",
"Targets": [
{
Expand Down
12 changes: 6 additions & 6 deletions packages/@winglang/platform-awscdk/test/schedule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test("convert single dayOfWeek from Unix to AWS", () => {
// GIVEN
const app = new AwsCdkApp();
const schedule = new cloud.Schedule(app, "Schedule", {
cron: "* * * * 1",
cron: "* * * * 0",
});
schedule.onTick(INFLIGHT_CODE);
const output = app.synth();
Expand All @@ -57,7 +57,7 @@ test("convert single dayOfWeek from Unix to AWS", () => {
const template = Template.fromJSON(JSON.parse(output));
template.resourceCountIs("AWS::Events::Rule", 1);
template.hasResourceProperties("AWS::Events::Rule", {
ScheduleExpression: "cron(* * ? * 0 *)",
ScheduleExpression: "cron(* * ? * 1 *)",
});
expect(awscdkSanitize(template)).toMatchSnapshot();
});
Expand All @@ -66,7 +66,7 @@ test("convert the range of dayOfWeek from Unix to AWS", () => {
// GIVEN
const app = new AwsCdkApp();
const schedule = new cloud.Schedule(app, "Schedule", {
cron: "* * * * 1-7",
cron: "* * * * 0-6",
});
schedule.onTick(INFLIGHT_CODE);
const output = app.synth();
Expand All @@ -75,7 +75,7 @@ test("convert the range of dayOfWeek from Unix to AWS", () => {
const template = Template.fromJSON(JSON.parse(output));
template.resourceCountIs("AWS::Events::Rule", 1);
template.hasResourceProperties("AWS::Events::Rule", {
ScheduleExpression: "cron(* * ? * 0-6 *)",
ScheduleExpression: "cron(* * ? * 1-7 *)",
});
expect(awscdkSanitize(template)).toMatchSnapshot();
});
Expand All @@ -84,7 +84,7 @@ test("convert the list of dayOfWeek from Unix to AWS", () => {
// GIVEN
const app = new AwsCdkApp();
const schedule = new cloud.Schedule(app, "Schedule", {
cron: "* * * * 1,3,5,7",
cron: "* * * * 0,2,4,6",
});
schedule.onTick(INFLIGHT_CODE);
const output = app.synth();
Expand All @@ -93,7 +93,7 @@ test("convert the list of dayOfWeek from Unix to AWS", () => {
const template = Template.fromJSON(JSON.parse(output));
template.resourceCountIs("AWS::Events::Rule", 1);
template.hasResourceProperties("AWS::Events::Rule", {
ScheduleExpression: "cron(* * ? * 0,2,4,6 *)",
ScheduleExpression: "cron(* * ? * 1,3,5,7 *)",
});
expect(awscdkSanitize(template)).toMatchSnapshot();
});
Expand Down
1 change: 1 addition & 0 deletions packages/@winglang/sdk/src/cloud/bucket.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ By default, buckets are configured with CORS for any origin. When a bucket is pr

```js playground example
bring cloud;
bring http;

let uploads = new cloud.Bucket(
// these are the default values
Expand Down
2 changes: 1 addition & 1 deletion packages/@winglang/sdk/src/shared-aws/schedule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const convertDayOfWeekFromUnixToAWS = (dayOfWeek: string): string => {

if (numbers) {
for (const number of numbers) {
dayOfWeek = dayOfWeek.replace(number, (parseInt(number) - 1).toString());
dayOfWeek = dayOfWeek.replace(number, (parseInt(number) + 1).toString());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`convert single dayOfWeek from Unix to AWS 1`] = `
"resource": {
"aws_cloudwatch_event_rule": {
"Schedule_15669BF1": {
"schedule_expression": "cron(* * ? * 0 *)",
"schedule_expression": "cron(* * ? * 1 *)",
},
},
"aws_cloudwatch_event_target": {
Expand Down Expand Up @@ -291,7 +291,7 @@ exports[`convert the list of dayOfWeek from Unix to AWS 1`] = `
"resource": {
"aws_cloudwatch_event_rule": {
"Schedule_15669BF1": {
"schedule_expression": "cron(* * ? * 0,2,4,6 *)",
"schedule_expression": "cron(* * ? * 1,3,5,7 *)",
},
},
"aws_cloudwatch_event_target": {
Expand Down Expand Up @@ -577,7 +577,7 @@ exports[`convert the range of dayOfWeek from Unix to AWS 1`] = `
"resource": {
"aws_cloudwatch_event_rule": {
"Schedule_15669BF1": {
"schedule_expression": "cron(* * ? * 0-6 *)",
"schedule_expression": "cron(* * ? * 1-7 *)",
},
},
"aws_cloudwatch_event_target": {
Expand Down
12 changes: 6 additions & 6 deletions packages/@winglang/sdk/test/target-tf-aws/schedule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ test("convert single dayOfWeek from Unix to AWS", () => {
// GIVEN
const app = new AwsApp();
const schedule = new cloud.Schedule(app, "Schedule", {
cron: "* * * * 1",
cron: "* * * * 0",
});
schedule.onTick(CODE_LOG_EVENT);
const output = app.synth();
Expand All @@ -108,7 +108,7 @@ test("convert single dayOfWeek from Unix to AWS", () => {
output,
"aws_cloudwatch_event_rule",
{
schedule_expression: "cron(* * ? * 0 *)",
schedule_expression: "cron(* * ? * 1 *)",
}
)
).toEqual(true);
Expand All @@ -120,7 +120,7 @@ test("convert the range of dayOfWeek from Unix to AWS", () => {
// GIVEN
const app = new AwsApp();
const schedule = new cloud.Schedule(app, "Schedule", {
cron: "* * * * 1-7",
cron: "* * * * 0-6",
});
schedule.onTick(CODE_LOG_EVENT);
const output = app.synth();
Expand All @@ -143,7 +143,7 @@ test("convert the range of dayOfWeek from Unix to AWS", () => {
output,
"aws_cloudwatch_event_rule",
{
schedule_expression: "cron(* * ? * 0-6 *)",
schedule_expression: "cron(* * ? * 1-7 *)",
}
)
).toEqual(true);
Expand All @@ -155,7 +155,7 @@ test("convert the list of dayOfWeek from Unix to AWS", () => {
// GIVEN
const app = new AwsApp();
const schedule = new cloud.Schedule(app, "Schedule", {
cron: "* * * * 1,3,5,7",
cron: "* * * * 0,2,4,6",
});
schedule.onTick(CODE_LOG_EVENT);
const output = app.synth();
Expand All @@ -178,7 +178,7 @@ test("convert the list of dayOfWeek from Unix to AWS", () => {
output,
"aws_cloudwatch_event_rule",
{
schedule_expression: "cron(* * ? * 0,2,4,6 *)",
schedule_expression: "cron(* * ? * 1,3,5,7 *)",
}
)
).toEqual(true);
Expand Down

0 comments on commit cdf646c

Please sign in to comment.