Add option to skip SSL verification
This commit is contained in:
parent
889de97892
commit
03c43f20b3
4 changed files with 26 additions and 10 deletions
|
@ -18,6 +18,7 @@ The application can be configured with the following environment variables:
|
|||
- `ACCESS_KEY_ID`: Your S3 access key ID (required)
|
||||
- `SECRET_ACCESS_KEY`: Your S3 secret access key (required)
|
||||
- `USE_SSL`: Whether your S3 server uses SSL or not (defaults to `true`)
|
||||
- `SKIP_SSL_VERIFICATION`: Whether the HTTP client should skip SSL verification (defaults to `false`)
|
||||
- `PORT`: The port the s3manager app should listen on (defaults to `8080`)
|
||||
|
||||
### Build and Run Locally
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"strconv"
|
||||
|
||||
"github.com/mastertinner/adapters/logging"
|
||||
"github.com/mastertinner/s3manager/internal/app/s3manager"
|
||||
|
@ -27,11 +28,8 @@ func main() {
|
|||
if !ok {
|
||||
log.Fatal("please provide SECRET_ACCESS_KEY")
|
||||
}
|
||||
useSSLEnvVar, ok := os.LookupEnv("USE_SSL")
|
||||
if !ok {
|
||||
useSSLEnvVar = "true"
|
||||
}
|
||||
useSSL := strings.ToLower(useSSLEnvVar) == "true"
|
||||
useSSL := getBoolEnvWithDefault("USE_SSL", true)
|
||||
skipSSLVerification := getBoolEnvWithDefault("SKIP_SSL_VERIFICATION", false)
|
||||
port, ok := os.LookupEnv("PORT")
|
||||
if !ok {
|
||||
port = "8080"
|
||||
|
@ -44,6 +42,9 @@ func main() {
|
|||
if err != nil {
|
||||
log.Fatalln(fmt.Errorf("error creating s3 client: %w", err))
|
||||
}
|
||||
if useSSL && skipSSLVerification {
|
||||
s3.SetCustomTransport(&http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}) //nolint:gosec
|
||||
}
|
||||
|
||||
// Set up router
|
||||
r := way.NewRouter()
|
||||
|
@ -59,3 +60,15 @@ func main() {
|
|||
lr := logging.Handler(os.Stdout)(r)
|
||||
log.Fatal(http.ListenAndServe(":"+port, lr))
|
||||
}
|
||||
|
||||
func getBoolEnvWithDefault(name string, defaultValue bool) bool {
|
||||
envValue, ok := os.LookupEnv(name)
|
||||
if !ok {
|
||||
return defaultValue
|
||||
}
|
||||
value, err := strconv.ParseBool(envValue)
|
||||
if err != nil {
|
||||
log.Fatalf("invalid value for %s", name)
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
|
3
go.mod
3
go.mod
|
@ -10,7 +10,8 @@ require (
|
|||
github.com/matryer/way v0.0.0-20180416093233-9632d0c407b0
|
||||
github.com/minio/minio-go v6.0.14+incompatible
|
||||
github.com/smartystreets/assertions v1.2.0 // indirect
|
||||
golang.org/x/net v0.0.0-20210414194228-064579744ee0 // indirect
|
||||
golang.org/x/crypto v0.0.0-20210415154028-4f45737414dc // indirect
|
||||
golang.org/x/net v0.0.0-20210415231046-e915ea6b2b7d // indirect
|
||||
golang.org/x/sys v0.0.0-20210415045647-66c3f260301c // indirect
|
||||
gopkg.in/ini.v1 v1.62.0 // indirect
|
||||
)
|
||||
|
|
7
go.sum
7
go.sum
|
@ -266,8 +266,9 @@ golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8U
|
|||
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 h1:It14KIkyBFYkHkwZ7k45minvA9aorojkyjGk9KJ5B/w=
|
||||
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
||||
golang.org/x/crypto v0.0.0-20210415154028-4f45737414dc h1:+q90ECDSAQirdykUN6sPEiBXBsp8Csjcca8Oy7bgLTA=
|
||||
golang.org/x/crypto v0.0.0-20210415154028-4f45737414dc/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
|
||||
|
@ -330,8 +331,8 @@ golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81R
|
|||
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20210414194228-064579744ee0 h1:iqW3Mjl/6IP9cHJC/wdiIu3lyBDMUfDElRMyFlqbtiQ=
|
||||
golang.org/x/net v0.0.0-20210414194228-064579744ee0/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8=
|
||||
golang.org/x/net v0.0.0-20210415231046-e915ea6b2b7d h1:BgJvlyh+UqCUaPlscHJ+PN8GcpfrFdr7NHjd1JL0+Gs=
|
||||
golang.org/x/net v0.0.0-20210415231046-e915ea6b2b7d/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
|
|
Loading…
Reference in a new issue