feat: settings for tls insecure skip verify (close #3306 in #3307)

pull/3311/head
BoYanZh 2023-02-08 22:01:26 +08:00 committed by GitHub
parent a4f4fb2d73
commit 7bc46de8aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 17 deletions

View File

@ -23,8 +23,9 @@ func init() {
} }
func NewRestyClient() *resty.Client { func NewRestyClient() *resty.Client {
return resty.New(). client := resty.New().
SetHeader("user-agent", UserAgent). SetHeader("user-agent", UserAgent).
SetRetryCount(3). SetRetryCount(3).
SetTimeout(DefaultTimeout) SetTimeout(DefaultTimeout)
return client
} }

View File

@ -1,10 +1,12 @@
package bootstrap package bootstrap
import ( import (
"crypto/tls"
"os" "os"
"path/filepath" "path/filepath"
"github.com/alist-org/alist/v3/cmd/flags" "github.com/alist-org/alist/v3/cmd/flags"
"github.com/alist-org/alist/v3/drivers/base"
"github.com/alist-org/alist/v3/internal/conf" "github.com/alist-org/alist/v3/internal/conf"
"github.com/alist-org/alist/v3/pkg/utils" "github.com/alist-org/alist/v3/pkg/utils"
"github.com/caarlos0/env/v7" "github.com/caarlos0/env/v7"
@ -49,7 +51,7 @@ func InitConfig() {
if err != nil { if err != nil {
log.Fatalf("marshal config error: %+v", err) log.Fatalf("marshal config error: %+v", err)
} }
err = os.WriteFile(configPath, confBody, 0777) err = os.WriteFile(configPath, confBody, 0o777)
if err != nil { if err != nil {
log.Fatalf("update config struct error: %+v", err) log.Fatalf("update config struct error: %+v", err)
} }
@ -69,11 +71,14 @@ func InitConfig() {
if err != nil { if err != nil {
log.Errorln("failed delete temp file:", err) log.Errorln("failed delete temp file:", err)
} }
err = os.MkdirAll(conf.Conf.TempDir, 0777) err = os.MkdirAll(conf.Conf.TempDir, 0o777)
if err != nil { if err != nil {
log.Fatalf("create temp dir error: %+v", err) log.Fatalf("create temp dir error: %+v", err)
} }
log.Debugf("config: %+v", conf.Conf) log.Debugf("config: %+v", conf.Conf)
if conf.Conf.TlsInsecureSkipVerify {
base.RestyClient = base.RestyClient.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true})
}
} }
func confFromEnv() { func confFromEnv() {

View File

@ -48,6 +48,7 @@ type Config struct {
BleveDir string `json:"bleve_dir" env:"BLEVE_DIR"` BleveDir string `json:"bleve_dir" env:"BLEVE_DIR"`
Log LogConfig `json:"log"` Log LogConfig `json:"log"`
MaxConnections int `json:"max_connections" env:"MAX_CONNECTIONS"` MaxConnections int `json:"max_connections" env:"MAX_CONNECTIONS"`
TlsInsecureSkipVerify bool `json:"tls_insecure_skip_verify" env:"TLS_INSECURE_SKIP_VERIFY"`
} }
func DefaultConfig() *Config { func DefaultConfig() *Config {
@ -76,5 +77,6 @@ func DefaultConfig() *Config {
MaxAge: 28, MaxAge: 28,
}, },
MaxConnections: 0, MaxConnections: 0,
TlsInsecureSkipVerify: false,
} }
} }