Skip to content

Commit

Permalink
Make RemoveHttpRule available for import
Browse files Browse the repository at this point in the history
  • Loading branch information
edw-defang committed May 15, 2024
1 parent 9b8c09f commit 6adcba1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
12 changes: 12 additions & 0 deletions acme/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"log"
"os"

awsalb "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2/types"
"github.com/defang-io/cloudacme/aws/acm"
"github.com/defang-io/cloudacme/aws/alb"
"github.com/mholt/acmez"
Expand Down Expand Up @@ -94,6 +95,17 @@ func UpdateAcmeCertificate(ctx context.Context, albArn, domain string, solver ac
return nil
}

func RemoveHttpRule(ctx context.Context, albArn string, ruleCond alb.RuleCondition) error {
listener, err := alb.GetListener(ctx, albArn, awsalb.ProtocolEnumHttp, 80)
if err != nil {
return fmt.Errorf("cannot get http listener: %w", err)
}
if err := alb.DeleteListenerPathRule(ctx, *listener.ListenerArn, ruleCond); err != nil {
return fmt.Errorf("failed to delete listener static rule: %w", err)
}
return nil
}

func getAccountKey() (*ecdsa.PrivateKey, error) {

accountKeyPem := os.Getenv("ACME_ACCOUNT_KEY")
Expand Down
14 changes: 1 addition & 13 deletions cmd/lambda/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
awsalb "github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2/types"
"github.com/defang-io/cloudacme/acme"
"github.com/defang-io/cloudacme/aws/alb"
"github.com/defang-io/cloudacme/solver"
Expand Down Expand Up @@ -63,7 +62,7 @@ func HandleALBEvent(ctx context.Context, evt events.ALBTargetGroupRequest) (*eve
PathPattern: []string{"/"},
}

if err := RemoveHttpRule(ctx, albArn, cond); err != nil {
if err := acme.RemoveHttpRule(ctx, albArn, cond); err != nil {
return nil, fmt.Errorf("failed to remove http rule: %w", err)
}

Expand Down Expand Up @@ -107,17 +106,6 @@ func validateCertAttached(ctx context.Context, domain string) error {
}
}

func RemoveHttpRule(ctx context.Context, albArn string, ruleCond alb.RuleCondition) error {
listener, err := alb.GetListener(ctx, albArn, awsalb.ProtocolEnumHttp, 80)
if err != nil {
return fmt.Errorf("cannot get http listener: %w", err)
}
if err := alb.DeleteListenerPathRule(ctx, *listener.ListenerArn, ruleCond); err != nil {
return fmt.Errorf("failed to delete listener static rule: %w", err)
}
return nil
}

func getHttpsRedirectURL(evt events.ALBTargetGroupRequest) string {
params := ""
if evt.QueryStringParameters != nil {
Expand Down

0 comments on commit 6adcba1

Please sign in to comment.