2020-07-12 23:00:47 +00:00
|
|
|
package legacy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/gorilla/mux"
|
2020-07-13 10:22:37 +00:00
|
|
|
"go.uber.org/zap"
|
2020-07-12 23:00:47 +00:00
|
|
|
)
|
|
|
|
|
2020-07-13 10:22:37 +00:00
|
|
|
func AttachS3API(r *mux.Router, obj ObjectLayer, l *zap.Logger) {
|
2020-07-13 11:23:23 +00:00
|
|
|
{ // should be removed in feature
|
|
|
|
// Initialize all help
|
|
|
|
initHelp()
|
|
|
|
|
|
|
|
globalGatewayName = "NeoFS GW"
|
|
|
|
|
|
|
|
// Set when gateway is enabled
|
|
|
|
globalIsGateway = true
|
|
|
|
|
|
|
|
// Handle gateway specific env
|
|
|
|
gatewayHandleEnvVars()
|
|
|
|
|
|
|
|
// Set system resources to maximum.
|
|
|
|
if err := setMaxResources(); err != nil {
|
|
|
|
l.Warn("could not set max resources",
|
|
|
|
zap.Error(err))
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: We need to move this code with globalConfigSys.Init()
|
|
|
|
// for now keep it here such that "s3" gateway layer initializes
|
|
|
|
// itself properly when KMS is set.
|
|
|
|
|
|
|
|
// Initialize server config.
|
|
|
|
srvCfg := newServerConfig()
|
|
|
|
|
|
|
|
// Override any values from ENVs.
|
|
|
|
lookupConfigs(srvCfg)
|
|
|
|
|
|
|
|
// hold the mutex lock before a new config is assigned.
|
|
|
|
globalServerConfigMu.Lock()
|
|
|
|
globalServerConfig = srvCfg
|
|
|
|
globalServerConfigMu.Unlock()
|
|
|
|
}
|
|
|
|
|
2020-07-12 23:00:47 +00:00
|
|
|
// Add healthcheck router
|
2020-07-13 09:51:21 +00:00
|
|
|
registerHealthCheckRouter(r)
|
2020-07-12 23:00:47 +00:00
|
|
|
|
|
|
|
// Add API router.
|
2020-07-13 09:51:21 +00:00
|
|
|
registerAPIRouter(r, true, true)
|
2020-07-12 23:00:47 +00:00
|
|
|
|
|
|
|
layer := NewGatewayLayerWithLocker(obj)
|
|
|
|
|
|
|
|
// Once endpoints are finalized, initialize the new object api in safe mode.
|
|
|
|
globalObjLayerMutex.Lock()
|
|
|
|
globalSafeMode = true
|
|
|
|
globalObjectAPI = layer
|
|
|
|
globalObjLayerMutex.Unlock()
|
|
|
|
|
|
|
|
// Calls all New() for all sub-systems.
|
|
|
|
newAllSubsystems()
|
|
|
|
|
|
|
|
// Verify if object layer supports
|
|
|
|
// - encryption
|
|
|
|
// - compression
|
|
|
|
verifyObjectLayerFeatures("gateway NeoFS", layer)
|
|
|
|
|
|
|
|
// Disable safe mode operation, after all initialization is over.
|
|
|
|
globalObjLayerMutex.Lock()
|
|
|
|
globalSafeMode = false
|
|
|
|
globalObjLayerMutex.Unlock()
|
|
|
|
}
|