Skip to content
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

Add id validation to initialization process (#5) #6

Merged
merged 1 commit into from Oct 17, 2021
Merged

Conversation

nekrassov01
Copy link
Owner

Implemented id validation to initialization process using regular expressions.

Invoke-PasmInitialize.ps1

# Pattern match validation 'VpcId' and 'AssociationSubnetId'
if ($PSBoundParameters.ContainsKey('VpcId')) {
    if ($vpcId -cnotmatch '^vpc-[0-9a-z]{17}$') {
        throw [InvalidOperationException]::new($('''{0}'' does not match a valid id pattern.' -f $vpcId))
    }
}
if ($PSBoundParameters.ContainsKey('SubnetId')) {
    foreach ($id in $SubnetId) {
        if ($id -cnotmatch '^subnet-[0-9a-z]{17}$') {
            throw [InvalidOperationException]::new($('''{0}'' does not match a valid id pattern.' -f $id))
        }
    }
}

Caution

This is only a validation using regular expressions and does not guarantee that the ID actually exists.

@nekrassov01 nekrassov01 merged commit 29844cb into main Oct 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant