Skip to content

feat(parser): add TransferFamilySchema for AWS Transfer Family events #3575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/utilities/parser.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Parser comes with the following built-in schemas:
| **SesSchema** | Lambda Event Source payload for Amazon Simple Email Service |
| **SnsSchema** | Lambda Event Source payload for Amazon Simple Notification Service |
| **SqsSchema** | Lambda Event Source payload for Amazon SQS |
| **TransferFamilySchema** | Lambda Event Source payload for AWS Transfer Family events |
| **VpcLatticeSchema** | Lambda Event Source payload for Amazon VPC Lattice |
| **VpcLatticeV2Schema** | Lambda Event Source payload for Amazon VPC Lattice v2 payload |

Expand Down
8 changes: 8 additions & 0 deletions packages/parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@
"require": "./lib/cjs/schemas/sqs.js",
"import": "./lib/esm/schemas/sqs.js"
},
"./schemas/transfer-family": {
"require": "./lib/cjs/schemas/transfer-family.js",
"import": "./lib/esm/schemas/transfer-family.js"
},
"./schemas/vpc-lattice": {
"require": "./lib/cjs/schemas/vpc-lattice.js",
"import": "./lib/esm/schemas/vpc-lattice.js"
Expand Down Expand Up @@ -323,6 +327,10 @@
"./lib/cjs/envelopes/sqs.d.ts",
"./lib/esm/envelopes/sqs.d.ts"
],
"schemas/transfer-family": [
"./lib/cjs/schemas/transfer-family.d.ts",
"./lib/esm/schemas/transfer-family.d.ts"
],
"envelopes/vpc-lattice": [
"./lib/cjs/envelopes/vpc-lattice.d.ts",
"./lib/esm/envelopes/vpc-lattice.d.ts"
Expand Down
1 change: 1 addition & 0 deletions packages/parser/src/schemas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,6 @@ export {
SnsNotificationSchema,
} from './sns.js';
export { SqsSchema, SqsRecordSchema } from './sqs.js';
export { TransferFamilySchema } from './transfer-family.js';
export { VpcLatticeSchema } from './vpc-lattice.js';
export { VpcLatticeV2Schema } from './vpc-latticev2.js';
29 changes: 29 additions & 0 deletions packages/parser/src/schemas/transfer-family.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { z } from 'zod';

/**
*
* Zod schema for AWS Transfer Family events.
*
* @example
* ```json
* {
* "username": "testUser",
* "password": "testPass",
* "protocol": "SFTP",
* "serverId": "s-abcd123456",
* "sourceIp": "192.168.0.100"
* }
* ```
*
* TransferFamilySchema validates events coming from AWS Transfer Family.
*
*/
const TransferFamilySchema = z.object({
username: z.string(),
password: z.string(),
protocol: z.string(),
serverId: z.string(),
sourceIp: z.string().ip(),
});

export { TransferFamilySchema };
1 change: 1 addition & 0 deletions packages/parser/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export type {
SnsEvent,
SnsSqsNotification,
SqsEvent,
TransferFamilyEvent,
VpcLatticeEvent,
VpcLatticeEventV2,
} from './schema.js';
4 changes: 4 additions & 0 deletions packages/parser/src/types/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import type {
SnsSqsNotificationSchema,
SqsRecordSchema,
SqsSchema,
TransferFamilySchema,
VpcLatticeSchema,
VpcLatticeV2Schema,
} from '../schemas/index.js';
Expand Down Expand Up @@ -129,6 +130,8 @@ type SqsEvent = z.infer<typeof SqsSchema>;

type SqsRecord = z.infer<typeof SqsRecordSchema>;

type TransferFamilyEvent = z.infer<typeof TransferFamilySchema>;

type VpcLatticeEvent = z.infer<typeof VpcLatticeSchema>;

type VpcLatticeEventV2 = z.infer<typeof VpcLatticeV2Schema>;
Expand Down Expand Up @@ -171,6 +174,7 @@ export type {
SnsRecord,
SqsEvent,
SqsRecord,
TransferFamilyEvent,
VpcLatticeEvent,
VpcLatticeEventV2,
};
8 changes: 8 additions & 0 deletions packages/parser/tests/events/transfer-family/base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"username": "value",
"password": "value",
"protocol": "SFTP",
"serverId": "s-abcd123456",
"sourceIp": "192.168.0.100"
}

35 changes: 35 additions & 0 deletions packages/parser/tests/unit/schema/transfer-family.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { describe, expect, it } from 'vitest';
import { TransferFamilySchema } from '../../../src/schemas/transfer-family';
import type { TransferFamilyEvent } from '../../../src/types/schema.js';
import { getTestEvent } from '../helpers/utils';

describe('Schema: TransferFamily', () => {
const baseEvent = getTestEvent<TransferFamilyEvent>({
eventsPath: 'transfer-family',
filename: 'base',
});

it('parses a valid TransferFamily event', () => {
// Prepare
const event = structuredClone(baseEvent);

// Act
const result = TransferFamilySchema.parse(event);

// Assess
expect(result).toStrictEqual(event);
});

it('throws if the event is not a valid TransferFamily event', () => {
// Prepare
const invalidEvent = {
username: 'testUser',
protocol: 'SFTP',
serverId: 's-abcd123456',
sourceIp: 'invalid-ip',
};

// Act & Assess
expect(() => TransferFamilySchema.parse(invalidEvent)).toThrow();
});
});