2021-04-18 15:41:13 -04:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2020-04-14 15:46:37 -04:00
|
|
|
|
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
|
|
|
"strconv"
|
2020-06-04 17:58:34 -04:00
|
|
|
"strings"
|
2020-04-14 15:46:37 -04:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/minio/minio/cmd/config"
|
|
|
|
"github.com/minio/minio/pkg/env"
|
|
|
|
)
|
|
|
|
|
2020-06-04 17:58:34 -04:00
|
|
|
// API sub-system constants
|
2020-04-14 15:46:37 -04:00
|
|
|
const (
|
2021-04-24 00:58:45 -04:00
|
|
|
apiRequestsMax = "requests_max"
|
|
|
|
apiRequestsDeadline = "requests_deadline"
|
|
|
|
apiClusterDeadline = "cluster_deadline"
|
|
|
|
apiCorsAllowOrigin = "cors_allow_origin"
|
|
|
|
apiRemoteTransportDeadline = "remote_transport_deadline"
|
|
|
|
apiListQuorum = "list_quorum"
|
|
|
|
apiExtendListCacheLife = "extend_list_cache_life"
|
|
|
|
apiReplicationWorkers = "replication_workers"
|
|
|
|
apiReplicationFailedWorkers = "replication_failed_workers"
|
|
|
|
|
|
|
|
EnvAPIRequestsMax = "MINIO_API_REQUESTS_MAX"
|
|
|
|
EnvAPIRequestsDeadline = "MINIO_API_REQUESTS_DEADLINE"
|
|
|
|
EnvAPIClusterDeadline = "MINIO_API_CLUSTER_DEADLINE"
|
|
|
|
EnvAPICorsAllowOrigin = "MINIO_API_CORS_ALLOW_ORIGIN"
|
|
|
|
EnvAPIRemoteTransportDeadline = "MINIO_API_REMOTE_TRANSPORT_DEADLINE"
|
|
|
|
EnvAPIListQuorum = "MINIO_API_LIST_QUORUM"
|
|
|
|
EnvAPIExtendListCacheLife = "MINIO_API_EXTEND_LIST_CACHE_LIFE"
|
|
|
|
EnvAPISecureCiphers = "MINIO_API_SECURE_CIPHERS"
|
|
|
|
EnvAPIReplicationWorkers = "MINIO_API_REPLICATION_WORKERS"
|
|
|
|
EnvAPIReplicationFailedWorkers = "MINIO_API_REPLICATION_FAILED_WORKERS"
|
2020-04-14 15:46:37 -04:00
|
|
|
)
|
|
|
|
|
2020-09-23 12:14:33 -04:00
|
|
|
// Deprecated key and ENVs
|
|
|
|
const (
|
|
|
|
apiReadyDeadline = "ready_deadline"
|
|
|
|
EnvAPIReadyDeadline = "MINIO_API_READY_DEADLINE"
|
|
|
|
)
|
|
|
|
|
2020-04-14 15:46:37 -04:00
|
|
|
// DefaultKVS - default storage class config
|
|
|
|
var (
|
|
|
|
DefaultKVS = config.KVS{
|
|
|
|
config.KV{
|
|
|
|
Key: apiRequestsMax,
|
|
|
|
Value: "0",
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: apiRequestsDeadline,
|
|
|
|
Value: "10s",
|
|
|
|
},
|
2020-05-23 20:38:39 -04:00
|
|
|
config.KV{
|
2020-09-23 12:14:33 -04:00
|
|
|
Key: apiClusterDeadline,
|
2020-05-23 20:38:39 -04:00
|
|
|
Value: "10s",
|
|
|
|
},
|
2020-06-04 17:58:34 -04:00
|
|
|
config.KV{
|
|
|
|
Key: apiCorsAllowOrigin,
|
|
|
|
Value: "*",
|
|
|
|
},
|
2020-09-12 02:03:08 -04:00
|
|
|
config.KV{
|
|
|
|
Key: apiRemoteTransportDeadline,
|
|
|
|
Value: "2h",
|
|
|
|
},
|
2020-11-02 20:21:56 -05:00
|
|
|
config.KV{
|
|
|
|
Key: apiListQuorum,
|
2021-02-08 21:12:28 -05:00
|
|
|
Value: "strict",
|
2020-11-02 20:21:56 -05:00
|
|
|
},
|
2020-11-05 14:49:56 -05:00
|
|
|
config.KV{
|
|
|
|
Key: apiExtendListCacheLife,
|
|
|
|
Value: "0s",
|
|
|
|
},
|
2021-02-02 06:15:06 -05:00
|
|
|
config.KV{
|
|
|
|
Key: apiReplicationWorkers,
|
2021-04-03 12:03:42 -04:00
|
|
|
Value: "500",
|
2021-02-02 06:15:06 -05:00
|
|
|
},
|
2021-04-24 00:58:45 -04:00
|
|
|
config.KV{
|
|
|
|
Key: apiReplicationFailedWorkers,
|
|
|
|
Value: "4",
|
|
|
|
},
|
2020-04-14 15:46:37 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// Config storage class configuration
|
|
|
|
type Config struct {
|
2021-04-24 00:58:45 -04:00
|
|
|
RequestsMax int `json:"requests_max"`
|
|
|
|
RequestsDeadline time.Duration `json:"requests_deadline"`
|
|
|
|
ClusterDeadline time.Duration `json:"cluster_deadline"`
|
|
|
|
CorsAllowOrigin []string `json:"cors_allow_origin"`
|
|
|
|
RemoteTransportDeadline time.Duration `json:"remote_transport_deadline"`
|
|
|
|
ListQuorum string `json:"list_strict_quorum"`
|
|
|
|
ExtendListLife time.Duration `json:"extend_list_cache_life"`
|
|
|
|
ReplicationWorkers int `json:"replication_workers"`
|
|
|
|
ReplicationFailedWorkers int `json:"replication_failed_workers"`
|
2020-04-14 15:46:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalJSON - Validate SS and RRS parity when unmarshalling JSON.
|
|
|
|
func (sCfg *Config) UnmarshalJSON(data []byte) error {
|
|
|
|
type Alias Config
|
|
|
|
aux := &struct {
|
|
|
|
*Alias
|
|
|
|
}{
|
|
|
|
Alias: (*Alias)(sCfg),
|
|
|
|
}
|
|
|
|
return json.Unmarshal(data, &aux)
|
|
|
|
}
|
|
|
|
|
2020-11-02 20:21:56 -05:00
|
|
|
// GetListQuorum interprets list quorum values and returns appropriate
|
|
|
|
// acceptable quorum expected for list operations
|
|
|
|
func (sCfg Config) GetListQuorum() int {
|
|
|
|
switch sCfg.ListQuorum {
|
|
|
|
case "reduced":
|
|
|
|
return 2
|
|
|
|
case "disk":
|
|
|
|
// smallest possible value, generally meant for testing.
|
|
|
|
return 1
|
|
|
|
case "strict":
|
|
|
|
return -1
|
|
|
|
}
|
2020-12-23 12:26:40 -05:00
|
|
|
// Defaults to 3 drives per set, defaults to "optimal" value
|
2020-11-02 20:21:56 -05:00
|
|
|
return 3
|
|
|
|
}
|
|
|
|
|
2020-04-14 15:46:37 -04:00
|
|
|
// LookupConfig - lookup api config and override with valid environment settings if any.
|
|
|
|
func LookupConfig(kvs config.KVS) (cfg Config, err error) {
|
2020-09-23 12:14:33 -04:00
|
|
|
// remove this since we have removed this already.
|
|
|
|
kvs.Delete(apiReadyDeadline)
|
|
|
|
|
2020-04-14 15:46:37 -04:00
|
|
|
if err = config.CheckValidKeys(config.APISubSys, kvs, DefaultKVS); err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check environment variables parameters
|
2020-06-04 17:58:34 -04:00
|
|
|
requestsMax, err := strconv.Atoi(env.Get(EnvAPIRequestsMax, kvs.Get(apiRequestsMax)))
|
2020-04-14 15:46:37 -04:00
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if requestsMax < 0 {
|
|
|
|
return cfg, errors.New("invalid API max requests value")
|
|
|
|
}
|
|
|
|
|
2020-06-04 17:58:34 -04:00
|
|
|
requestsDeadline, err := time.ParseDuration(env.Get(EnvAPIRequestsDeadline, kvs.Get(apiRequestsDeadline)))
|
2020-04-14 15:46:37 -04:00
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
|
2020-09-23 12:14:33 -04:00
|
|
|
clusterDeadline, err := time.ParseDuration(env.Get(EnvAPIClusterDeadline, kvs.Get(apiClusterDeadline)))
|
2020-05-23 20:38:39 -04:00
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
|
2020-06-04 17:58:34 -04:00
|
|
|
corsAllowOrigin := strings.Split(env.Get(EnvAPICorsAllowOrigin, kvs.Get(apiCorsAllowOrigin)), ",")
|
2020-09-12 02:03:08 -04:00
|
|
|
|
|
|
|
remoteTransportDeadline, err := time.ParseDuration(env.Get(EnvAPIRemoteTransportDeadline, kvs.Get(apiRemoteTransportDeadline)))
|
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
|
2020-11-02 20:21:56 -05:00
|
|
|
listQuorum := env.Get(EnvAPIListQuorum, kvs.Get(apiListQuorum))
|
|
|
|
switch listQuorum {
|
|
|
|
case "strict", "optimal", "reduced", "disk":
|
|
|
|
default:
|
|
|
|
return cfg, errors.New("invalid value for list strict quorum")
|
|
|
|
}
|
|
|
|
|
2020-11-05 14:49:56 -05:00
|
|
|
listLife, err := time.ParseDuration(env.Get(EnvAPIExtendListCacheLife, kvs.Get(apiExtendListCacheLife)))
|
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
2021-02-08 21:12:28 -05:00
|
|
|
|
2021-02-02 06:15:06 -05:00
|
|
|
replicationWorkers, err := strconv.Atoi(env.Get(EnvAPIReplicationWorkers, kvs.Get(apiReplicationWorkers)))
|
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
2021-02-08 21:12:28 -05:00
|
|
|
|
2021-02-02 06:15:06 -05:00
|
|
|
if replicationWorkers <= 0 {
|
|
|
|
return cfg, config.ErrInvalidReplicationWorkersValue(nil).Msg("Minimum number of replication workers should be 1")
|
|
|
|
}
|
2021-02-08 21:12:28 -05:00
|
|
|
|
2021-04-24 00:58:45 -04:00
|
|
|
replicationFailedWorkers, err := strconv.Atoi(env.Get(EnvAPIReplicationFailedWorkers, kvs.Get(apiReplicationFailedWorkers)))
|
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if replicationFailedWorkers <= 0 {
|
|
|
|
return cfg, config.ErrInvalidReplicationWorkersValue(nil).Msg("Minimum number of replication failed workers should be 1")
|
|
|
|
}
|
|
|
|
|
2020-06-04 17:58:34 -04:00
|
|
|
return Config{
|
2021-04-24 00:58:45 -04:00
|
|
|
RequestsMax: requestsMax,
|
|
|
|
RequestsDeadline: requestsDeadline,
|
|
|
|
ClusterDeadline: clusterDeadline,
|
|
|
|
CorsAllowOrigin: corsAllowOrigin,
|
|
|
|
RemoteTransportDeadline: remoteTransportDeadline,
|
|
|
|
ListQuorum: listQuorum,
|
|
|
|
ExtendListLife: listLife,
|
|
|
|
ReplicationWorkers: replicationWorkers,
|
|
|
|
ReplicationFailedWorkers: replicationFailedWorkers,
|
2020-06-04 17:58:34 -04:00
|
|
|
}, nil
|
2020-04-14 15:46:37 -04:00
|
|
|
}
|