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"
|
2021-08-12 01:23:56 -04:00
|
|
|
"runtime"
|
2020-04-14 15:46:37 -04:00
|
|
|
"strconv"
|
2020-06-04 17:58:34 -04:00
|
|
|
"strings"
|
2020-04-14 15:46:37 -04:00
|
|
|
"time"
|
|
|
|
|
2021-06-01 17:59:40 -04:00
|
|
|
"github.com/minio/minio/internal/config"
|
2021-05-28 18:17:01 -04:00
|
|
|
"github.com/minio/pkg/env"
|
2020-04-14 15:46:37 -04:00
|
|
|
)
|
|
|
|
|
2020-06-04 17:58:34 -04:00
|
|
|
// API sub-system constants
|
2020-04-14 15:46:37 -04:00
|
|
|
const (
|
2021-10-04 13:52:28 -04:00
|
|
|
apiRequestsMax = "requests_max"
|
|
|
|
apiRequestsDeadline = "requests_deadline"
|
|
|
|
apiClusterDeadline = "cluster_deadline"
|
|
|
|
apiCorsAllowOrigin = "cors_allow_origin"
|
|
|
|
apiRemoteTransportDeadline = "remote_transport_deadline"
|
|
|
|
apiListQuorum = "list_quorum"
|
|
|
|
apiReplicationWorkers = "replication_workers"
|
|
|
|
apiReplicationFailedWorkers = "replication_failed_workers"
|
|
|
|
apiTransitionWorkers = "transition_workers"
|
|
|
|
apiStaleUploadsCleanupInterval = "stale_uploads_cleanup_interval"
|
|
|
|
apiStaleUploadsExpiry = "stale_uploads_expiry"
|
|
|
|
apiDeleteCleanupInterval = "delete_cleanup_interval"
|
2022-01-17 11:34:14 -05:00
|
|
|
apiDisableODirect = "disable_odirect"
|
2022-02-14 12:19:01 -05:00
|
|
|
apiGzipObjects = "gzip_objects"
|
2021-04-24 00:58:45 -04:00
|
|
|
|
|
|
|
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"
|
2021-10-08 15:40:34 -04:00
|
|
|
EnvAPISecureCiphers = "MINIO_API_SECURE_CIPHERS" // default "on"
|
2021-04-24 00:58:45 -04:00
|
|
|
EnvAPIReplicationWorkers = "MINIO_API_REPLICATION_WORKERS"
|
|
|
|
EnvAPIReplicationFailedWorkers = "MINIO_API_REPLICATION_FAILED_WORKERS"
|
2021-08-12 01:23:56 -04:00
|
|
|
EnvAPITransitionWorkers = "MINIO_API_TRANSITION_WORKERS"
|
2021-10-04 13:52:28 -04:00
|
|
|
|
|
|
|
EnvAPIStaleUploadsCleanupInterval = "MINIO_API_STALE_UPLOADS_CLEANUP_INTERVAL"
|
|
|
|
EnvAPIStaleUploadsExpiry = "MINIO_API_STALE_UPLOADS_EXPIRY"
|
|
|
|
EnvAPIDeleteCleanupInterval = "MINIO_API_DELETE_CLEANUP_INTERVAL"
|
|
|
|
EnvDeleteCleanupInterval = "MINIO_DELETE_CLEANUP_INTERVAL"
|
2022-01-17 11:34:14 -05:00
|
|
|
EnvAPIDisableODirect = "MINIO_API_DISABLE_ODIRECT"
|
2022-02-14 12:19:01 -05:00
|
|
|
EnvAPIGzipObjects = "MINIO_API_GZIP_OBJECTS"
|
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-09-02 20:45:30 -04:00
|
|
|
Value: "strict",
|
2020-11-02 20:21:56 -05:00
|
|
|
},
|
2021-02-02 06:15:06 -05:00
|
|
|
config.KV{
|
|
|
|
Key: apiReplicationWorkers,
|
2021-05-26 14:55:46 -04:00
|
|
|
Value: "250",
|
2021-02-02 06:15:06 -05:00
|
|
|
},
|
2021-04-24 00:58:45 -04:00
|
|
|
config.KV{
|
|
|
|
Key: apiReplicationFailedWorkers,
|
2021-05-26 14:55:46 -04:00
|
|
|
Value: "8",
|
2021-04-24 00:58:45 -04:00
|
|
|
},
|
2021-08-12 01:23:56 -04:00
|
|
|
config.KV{
|
|
|
|
Key: apiTransitionWorkers,
|
|
|
|
Value: "100",
|
|
|
|
},
|
2021-10-04 13:52:28 -04:00
|
|
|
config.KV{
|
|
|
|
Key: apiStaleUploadsCleanupInterval,
|
|
|
|
Value: "6h",
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: apiStaleUploadsExpiry,
|
|
|
|
Value: "24h",
|
|
|
|
},
|
|
|
|
config.KV{
|
|
|
|
Key: apiDeleteCleanupInterval,
|
|
|
|
Value: "5m",
|
|
|
|
},
|
2022-01-17 11:34:14 -05:00
|
|
|
config.KV{
|
|
|
|
Key: apiDisableODirect,
|
|
|
|
Value: "off",
|
|
|
|
},
|
2022-02-14 12:19:01 -05:00
|
|
|
config.KV{
|
|
|
|
Key: apiGzipObjects,
|
|
|
|
Value: "off",
|
|
|
|
},
|
2020-04-14 15:46:37 -04:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// Config storage class configuration
|
|
|
|
type Config struct {
|
2021-10-04 13:52:28 -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_quorum"`
|
|
|
|
ReplicationWorkers int `json:"replication_workers"`
|
|
|
|
ReplicationFailedWorkers int `json:"replication_failed_workers"`
|
|
|
|
TransitionWorkers int `json:"transition_workers"`
|
|
|
|
StaleUploadsCleanupInterval time.Duration `json:"stale_uploads_cleanup_interval"`
|
|
|
|
StaleUploadsExpiry time.Duration `json:"stale_uploads_expiry"`
|
|
|
|
DeleteCleanupInterval time.Duration `json:"delete_cleanup_interval"`
|
2022-01-17 11:34:14 -05:00
|
|
|
DisableODirect bool `json:"disable_odirect"`
|
2022-02-14 12:19:01 -05:00
|
|
|
GzipObjects bool `json:"gzip_objects"`
|
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)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
2021-07-05 18:34:41 -04:00
|
|
|
kvs.Delete("extend_list_cache_life")
|
2020-09-23 12:14:33 -04:00
|
|
|
|
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
|
2022-02-21 18:50:45 -05:00
|
|
|
requestsMax, err := strconv.Atoi(env.Get(EnvAPIRequestsMax, kvs.GetWithDefault(apiRequestsMax, DefaultKVS)))
|
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")
|
|
|
|
}
|
|
|
|
|
2022-02-21 18:50:45 -05:00
|
|
|
requestsDeadline, err := time.ParseDuration(env.Get(EnvAPIRequestsDeadline, kvs.GetWithDefault(apiRequestsDeadline, DefaultKVS)))
|
2020-04-14 15:46:37 -04:00
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
|
2022-02-21 18:50:45 -05:00
|
|
|
clusterDeadline, err := time.ParseDuration(env.Get(EnvAPIClusterDeadline, kvs.GetWithDefault(apiClusterDeadline, DefaultKVS)))
|
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
|
|
|
|
2022-02-21 18:50:45 -05:00
|
|
|
remoteTransportDeadline, err := time.ParseDuration(env.Get(EnvAPIRemoteTransportDeadline, kvs.GetWithDefault(apiRemoteTransportDeadline, DefaultKVS)))
|
2020-09-12 02:03:08 -04:00
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
|
2022-02-21 18:50:45 -05:00
|
|
|
listQuorum := env.Get(EnvAPIListQuorum, kvs.GetWithDefault(apiListQuorum, DefaultKVS))
|
2020-11-02 20:21:56 -05:00
|
|
|
switch listQuorum {
|
|
|
|
case "strict", "optimal", "reduced", "disk":
|
|
|
|
default:
|
|
|
|
return cfg, errors.New("invalid value for list strict quorum")
|
|
|
|
}
|
|
|
|
|
2022-02-21 18:50:45 -05:00
|
|
|
replicationWorkers, err := strconv.Atoi(env.Get(EnvAPIReplicationWorkers, kvs.GetWithDefault(apiReplicationWorkers, DefaultKVS)))
|
2021-02-02 06:15:06 -05:00
|
|
|
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
|
|
|
|
2022-02-21 18:50:45 -05:00
|
|
|
replicationFailedWorkers, err := strconv.Atoi(env.Get(EnvAPIReplicationFailedWorkers, kvs.GetWithDefault(apiReplicationFailedWorkers, DefaultKVS)))
|
2021-04-24 00:58:45 -04:00
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if replicationFailedWorkers <= 0 {
|
|
|
|
return cfg, config.ErrInvalidReplicationWorkersValue(nil).Msg("Minimum number of replication failed workers should be 1")
|
|
|
|
}
|
|
|
|
|
2022-02-21 18:50:45 -05:00
|
|
|
transitionWorkers, err := strconv.Atoi(env.Get(EnvAPITransitionWorkers, kvs.GetWithDefault(apiTransitionWorkers, DefaultKVS)))
|
2021-08-12 01:23:56 -04:00
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
if transitionWorkers < runtime.GOMAXPROCS(0)/2 {
|
|
|
|
return cfg, config.ErrInvalidTransitionWorkersValue(nil)
|
|
|
|
}
|
|
|
|
|
2021-10-04 13:52:28 -04:00
|
|
|
v := env.Get(EnvAPIDeleteCleanupInterval, kvs.Get(apiDeleteCleanupInterval))
|
|
|
|
if v == "" {
|
2022-02-21 18:50:45 -05:00
|
|
|
v = env.Get(EnvDeleteCleanupInterval, kvs.GetWithDefault(apiDeleteCleanupInterval, DefaultKVS))
|
2021-10-04 13:52:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
deleteCleanupInterval, err := time.ParseDuration(v)
|
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
|
2022-02-21 18:50:45 -05:00
|
|
|
staleUploadsCleanupInterval, err := time.ParseDuration(env.Get(EnvAPIStaleUploadsCleanupInterval, kvs.GetWithDefault(apiStaleUploadsCleanupInterval, DefaultKVS)))
|
2021-10-04 13:52:28 -04:00
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
|
2022-02-21 18:50:45 -05:00
|
|
|
staleUploadsExpiry, err := time.ParseDuration(env.Get(EnvAPIStaleUploadsExpiry, kvs.GetWithDefault(apiStaleUploadsExpiry, DefaultKVS)))
|
2021-10-04 13:52:28 -04:00
|
|
|
if err != nil {
|
|
|
|
return cfg, err
|
|
|
|
}
|
|
|
|
|
2022-01-17 11:34:14 -05:00
|
|
|
disableODirect := env.Get(EnvAPIDisableODirect, kvs.Get(apiDisableODirect)) == config.EnableOn
|
|
|
|
|
2022-02-14 12:19:01 -05:00
|
|
|
gzipObjects := env.Get(EnvAPIGzipObjects, kvs.Get(apiGzipObjects)) == config.EnableOn
|
|
|
|
|
2020-06-04 17:58:34 -04:00
|
|
|
return Config{
|
2021-10-04 13:52:28 -04:00
|
|
|
RequestsMax: requestsMax,
|
|
|
|
RequestsDeadline: requestsDeadline,
|
|
|
|
ClusterDeadline: clusterDeadline,
|
|
|
|
CorsAllowOrigin: corsAllowOrigin,
|
|
|
|
RemoteTransportDeadline: remoteTransportDeadline,
|
|
|
|
ListQuorum: listQuorum,
|
|
|
|
ReplicationWorkers: replicationWorkers,
|
|
|
|
ReplicationFailedWorkers: replicationFailedWorkers,
|
|
|
|
TransitionWorkers: transitionWorkers,
|
|
|
|
StaleUploadsCleanupInterval: staleUploadsCleanupInterval,
|
|
|
|
StaleUploadsExpiry: staleUploadsExpiry,
|
|
|
|
DeleteCleanupInterval: deleteCleanupInterval,
|
2022-01-17 11:34:14 -05:00
|
|
|
DisableODirect: disableODirect,
|
2022-02-14 12:19:01 -05:00
|
|
|
GzipObjects: gzipObjects,
|
2020-06-04 17:58:34 -04:00
|
|
|
}, nil
|
2020-04-14 15:46:37 -04:00
|
|
|
}
|