Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add localstack endpoint resolver
- Loading branch information
Showing
3 changed files
with
72 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package endpoints | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws/endpoints" | ||
"os" | ||
"strings" | ||
) | ||
|
||
type localStackResolver struct { | ||
defaultResolver endpoints.Resolver | ||
} | ||
|
||
func getLocalStackUrl() string { | ||
hostname := os.Getenv("LOCALSTACK_HOSTNAME") | ||
|
||
if hostname == "" { | ||
hostname = "localhost" | ||
} | ||
|
||
port := os.Getenv("EDGE_PORT") | ||
if port == "" { | ||
port = "4566" | ||
} | ||
|
||
ssl := os.Getenv("USE_SSL") | ||
disableSSL := true | ||
if ssl == "1" || strings.ToLower(ssl) == "true" { | ||
disableSSL = false | ||
} | ||
|
||
return endpoints.AddScheme(hostname + ":" + port, disableSSL) | ||
} | ||
|
||
func (l *localStackResolver) EndpointFor(service, region string, opts ...func(*endpoints.Options)) (endpoints.ResolvedEndpoint, error) { | ||
endpointFor, err := l.defaultResolver.EndpointFor(service, region, opts...) | ||
|
||
if err != nil { | ||
return endpointFor, err | ||
} | ||
|
||
endpointFor.URL = getLocalStackUrl() | ||
|
||
return endpointFor, err | ||
} | ||
|
||
func NewLocalstackResolver() *localStackResolver { | ||
resolver := &localStackResolver{ | ||
defaultResolver: endpoints.DefaultResolver(), | ||
} | ||
|
||
return resolver | ||
} |
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,17 @@ | ||
package endpoints | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws/endpoints" | ||
"os" | ||
"strings" | ||
) | ||
|
||
func NewResolver() endpoints.Resolver { | ||
flag := os.Getenv("LOCALSTACK_DISABLE") | ||
|
||
if flag == "1" || strings.ToLower(flag) == "true" { | ||
return endpoints.DefaultResolver() | ||
} else { | ||
return NewLocalstackResolver() | ||
} | ||
} |