Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
164adc7
add option to manifest, redirect to https in cf, forward http to alb
dannyrandall Sep 16, 2022
3f683bc
manifest validation
dannyrandall Sep 20, 2022
a7d9344
verify services will work with `terminate_tls`
dannyrandall Sep 20, 2022
35eed74
testing in package elbv2
dannyrandall Sep 20, 2022
ef68646
gen mocks
dannyrandall Sep 20, 2022
eda434e
env_deploy tests
dannyrandall Sep 20, 2022
410b803
export some CDN manifest types
dannyrandall Sep 20, 2022
7241bdc
better error, Verify() tests cases
dannyrandall Sep 20, 2022
97d9e21
add `Verify()` to `env package`
dannyrandall Sep 20, 2022
ce1cafe
function docs
dannyrandall Sep 20, 2022
21a53ac
Merge branch 'mainline' into feat/cdn-tls
dannyrandall Sep 20, 2022
ff705ce
fix lint
dannyrandall Sep 21, 2022
d942ac5
change rule api
dannyrandall Sep 21, 2022
0348066
Update internal/pkg/cli/deploy/env.go
dannyrandall Sep 21, 2022
d084e34
rename to validate
dannyrandall Sep 21, 2022
8bae8a8
Update internal/pkg/cli/deploy/env.go
dannyrandall Sep 21, 2022
dc7bde0
Update internal/pkg/cli/deploy/env.go
dannyrandall Sep 22, 2022
026df8c
Update internal/pkg/cli/deploy/env.go
dannyrandall Sep 22, 2022
63650d6
don't leak manifest internals
dannyrandall Sep 22, 2022
b3c148d
change error to just be a warning
dannyrandall Sep 22, 2022
1db2650
move constant
dannyrandall Sep 22, 2022
c52c836
warn sometimes, error sometimes
dannyrandall Sep 22, 2022
4086a65
error testing
dannyrandall Sep 22, 2022
9ac84d3
delete extra func
dannyrandall Sep 22, 2022
6d7d336
Merge branch 'mainline' into feat/cdn-tls
dannyrandall Sep 22, 2022
556fc96
fix interfaces
dannyrandall Sep 22, 2022
abfc832
fix elbv2 tests
dannyrandall Sep 22, 2022
90a2126
fix lint
dannyrandall Sep 22, 2022
5fc137a
typo
dannyrandall Sep 22, 2022
544159b
use `elbv2.DescribeRulesWithContext`
dannyrandall Sep 23, 2022
8c94bf2
address some feedback
dannyrandall Sep 23, 2022
d63d204
bye friend 🫡
dannyrandall Sep 23, 2022
a9e4c33
it was fun while it lasted
dannyrandall Sep 23, 2022
e78e4d4
Merge branch 'mainline' into feat/cdn-tls
dannyrandall Sep 23, 2022
dc8ba3d
address some fb
dannyrandall Sep 26, 2022
f9614b4
docstrings
dannyrandall Sep 26, 2022
b3eee7f
change error message to a single line
dannyrandall Sep 26, 2022
cfa0206
Merge branch 'mainline' into feat/cdn-tls
dannyrandall Sep 26, 2022
5e13e94
docstring for `RecommendActions`
dannyrandall Sep 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions internal/pkg/aws/elbv2/elbv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
package elbv2

import (
"context"
"errors"
"fmt"
"sort"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/elbv2"
)
Expand All @@ -19,8 +22,9 @@ const (
)

type api interface {
DescribeTargetHealth(input *elbv2.DescribeTargetHealthInput) (*elbv2.DescribeTargetHealthOutput, error)
DescribeRules(input *elbv2.DescribeRulesInput) (*elbv2.DescribeRulesOutput, error)
DescribeTargetHealth(*elbv2.DescribeTargetHealthInput) (*elbv2.DescribeTargetHealthOutput, error)
DescribeRules(*elbv2.DescribeRulesInput) (*elbv2.DescribeRulesOutput, error)
DescribeRulesWithContext(context.Context, *elbv2.DescribeRulesInput, ...request.Option) (*elbv2.DescribeRulesOutput, error)
}

// ELBV2 wraps an AWS ELBV2 client.
Expand Down Expand Up @@ -73,6 +77,33 @@ func (e *ELBV2) ListenerRuleHostHeaders(ruleARN string) ([]string, error) {
return hostHeaders, nil
}

// Rule wraps an elbv2.Rule to add some nice functionality to it.
type Rule elbv2.Rule
Comment thread
dannyrandall marked this conversation as resolved.

// DescribeRule returns the Rule with ruleARN.
func (e *ELBV2) DescribeRule(ctx context.Context, ruleARN string) (Rule, error) {
resp, err := e.client.DescribeRulesWithContext(ctx, &elbv2.DescribeRulesInput{
RuleArns: aws.StringSlice([]string{ruleARN}),
})
if err != nil {
return Rule{}, err
} else if len(resp.Rules) == 0 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we don't need the else

return Rule{}, errors.New("not found")
Comment thread
dannyrandall marked this conversation as resolved.
}

return Rule(*resp.Rules[0]), nil
}

// HasRedirectAction returns true if the rule has a redirect action.
func (r *Rule) HasRedirectAction() bool {
for _, action := range r.Actions {
if aws.StringValue(action.Type) == elbv2.ActionTypeEnumRedirect {
return true
}
}
return false
}

// TargetHealth wraps up elbv2.TargetHealthDescription.
type TargetHealth elbv2.TargetHealthDescription

Expand Down
98 changes: 98 additions & 0 deletions internal/pkg/aws/elbv2/elbv2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package elbv2

import (
"context"
"errors"
"fmt"
"testing"
Expand Down Expand Up @@ -219,6 +220,103 @@ func TestELBV2_ListenerRuleHostHeaders(t *testing.T) {
}
}

func TestELBV2_DescribeRule(t *testing.T) {
mockARN := "mockListenerRuleARN"
testCases := map[string]struct {
setUpMock func(m *mocks.Mockapi)

expectedErr string
expected Rule
}{
"fail to describe rules": {
setUpMock: func(m *mocks.Mockapi) {
m.EXPECT().DescribeRulesWithContext(gomock.Any(), &elbv2.DescribeRulesInput{
RuleArns: aws.StringSlice([]string{mockARN}),
}).Return(nil, errors.New("some error"))
},
expectedErr: "some error",
},
"cannot find listener rule": {
setUpMock: func(m *mocks.Mockapi) {
m.EXPECT().DescribeRulesWithContext(gomock.Any(), &elbv2.DescribeRulesInput{
RuleArns: aws.StringSlice([]string{mockARN}),
}).Return(&elbv2.DescribeRulesOutput{}, nil)
},
expectedErr: `not found`,
},
"success": {
setUpMock: func(m *mocks.Mockapi) {
m.EXPECT().DescribeRulesWithContext(gomock.Any(), &elbv2.DescribeRulesInput{
RuleArns: aws.StringSlice([]string{mockARN}),
}).Return(&elbv2.DescribeRulesOutput{
Rules: []*elbv2.Rule{
{
RuleArn: aws.String(mockARN),
},
},
}, nil)
},
expected: Rule(elbv2.Rule{
RuleArn: aws.String(mockARN),
}),
},
}

for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

mockAPI := mocks.NewMockapi(ctrl)
tc.setUpMock(mockAPI)

elbv2Client := ELBV2{
client: mockAPI,
}

actual, err := elbv2Client.DescribeRule(context.Background(), mockARN)
if tc.expectedErr != "" {
require.EqualError(t, err, tc.expectedErr)
} else {
require.Equal(t, tc.expected, actual)
}
})
}
}

func TestELBV2Rule_HasRedirectAction(t *testing.T) {
testCases := map[string]struct {
rule Rule
expected bool
}{
"rule doesn't have redirect": {
rule: Rule(elbv2.Rule{
Actions: []*elbv2.Action{
{
Type: aws.String(elbv2.ActionTypeEnumForward),
},
},
}),
},
"rule has redirect": {
rule: Rule(elbv2.Rule{
Actions: []*elbv2.Action{
{
Type: aws.String(elbv2.ActionTypeEnumRedirect),
},
},
}),
expected: true,
},
}

for name, tc := range testCases {
t.Run(name, func(t *testing.T) {
require.Equal(t, tc.expected, tc.rule.HasRedirectAction())
})
}
}

func TestTargetHealth_HealthStatus(t *testing.T) {
testCases := map[string]struct {
inTargetHealth *TargetHealth
Expand Down
38 changes: 30 additions & 8 deletions internal/pkg/aws/elbv2/mocks/mock_elbv2.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading