refactor(t228): remove Python ERP connector
This commit is contained in:
@@ -19,46 +19,40 @@ const (
|
||||
ClaimLeaseEnvironment = "CMROUBAO_CLAIM_LEASE"
|
||||
RunningLeaseEnvironment = "CMROUBAO_RUNNING_LEASE"
|
||||
ReadinessTTLEnvironment = "CMROUBAO_READINESS_TTL"
|
||||
ERPConnectorURLEnvironment = "CMROUBAO_ERP_CONNECTOR_URL"
|
||||
ERPConnectorAPIKeyEnvironment = "CMROUBAO_ERP_CONNECTOR_API_KEY"
|
||||
ShunyunbaoURLEnvironment = "CMROUBAO_SHUNYUNBAO_URL"
|
||||
ShunyunbaoUsernameEnvironment = "CMROUBAO_SHUNYUNBAO_USERNAME"
|
||||
ShunyunbaoPasswordEnvironment = "CMROUBAO_SHUNYUNBAO_PASSWORD"
|
||||
|
||||
defaultHTTPAddress = "127.0.0.1:8080"
|
||||
defaultDatabasePath = "var/cmroubao.db"
|
||||
defaultAssetDirectory = "var/assets"
|
||||
defaultClaimLease = 10 * time.Minute
|
||||
defaultRunningLease = 30 * time.Minute
|
||||
defaultReadinessTTL = 2 * time.Minute
|
||||
defaultERPConnectorURL = "http://127.0.0.1:8091"
|
||||
defaultShunyunbaoURL = "https://www.shunyunbaoerp.com"
|
||||
defaultHTTPAddress = "127.0.0.1:8080"
|
||||
defaultDatabasePath = "var/cmroubao.db"
|
||||
defaultAssetDirectory = "var/assets"
|
||||
defaultClaimLease = 10 * time.Minute
|
||||
defaultRunningLease = 30 * time.Minute
|
||||
defaultReadinessTTL = 2 * time.Minute
|
||||
defaultShunyunbaoURL = "https://www.shunyunbaoerp.com"
|
||||
)
|
||||
|
||||
type LookupEnvironment func(string) (string, bool)
|
||||
|
||||
type Config struct {
|
||||
HTTPAddress string
|
||||
DatabasePath string
|
||||
AssetDirectory string
|
||||
TLSCertificate string
|
||||
TLSPrivateKey string
|
||||
ReadHeaderTimeout time.Duration
|
||||
ReadTimeout time.Duration
|
||||
WriteTimeout time.Duration
|
||||
IdleTimeout time.Duration
|
||||
ShutdownTimeout time.Duration
|
||||
MaxHeaderBytes int
|
||||
ClaimLease time.Duration
|
||||
RunningLease time.Duration
|
||||
ReadinessTTL time.Duration
|
||||
ERPConnectorURL string
|
||||
ERPConnectorAPIKey string
|
||||
ERPConnectorTimeout time.Duration
|
||||
ShunyunbaoURL string
|
||||
ShunyunbaoUsername string
|
||||
ShunyunbaoPassword string
|
||||
ShunyunbaoTimeout time.Duration
|
||||
HTTPAddress string
|
||||
DatabasePath string
|
||||
AssetDirectory string
|
||||
TLSCertificate string
|
||||
TLSPrivateKey string
|
||||
ReadHeaderTimeout time.Duration
|
||||
ReadTimeout time.Duration
|
||||
WriteTimeout time.Duration
|
||||
IdleTimeout time.Duration
|
||||
ShutdownTimeout time.Duration
|
||||
MaxHeaderBytes int
|
||||
ClaimLease time.Duration
|
||||
RunningLease time.Duration
|
||||
ReadinessTTL time.Duration
|
||||
ShunyunbaoURL string
|
||||
ShunyunbaoUsername string
|
||||
ShunyunbaoPassword string
|
||||
ShunyunbaoTimeout time.Duration
|
||||
}
|
||||
|
||||
func Load(lookup LookupEnvironment) (Config, error) {
|
||||
@@ -152,27 +146,6 @@ func Load(lookup LookupEnvironment) (Config, error) {
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
erpConnectorURL, err := environmentValue(
|
||||
lookup,
|
||||
ERPConnectorURLEnvironment,
|
||||
defaultERPConnectorURL,
|
||||
)
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
if err := validateLoopbackURL(erpConnectorURL); err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
erpConnectorAPIKey := ""
|
||||
if value, exists := lookup(ERPConnectorAPIKeyEnvironment); exists {
|
||||
erpConnectorAPIKey = strings.TrimSpace(value)
|
||||
if len([]byte(erpConnectorAPIKey)) < 32 {
|
||||
return Config{}, errors.New(
|
||||
ERPConnectorAPIKeyEnvironment +
|
||||
" must contain at least 32 UTF-8 bytes",
|
||||
)
|
||||
}
|
||||
}
|
||||
shunyunbaoURL, err := environmentValue(
|
||||
lookup,
|
||||
ShunyunbaoURLEnvironment,
|
||||
@@ -206,57 +179,27 @@ func Load(lookup LookupEnvironment) (Config, error) {
|
||||
}
|
||||
|
||||
return Config{
|
||||
HTTPAddress: httpAddress,
|
||||
DatabasePath: filepath.Clean(databasePath),
|
||||
AssetDirectory: assetDirectory,
|
||||
TLSCertificate: cleanOptionalPath(tlsCertificate),
|
||||
TLSPrivateKey: cleanOptionalPath(tlsPrivateKey),
|
||||
ReadHeaderTimeout: 5 * time.Second,
|
||||
ReadTimeout: 15 * time.Second,
|
||||
WriteTimeout: 30 * time.Second,
|
||||
IdleTimeout: 60 * time.Second,
|
||||
ShutdownTimeout: 10 * time.Second,
|
||||
MaxHeaderBytes: 1 << 20,
|
||||
ClaimLease: claimLease,
|
||||
RunningLease: runningLease,
|
||||
ReadinessTTL: readinessTTL,
|
||||
ERPConnectorURL: strings.TrimRight(erpConnectorURL, "/"),
|
||||
ERPConnectorAPIKey: erpConnectorAPIKey,
|
||||
ERPConnectorTimeout: 90 * time.Second,
|
||||
ShunyunbaoURL: strings.TrimRight(shunyunbaoURL, "/"),
|
||||
ShunyunbaoUsername: shunyunbaoUsername,
|
||||
ShunyunbaoPassword: shunyunbaoPassword,
|
||||
ShunyunbaoTimeout: 30 * time.Second,
|
||||
HTTPAddress: httpAddress,
|
||||
DatabasePath: filepath.Clean(databasePath),
|
||||
AssetDirectory: assetDirectory,
|
||||
TLSCertificate: cleanOptionalPath(tlsCertificate),
|
||||
TLSPrivateKey: cleanOptionalPath(tlsPrivateKey),
|
||||
ReadHeaderTimeout: 5 * time.Second,
|
||||
ReadTimeout: 15 * time.Second,
|
||||
WriteTimeout: 30 * time.Second,
|
||||
IdleTimeout: 60 * time.Second,
|
||||
ShutdownTimeout: 10 * time.Second,
|
||||
MaxHeaderBytes: 1 << 20,
|
||||
ClaimLease: claimLease,
|
||||
RunningLease: runningLease,
|
||||
ReadinessTTL: readinessTTL,
|
||||
ShunyunbaoURL: strings.TrimRight(shunyunbaoURL, "/"),
|
||||
ShunyunbaoUsername: shunyunbaoUsername,
|
||||
ShunyunbaoPassword: shunyunbaoPassword,
|
||||
ShunyunbaoTimeout: 30 * time.Second,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func validateLoopbackURL(value string) error {
|
||||
parsed, err := url.Parse(value)
|
||||
if err != nil || parsed.Scheme != "http" || parsed.User != nil ||
|
||||
parsed.RawQuery != "" || parsed.Fragment != "" ||
|
||||
(parsed.Path != "" && parsed.Path != "/") {
|
||||
return errors.New(
|
||||
ERPConnectorURLEnvironment +
|
||||
" must be an http loopback origin without credentials or path",
|
||||
)
|
||||
}
|
||||
host := parsed.Hostname()
|
||||
ip := net.ParseIP(host)
|
||||
if !strings.EqualFold(host, "localhost") &&
|
||||
(ip == nil || !ip.IsLoopback()) {
|
||||
return errors.New(
|
||||
ERPConnectorURLEnvironment + " must use a loopback host",
|
||||
)
|
||||
}
|
||||
port, err := strconv.Atoi(parsed.Port())
|
||||
if err != nil || port < 1 || port > 65535 {
|
||||
return errors.New(
|
||||
ERPConnectorURLEnvironment + " must include a valid port",
|
||||
)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateHTTPSOrigin(value, environment string) error {
|
||||
parsed, err := url.Parse(value)
|
||||
if err != nil || parsed.Scheme != "https" || parsed.Host == "" ||
|
||||
|
||||
Reference in New Issue
Block a user