forked from kubernetes-sigs/aws-load-balancer-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
77aaf66
commit d4bf180
Showing
15 changed files
with
160 additions
and
34 deletions.
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
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
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,24 @@ | ||
package endpoints | ||
|
||
import "github.com/aws/aws-sdk-go-v2/aws" | ||
|
||
func NewResolver(configuration map[string]string) *Resolver { | ||
return &Resolver{ | ||
configuration: configuration, | ||
} | ||
} | ||
|
||
// Resolver is an AWS endpoints.Resolver that allows to customize AWS API endpoints. | ||
// It can be configured using the following format "${AWSServiceID}=${URL}" | ||
// e.g. "EC2=https://ec2.domain.com,Elastic Load Balancing v2=https://elbv2.domain.com" | ||
type Resolver struct { | ||
configuration map[string]string | ||
} | ||
|
||
func (c *Resolver) EndpointFor(serviceId string) *string { | ||
customEndpoint := c.configuration[serviceId] | ||
if len(customEndpoint) != 0 { | ||
return aws.String(customEndpoint) | ||
} | ||
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,53 @@ | ||
package endpoints | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go-v2/aws" | ||
"github.com/aws/aws-sdk-go-v2/service/ec2" | ||
"github.com/aws/aws-sdk-go-v2/service/elasticloadbalancingv2" | ||
"github.com/aws/aws-sdk-go-v2/service/wafv2" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestAWSEndpointResolver_EndpointFor(t *testing.T) { | ||
configuration := map[string]string{ | ||
ec2.ServiceID: "https://ec2.domain.com", | ||
elasticloadbalancingv2.ServiceID: "https://elbv2.domain.com", | ||
} | ||
c := &Resolver{ | ||
configuration: configuration, | ||
} | ||
|
||
type args struct { | ||
val string | ||
} | ||
|
||
tests := []struct { | ||
name string | ||
args args | ||
want *string | ||
wantErr error | ||
}{ | ||
{ | ||
name: "when custom endpoint is configured", | ||
args: args{ | ||
val: ec2.ServiceID, | ||
}, | ||
want: aws.String(configuration[ec2.ServiceID]), | ||
}, | ||
{ | ||
name: "when custom endpoint is unconfigured", | ||
args: args{ | ||
val: wafv2.ServiceID, | ||
}, | ||
want: nil, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
res := c.EndpointFor(tt.args.val) | ||
assert.Equal(t, tt.want, res) | ||
}) | ||
} | ||
} |
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
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
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
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
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