-
Notifications
You must be signed in to change notification settings - Fork 156
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
dreamorosi
merged 4 commits into
aws-powertools:main
from
VatsalGoel3:feature/transfer-family-schema
Feb 10, 2025
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f58af61
feat(parser): add TransferFamilySchema with type definitions, tests, …
VatsalGoel3 b904c85
fix: revert unintended changes to package.json, package-lock.json
VatsalGoel3 94d2e89
fix: revert all unintended package.json changes to match main
VatsalGoel3 41a1725
fix(parser): apply requested changes for TransferFamilySchema
VatsalGoel3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { z } from 'zod'; | ||
|
||
/** | ||
* TransferFamilySchema validates events coming from AWS Transfer Family. | ||
*/ | ||
export const TransferFamilySchema = z.object({ | ||
dreamorosi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
username: z.string(), | ||
password: z.string(), | ||
protocol: z.string(), | ||
serverId: z.string(), | ||
// Validates that sourceIp is a valid IPv4/IPv6 string. Adjust as needed. | ||
sourceIp: z | ||
.string() | ||
.refine( | ||
(ip) => | ||
/^(\d{1,3}\.){3}\d{1,3}$/.test(ip) || | ||
!!ip.match(/^([0-9a-f]{0,4}:){2,7}[0-9a-f]{0,4}$/i), | ||
{ message: 'Invalid IP address' } | ||
), | ||
dreamorosi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}); | ||
|
||
/** | ||
* Type alias for TransferFamilyEvent, inferred from this schema. | ||
*/ | ||
export type TransferFamilyEvent = z.infer<typeof TransferFamilySchema>; | ||
dreamorosi marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
|
dreamorosi marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { describe, expect, it } from 'vitest'; // or jest, depending on the project configuration | ||
dreamorosi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import { TransferFamilySchema } from '../../../src/schemas/transfer-family'; | ||
|
||
describe('TransferFamilySchema', () => { | ||
it('should validate a valid TransferFamily event', () => { | ||
const validEvent = { | ||
username: 'testUser', | ||
password: 'testPass', | ||
protocol: 'SFTP', | ||
serverId: 's-abcd123456', | ||
sourceIp: '192.168.0.100', | ||
}; | ||
|
||
// This should not throw an error if the event is valid. | ||
expect(() => TransferFamilySchema.parse(validEvent)).not.toThrow(); | ||
}); | ||
|
||
it('should throw an error for an invalid TransferFamily event', () => { | ||
const invalidEvent = { | ||
username: 'testUser', | ||
// missing password | ||
protocol: 'SFTP', | ||
serverId: 's-abcd123456', | ||
sourceIp: 'invalid-ip', | ||
}; | ||
|
||
// This should throw an error due to missing fields / invalid IP. | ||
expect(() => TransferFamilySchema.parse(invalidEvent)).toThrow(); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.