Skip to content

Commit

Permalink
feat: settings for tls insecure skip verify (close #3306 in #3307)
Browse files Browse the repository at this point in the history
  • Loading branch information
BoYanZh authored Feb 8, 2023
1 parent a4f4fb2 commit 7bc46de
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 17 deletions.
3 changes: 2 additions & 1 deletion drivers/base/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ func init() {
}

func NewRestyClient() *resty.Client {
return resty.New().
client := resty.New().
SetHeader("user-agent", UserAgent).
SetRetryCount(3).
SetTimeout(DefaultTimeout)
return client
}
9 changes: 7 additions & 2 deletions internal/bootstrap/config.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package bootstrap

import (
"crypto/tls"
"os"
"path/filepath"

"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/pkg/utils"
"github.com/caarlos0/env/v7"
Expand Down Expand Up @@ -49,7 +51,7 @@ func InitConfig() {
if err != nil {
log.Fatalf("marshal config error: %+v", err)
}
err = os.WriteFile(configPath, confBody, 0777)
err = os.WriteFile(configPath, confBody, 0o777)
if err != nil {
log.Fatalf("update config struct error: %+v", err)
}
Expand All @@ -69,11 +71,14 @@ func InitConfig() {
if err != nil {
log.Errorln("failed delete temp file:", err)
}
err = os.MkdirAll(conf.Conf.TempDir, 0777)
err = os.MkdirAll(conf.Conf.TempDir, 0o777)
if err != nil {
log.Fatalf("create temp dir error: %+v", err)
}
log.Debugf("config: %+v", conf.Conf)
if conf.Conf.TlsInsecureSkipVerify {
base.RestyClient = base.RestyClient.SetTLSClientConfig(&tls.Config{InsecureSkipVerify: true})
}
}

func confFromEnv() {
Expand Down
30 changes: 16 additions & 14 deletions internal/conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,20 @@ type LogConfig struct {
}

type Config struct {
Force bool `json:"force" env:"FORCE"`
Address string `json:"address" env:"ADDR"`
Port int `json:"port" env:"PORT"`
SiteURL string `json:"site_url" env:"SITE_URL"`
Cdn string `json:"cdn" env:"CDN"`
JwtSecret string `json:"jwt_secret" env:"JWT_SECRET"`
TokenExpiresIn int `json:"token_expires_in" env:"TOKEN_EXPIRES_IN"`
Database Database `json:"database"`
Scheme Scheme `json:"scheme"`
TempDir string `json:"temp_dir" env:"TEMP_DIR"`
BleveDir string `json:"bleve_dir" env:"BLEVE_DIR"`
Log LogConfig `json:"log"`
MaxConnections int `json:"max_connections" env:"MAX_CONNECTIONS"`
Force bool `json:"force" env:"FORCE"`
Address string `json:"address" env:"ADDR"`
Port int `json:"port" env:"PORT"`
SiteURL string `json:"site_url" env:"SITE_URL"`
Cdn string `json:"cdn" env:"CDN"`
JwtSecret string `json:"jwt_secret" env:"JWT_SECRET"`
TokenExpiresIn int `json:"token_expires_in" env:"TOKEN_EXPIRES_IN"`
Database Database `json:"database"`
Scheme Scheme `json:"scheme"`
TempDir string `json:"temp_dir" env:"TEMP_DIR"`
BleveDir string `json:"bleve_dir" env:"BLEVE_DIR"`
Log LogConfig `json:"log"`
MaxConnections int `json:"max_connections" env:"MAX_CONNECTIONS"`
TlsInsecureSkipVerify bool `json:"tls_insecure_skip_verify" env:"TLS_INSECURE_SKIP_VERIFY"`
}

func DefaultConfig() *Config {
Expand Down Expand Up @@ -75,6 +76,7 @@ func DefaultConfig() *Config {
MaxBackups: 5,
MaxAge: 28,
},
MaxConnections: 0,
MaxConnections: 0,
TlsInsecureSkipVerify: false,
}
}

0 comments on commit 7bc46de

Please sign in to comment.