-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OCM-12364 | feat: create/cluster validation for hcpsharedvpc flags
- Loading branch information
1 parent
e22e1ea
commit bdccf8d
Showing
3 changed files
with
129 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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,38 @@ | ||
package cluster | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go-v2/aws/arn" | ||
) | ||
|
||
const ( | ||
hcpSharedVpcFlagOnlyErrorMsg = "setting the '%s' flag is only supported when creating a Hosted Control Plane " + | ||
"cluster" | ||
|
||
hcpSharedVpcFlagNotFilledErrorMsg = "must supply '%s' flag when creating a Hosted Control Plane shared VPC cluster" | ||
|
||
isNotValidArnErrorMsg = "ARN supplied with flag '%s' is not a valid ARN format" | ||
) | ||
|
||
func validateHcpSharedVpcArgs(route53RoleArn string, vpcEndpointRoleArn string, | ||
ingressPrivateHostedZoneId string, hcpInternalCommunicationHostedZoneId string) error { | ||
|
||
if route53RoleArn == "" { | ||
return fmt.Errorf(hcpSharedVpcFlagNotFilledErrorMsg, route53RoleArnFlag) | ||
} else if !arn.IsARN(route53RoleArn) { | ||
return fmt.Errorf(isNotValidArnErrorMsg, route53RoleArnFlag) | ||
} | ||
if vpcEndpointRoleArn == "" { | ||
return fmt.Errorf(hcpSharedVpcFlagNotFilledErrorMsg, vpcEndpointRoleArnFlag) | ||
} else if !arn.IsARN(vpcEndpointRoleArn) { | ||
return fmt.Errorf(isNotValidArnErrorMsg, vpcEndpointRoleArnFlag) | ||
} | ||
if ingressPrivateHostedZoneId == "" { | ||
return fmt.Errorf(hcpSharedVpcFlagNotFilledErrorMsg, ingressPrivateHostedZoneIdFlag) | ||
} | ||
if hcpInternalCommunicationHostedZoneId == "" { | ||
return fmt.Errorf(hcpSharedVpcFlagNotFilledErrorMsg, hcpInternalCommunicationHostedZoneIdFlag) | ||
} | ||
return nil | ||
} |
This file contains 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,57 @@ | ||
package cluster | ||
|
||
import ( | ||
"fmt" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Test validation functions", func() { | ||
|
||
validTestArn := "arn:aws:iam::123456789012:role/test" | ||
invalidTestArn := "123arn:aws?" | ||
|
||
Context("Validation of HCP shared VPC", func() { | ||
When("isHostedCp", func() { | ||
It("OK: Passes validation (all flags filled out and correct format", func() { | ||
err := validateHcpSharedVpcArgs(validTestArn, validTestArn, "123", "123") | ||
Expect(err).ToNot(HaveOccurred()) | ||
}) | ||
It("KO: Invalid Route53 ARN", func() { | ||
err := validateHcpSharedVpcArgs(invalidTestArn, validTestArn, "123", "123") | ||
Expect(err).To(HaveOccurred()) | ||
Expect(err.Error()).To(ContainSubstring(fmt.Sprintf(isNotValidArnErrorMsg, route53RoleArnFlag))) | ||
}) | ||
It("KO: invalid VPC Endpoint ARN", func() { | ||
err := validateHcpSharedVpcArgs(validTestArn, invalidTestArn, "123", "123") | ||
Expect(err).To(HaveOccurred()) | ||
Expect(err.Error()).To(ContainSubstring(fmt.Sprintf(isNotValidArnErrorMsg, vpcEndpointRoleArnFlag))) | ||
}) | ||
It("KO: Route53 ARN flag not populated", func() { | ||
err := validateHcpSharedVpcArgs("", validTestArn, "123", "123") | ||
Expect(err).To(HaveOccurred()) | ||
Expect(err.Error()).To(ContainSubstring(fmt.Sprintf(hcpSharedVpcFlagNotFilledErrorMsg, | ||
route53RoleArnFlag))) | ||
}) | ||
It("KO: VPC Endpoint ARN flag not populated", func() { | ||
err := validateHcpSharedVpcArgs(validTestArn, "", "123", "123") | ||
Expect(err).To(HaveOccurred()) | ||
Expect(err.Error()).To(ContainSubstring(fmt.Sprintf(hcpSharedVpcFlagNotFilledErrorMsg, | ||
vpcEndpointRoleArnFlag))) | ||
}) | ||
It("KO: Ingress Private Hosted Zone ID flag not populated", func() { | ||
err := validateHcpSharedVpcArgs(validTestArn, validTestArn, "", "123") | ||
Expect(err).To(HaveOccurred()) | ||
Expect(err.Error()).To(ContainSubstring(fmt.Sprintf(hcpSharedVpcFlagNotFilledErrorMsg, | ||
ingressPrivateHostedZoneIdFlag))) | ||
}) | ||
It("KO: HCP Internal Communication Hosted Zone ID flag not populated", func() { | ||
err := validateHcpSharedVpcArgs(validTestArn, validTestArn, "123", "") | ||
Expect(err).To(HaveOccurred()) | ||
Expect(err.Error()).To(ContainSubstring(fmt.Sprintf(hcpSharedVpcFlagNotFilledErrorMsg, | ||
hcpInternalCommunicationHostedZoneIdFlag))) | ||
}) | ||
}) | ||
}) | ||
}) |