-
Notifications
You must be signed in to change notification settings - Fork 86
Add option to filter certificates by tag before adding it to LB #658
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -15,16 +15,18 @@ type acmExpect struct { | |
DomainNames []string | ||
Chain int | ||
Error error | ||
EmptyList bool | ||
} | ||
|
||
func TestACM(t *testing.T) { | ||
cert := mustRead("acm.txt") | ||
chain := mustRead("chain.txt") | ||
|
||
for _, ti := range []struct { | ||
msg string | ||
api acmiface.ACMAPI | ||
expect acmExpect | ||
msg string | ||
api acmiface.ACMAPI | ||
filterTag string | ||
expect acmExpect | ||
}{ | ||
{ | ||
msg: "Found ACM Cert foobar and a chain", | ||
|
@@ -69,9 +71,64 @@ func TestACM(t *testing.T) { | |
Error: nil, | ||
}, | ||
}, | ||
{ | ||
msg: "Found ACM Cert with correct filter tag", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you like to add tests with several certificates in the list. |
||
api: fake.NewACMClientWithTags( | ||
acm.ListCertificatesOutput{ | ||
CertificateSummaryList: []*acm.CertificateSummary{ | ||
{ | ||
CertificateArn: aws.String("foobar"), | ||
DomainName: aws.String("foobar.de"), | ||
}, | ||
}, | ||
}, | ||
acm.GetCertificateOutput{ | ||
Certificate: aws.String(cert), | ||
}, | ||
map[string]*acm.ListTagsForCertificateOutput{ | ||
"foobar": { | ||
Tags: []*acm.Tag{{Key: aws.String("production"), Value: aws.String("true")}}, | ||
}, | ||
}, | ||
), | ||
filterTag: "production=true", | ||
expect: acmExpect{ | ||
ARN: "foobar", | ||
DomainNames: []string{"foobar.de"}, | ||
Error: nil, | ||
}, | ||
}, | ||
{ | ||
msg: "Found ACM Cert with incorrect filter tag", | ||
lucastt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
api: fake.NewACMClientWithTags( | ||
acm.ListCertificatesOutput{ | ||
CertificateSummaryList: []*acm.CertificateSummary{ | ||
{ | ||
CertificateArn: aws.String("foobar"), | ||
DomainName: aws.String("foobar.de"), | ||
}, | ||
}, | ||
}, | ||
acm.GetCertificateOutput{ | ||
Certificate: aws.String(cert), | ||
}, | ||
map[string]*acm.ListTagsForCertificateOutput{ | ||
"foobar": { | ||
Tags: []*acm.Tag{{Key: aws.String("production"), Value: aws.String("false")}}, | ||
}, | ||
}, | ||
), | ||
filterTag: "production=true", | ||
expect: acmExpect{ | ||
EmptyList: true, | ||
ARN: "foobar", | ||
DomainNames: []string{"foobar.de"}, | ||
Error: nil, | ||
}, | ||
}, | ||
} { | ||
t.Run(ti.msg, func(t *testing.T) { | ||
provider := newACMCertProvider(ti.api) | ||
provider := newACMCertProvider(ti.api, ti.filterTag) | ||
list, err := provider.GetCertificates() | ||
|
||
if ti.expect.Error != nil { | ||
|
@@ -80,11 +137,16 @@ func TestACM(t *testing.T) { | |
require.NoError(t, err) | ||
} | ||
|
||
require.Equal(t, 1, len(list)) | ||
if ti.expect.EmptyList { | ||
require.Equal(t, 0, len(list)) | ||
|
||
cert := list[0] | ||
require.Equal(t, ti.expect.ARN, cert.ID()) | ||
require.Equal(t, ti.expect.DomainNames, cert.DomainNames()) | ||
} else { | ||
require.Equal(t, 1, len(list)) | ||
|
||
cert := list[0] | ||
require.Equal(t, ti.expect.ARN, cert.ID()) | ||
require.Equal(t, ti.expect.DomainNames, cert.DomainNames()) | ||
} | ||
}) | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we should add a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could but I believe this case is covered in the if in line 52, because if
filterTag == ""
thenlen(tag) != 2
, and in this case we will just returnacmSummaries
in line 56, which is just after the if.