Skip to content

Added Custom Endpoints #6

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
# Original
sites.json

# Build Files
/s3-proxy

# Vendor
/vendor
4 changes: 3 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
kPrefixKeyName = "S3PROXY_OPTION_PREFIX"
kForceSSLKeyName = "S3PROXY_OPTION_FORCE_SSL"
kProxiedKeyName = "S3PROXY_OPTION_PROXIED"
kEndpointKeyName = "S3PROXY_OPTION_ENDPOINT"
)

func ConfiguredProxyHandler() (http.Handler, error) {
Expand Down Expand Up @@ -80,6 +81,7 @@ func createSingle() (http.Handler, error) {
Prefix: os.Getenv(kPrefixKeyName),
ForceSSL: os.Getenv(kForceSSLKeyName) == "true",
Proxied: os.Getenv(kProxiedKeyName) == "true",
Endpoint: os.Getenv(kEndpointKeyName),
}

s := Site{
Expand All @@ -103,7 +105,7 @@ func createSingle() (http.Handler, error) {
func createSiteHandler(s Site) http.Handler {
var handler http.Handler

proxy := NewS3Proxy(s.AWSKey, s.AWSSecret, s.AWSRegion, s.AWSBucket)
proxy := NewS3Proxy(s.AWSKey, s.AWSSecret, s.AWSRegion, s.AWSBucket, s.Options.Endpoint)
handler = NewProxyHandler(proxy, s.Options.Prefix)

if s.Options.Website {
Expand Down
15 changes: 15 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module github.com/lexi-the-cute/s3-proxy

go 1.21.0

require (
github.com/aws/aws-sdk-go v1.7.7-0.20170309013840-37f127c188d1
github.com/gorilla/handlers v0.0.0-20170224193955-13d73096a474
)

require (
github.com/go-ini/ini v1.25.3-0.20170223222215-c437d20015c2 // indirect
github.com/jmespath/go-jmespath v0.0.0-20160803190731-bd40a432e4c7 // indirect
github.com/smartystreets/goconvey v1.8.1 // indirect
github.com/stretchr/testify v1.8.4 // indirect
)
24 changes: 24 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
github.com/aws/aws-sdk-go v1.7.7-0.20170309013840-37f127c188d1 h1:kiold1f/BW2ImHHXjJdTAVg6IdbitFS8dtBkFdgn2dg=
github.com/aws/aws-sdk-go v1.7.7-0.20170309013840-37f127c188d1/go.mod h1:ZRmQr0FajVIyZ4ZzBYKG5P3ZqPz9IHG41ZoMu1ADI3k=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-ini/ini v1.25.3-0.20170223222215-c437d20015c2 h1:fQTW7Ld5mxOCS6aa1a3ncoq0uPA09+p+c/cYil0KI/E=
github.com/go-ini/ini v1.25.3-0.20170223222215-c437d20015c2/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
github.com/gopherjs/gopherjs v1.17.2 h1:fQnZVsXk8uxXIStYb0N4bGk7jeyTalG/wsZjQ25dO0g=
github.com/gopherjs/gopherjs v1.17.2/go.mod h1:pRRIvn/QzFLrKfvEz3qUuEhtE/zLCWfreZ6J5gM2i+k=
github.com/gorilla/handlers v0.0.0-20170224193955-13d73096a474 h1:KNovrfevBTefw9X8FKnoaKhKOc+UWmGsQRsiZRTkGl4=
github.com/gorilla/handlers v0.0.0-20170224193955-13d73096a474/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ=
github.com/jmespath/go-jmespath v0.0.0-20160803190731-bd40a432e4c7 h1:SMvOWPJCES2GdFracYbBQh93GXac8fq7HeN6JnpduB8=
github.com/jmespath/go-jmespath v0.0.0-20160803190731-bd40a432e4c7/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/smarty/assertions v1.15.0 h1:cR//PqUBUiQRakZWqBiFFQ9wb8emQGDb0HeGdqGByCY=
github.com/smarty/assertions v1.15.0/go.mod h1:yABtdzeQs6l1brC900WlRNwj6ZR55d7B+E8C6HtKdec=
github.com/smartystreets/goconvey v1.8.1 h1:qGjIddxOk4grTu9JPOU31tVfq3cNdBlNa5sSznIX1xY=
github.com/smartystreets/goconvey v1.8.1/go.mod h1:+/u4qLyY6x1jReYOp7GOM2FSt8aP9CzCZL03bI28W60=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Options struct {
Prefix string `json:"prefix"`
ForceSSL bool `json:"forceSsl"`
Proxied bool `json:"proxied"`
Endpoint string `json:"endpoint"`
}

func main() {
Expand Down
14 changes: 13 additions & 1 deletion proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/aws/aws-sdk-go/aws/endpoints"
)

type S3Proxy interface {
Expand All @@ -17,10 +18,21 @@ type RealS3Proxy struct {
s3 *s3.S3
}

func NewS3Proxy(key, secret, region, bucket string) S3Proxy {
func NewS3Proxy(key, secret, region, bucket, endpoint string) S3Proxy {
endpointResolver := func(service, region string, optFns ...func(*endpoints.Options)) (endpoints.ResolvedEndpoint, error) {
if endpoint != "" {
return endpoints.ResolvedEndpoint{
URL: endpoint,
}, nil
}

return endpoints.DefaultResolver().EndpointFor(service, region, optFns...)
}

sess := session.Must(session.NewSession(&aws.Config{
Region: aws.String(region),
Credentials: credentials.NewStaticCredentials(key, secret, ""),
EndpointResolver: endpoints.ResolverFunc(endpointResolver),
}))

return &RealS3Proxy{
Expand Down
187 changes: 0 additions & 187 deletions vendor/vendor.json

This file was deleted.