Skip to content

Commit

Permalink
Add support for wildcard custom domains
Browse files Browse the repository at this point in the history
  • Loading branch information
ipmb committed Mar 3, 2023
1 parent 86d8721 commit 53a3d99
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
14 changes: 8 additions & 6 deletions stacks/custom_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type CustomDomainStackParameters struct {
HostedZone string
ClusterStackName string
PrimaryDomain string
CertificateName string
AltDomain1 string
AltDomain2 string
AltDomain3 string
Expand Down Expand Up @@ -141,6 +142,8 @@ func (p *CustomDomainStackParameters) SetInternalFields(sess *session.Session, n
}
p.HostedZone = strings.Split(*zone.Id, "/")[2]
ui.Spinner.Stop()
// `*` is not allowed in certificate names
p.CertificateName = strings.Replace(*name, "*", "wildcard", -1)
return nil
}

Expand Down Expand Up @@ -182,20 +185,19 @@ func (*CustomDomainStack) AskQuestions(_ *session.Session) error {
}

func (*CustomDomainStack) StackName(name *string) *string {
stackName := fmt.Sprintf(
customDomainStackNameTmpl,
strings.ReplaceAll(strings.TrimSuffix(*name, "."), ".", "-"),
)
slug := strings.ReplaceAll(strings.TrimSuffix(*name, "."), ".", "-")
slug = strings.ReplaceAll(slug, "*", "wildcard")
stackName := fmt.Sprintf(customDomainStackNameTmpl, slug)
return &stackName
}

func (*CustomDomainStack) StackType() string {
return "custom domain"
}

func (*CustomDomainStack) Tags(name *string) []*cloudformation.Tag {
func (a *CustomDomainStack) Tags(name *string) []*cloudformation.Tag {
return []*cloudformation.Tag{
{Key: aws.String("apppack:customDomain"), Value: name},
{Key: aws.String("apppack:customDomain"), Value: &a.Parameters.CertificateName},
// TODO
// {Key: aws.String("apppack:appName"), Value: appName},
{Key: aws.String("apppack"), Value: aws.String("true")},
Expand Down
22 changes: 22 additions & 0 deletions stacks/custom_domain_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package stacks

import (
"testing"

"github.com/aws/aws-sdk-go/aws"
)

func TestCustomDomainStackName(t *testing.T) {
stack := CustomDomainStack{}
actual := stack.StackName(aws.String("example.com"))
expected := "apppack-customdomain-example-com"
if *actual != expected {
t.Errorf("Expected %s, got %s", expected, *actual)
}

actual = stack.StackName(aws.String("*.example.com"))
expected = "apppack-customdomain-wildcard-example-com"
if *actual != expected {
t.Errorf("Expected %s, got %s", expected, *actual)
}
}

0 comments on commit 53a3d99

Please sign in to comment.