mirror of
https://github.com/minio/minio.git
synced 2024-12-23 21:55:53 -05:00
Use constants for gateway names to avoid bugs caused by spelling. (#10355)
This commit is contained in:
parent
ea5094e842
commit
ea1803417f
@ -81,7 +81,7 @@ func (sys *BucketMetadataSys) Update(bucket string, configFile string, configDat
|
||||
// This code is needed only for gateway implementations.
|
||||
switch configFile {
|
||||
case bucketSSEConfig:
|
||||
if globalGatewayName == "nas" {
|
||||
if globalGatewayName == NASBackendGateway {
|
||||
meta, err := loadBucketMetadata(GlobalContext, objAPI, bucket)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -90,7 +90,7 @@ func (sys *BucketMetadataSys) Update(bucket string, configFile string, configDat
|
||||
return meta.Save(GlobalContext, objAPI)
|
||||
}
|
||||
case bucketLifecycleConfig:
|
||||
if globalGatewayName == "nas" {
|
||||
if globalGatewayName == NASBackendGateway {
|
||||
meta, err := loadBucketMetadata(GlobalContext, objAPI, bucket)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -99,7 +99,7 @@ func (sys *BucketMetadataSys) Update(bucket string, configFile string, configDat
|
||||
return meta.Save(GlobalContext, objAPI)
|
||||
}
|
||||
case bucketTaggingConfig:
|
||||
if globalGatewayName == "nas" {
|
||||
if globalGatewayName == NASBackendGateway {
|
||||
meta, err := loadBucketMetadata(GlobalContext, objAPI, bucket)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -108,7 +108,7 @@ func (sys *BucketMetadataSys) Update(bucket string, configFile string, configDat
|
||||
return meta.Save(GlobalContext, objAPI)
|
||||
}
|
||||
case bucketNotificationConfig:
|
||||
if globalGatewayName == "nas" {
|
||||
if globalGatewayName == NASBackendGateway {
|
||||
meta, err := loadBucketMetadata(GlobalContext, objAPI, bucket)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -273,7 +273,7 @@ func (sys *BucketMetadataSys) GetLifecycleConfig(bucket string) (*lifecycle.Life
|
||||
// GetNotificationConfig returns configured notification config
|
||||
// The returned object may not be modified.
|
||||
func (sys *BucketMetadataSys) GetNotificationConfig(bucket string) (*event.Config, error) {
|
||||
if globalIsGateway && globalGatewayName == "nas" {
|
||||
if globalIsGateway && globalGatewayName == NASBackendGateway {
|
||||
// Only needed in case of NAS gateway.
|
||||
objAPI := newObjectLayerWithoutSafeModeFn()
|
||||
if objAPI == nil {
|
||||
|
@ -21,7 +21,14 @@ import (
|
||||
)
|
||||
|
||||
// GatewayMinioSysTmp prefix is used in Azure/GCS gateway for save metadata sent by Initialize Multipart Upload API.
|
||||
const GatewayMinioSysTmp = "minio.sys.tmp/"
|
||||
const (
|
||||
GatewayMinioSysTmp = "minio.sys.tmp/"
|
||||
AzureBackendGateway = "azure"
|
||||
GCSBackendGateway = "gcs"
|
||||
HDFSBackendGateway = "hdfs"
|
||||
NASBackendGateway = "nas"
|
||||
S3BackendGateway = "s3"
|
||||
)
|
||||
|
||||
// Gateway represents a gateway backend.
|
||||
type Gateway interface {
|
||||
|
@ -262,8 +262,8 @@ func StartGateway(ctx *cli.Context, gw Gateway) {
|
||||
}
|
||||
|
||||
// Currently only NAS and S3 gateway support encryption headers.
|
||||
encryptionEnabled := gatewayName == "s3" || gatewayName == "nas"
|
||||
allowSSEKMS := gatewayName == "s3" // Only S3 can support SSE-KMS (as pass-through)
|
||||
encryptionEnabled := gatewayName == S3BackendGateway || gatewayName == NASBackendGateway
|
||||
allowSSEKMS := gatewayName == S3BackendGateway // Only S3 can support SSE-KMS (as pass-through)
|
||||
|
||||
// Add API router.
|
||||
registerAPIRouter(router, encryptionEnabled, allowSSEKMS)
|
||||
@ -310,7 +310,7 @@ func StartGateway(ctx *cli.Context, gw Gateway) {
|
||||
// Calls all New() for all sub-systems.
|
||||
newAllSubsystems()
|
||||
|
||||
if gatewayName == "nas" {
|
||||
if gatewayName == NASBackendGateway {
|
||||
buckets, err := newObject.ListBuckets(GlobalContext)
|
||||
if err != nil {
|
||||
logger.Fatal(err, "Unable to list buckets")
|
||||
|
@ -73,7 +73,6 @@ const (
|
||||
azureBlockSize = 100 * humanize.MiByte
|
||||
azureS3MinPartSize = 5 * humanize.MiByte
|
||||
metadataObjectNameTemplate = minio.GatewayMinioSysTmp + "multipart/v1/%s.%x/azure.json"
|
||||
azureBackend = "azure"
|
||||
azureMarkerPrefix = "{minio}"
|
||||
metadataPartNamePrefix = minio.GatewayMinioSysTmp + "multipart/v1/%s.%x"
|
||||
maxPartsCount = 10000
|
||||
@ -113,7 +112,7 @@ EXAMPLES:
|
||||
`
|
||||
|
||||
minio.RegisterGatewayCommand(cli.Command{
|
||||
Name: azureBackend,
|
||||
Name: minio.AzureBackendGateway,
|
||||
Usage: "Microsoft Azure Blob Storage",
|
||||
Action: azureGatewayMain,
|
||||
CustomHelpTemplate: azureGatewayTemplate,
|
||||
@ -170,7 +169,7 @@ type Azure struct {
|
||||
|
||||
// Name implements Gateway interface.
|
||||
func (g *Azure) Name() string {
|
||||
return azureBackend
|
||||
return minio.AzureBackendGateway
|
||||
}
|
||||
|
||||
// NewGatewayLayer initializes azure blob storage client and returns AzureObjects.
|
||||
|
@ -91,8 +91,6 @@ const (
|
||||
|
||||
// Project ID key in credentials.json
|
||||
gcsProjectIDKey = "project_id"
|
||||
|
||||
gcsBackend = "gcs"
|
||||
)
|
||||
|
||||
func init() {
|
||||
@ -132,7 +130,7 @@ EXAMPLES:
|
||||
`
|
||||
|
||||
minio.RegisterGatewayCommand(cli.Command{
|
||||
Name: gcsBackend,
|
||||
Name: minio.GCSBackendGateway,
|
||||
Usage: "Google Cloud Storage",
|
||||
Action: gcsGatewayMain,
|
||||
CustomHelpTemplate: gcsGatewayTemplate,
|
||||
@ -145,13 +143,13 @@ func gcsGatewayMain(ctx *cli.Context) {
|
||||
projectID := ctx.Args().First()
|
||||
if projectID == "" && os.Getenv("GOOGLE_APPLICATION_CREDENTIALS") == "" {
|
||||
logger.LogIf(minio.GlobalContext, errGCSProjectIDNotFound, logger.Application)
|
||||
cli.ShowCommandHelpAndExit(ctx, "gcs", 1)
|
||||
cli.ShowCommandHelpAndExit(ctx, minio.GCSBackendGateway, 1)
|
||||
}
|
||||
if projectID != "" && !isValidGCSProjectIDFormat(projectID) {
|
||||
reqInfo := (&logger.ReqInfo{}).AppendTags("projectID", ctx.Args().First())
|
||||
contxt := logger.SetReqInfo(minio.GlobalContext, reqInfo)
|
||||
logger.LogIf(contxt, errGCSInvalidProjectID, logger.Application)
|
||||
cli.ShowCommandHelpAndExit(ctx, "gcs", 1)
|
||||
cli.ShowCommandHelpAndExit(ctx, minio.GCSBackendGateway, 1)
|
||||
}
|
||||
|
||||
minio.StartGateway(ctx, &GCS{projectID})
|
||||
@ -164,7 +162,7 @@ type GCS struct {
|
||||
|
||||
// Name returns the name of gcs ObjectLayer.
|
||||
func (g *GCS) Name() string {
|
||||
return gcsBackend
|
||||
return minio.GCSBackendGateway
|
||||
}
|
||||
|
||||
// NewGatewayLayer returns gcs ObjectLayer.
|
||||
|
@ -47,8 +47,6 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
hdfsBackend = "hdfs"
|
||||
|
||||
hdfsSeparator = minio.SlashSeparator
|
||||
)
|
||||
|
||||
@ -84,7 +82,7 @@ EXAMPLES:
|
||||
`
|
||||
|
||||
minio.RegisterGatewayCommand(cli.Command{
|
||||
Name: hdfsBackend,
|
||||
Name: minio.HDFSBackendGateway,
|
||||
Usage: "Hadoop Distributed File System (HDFS)",
|
||||
Action: hdfsGatewayMain,
|
||||
CustomHelpTemplate: hdfsGatewayTemplate,
|
||||
@ -96,7 +94,7 @@ EXAMPLES:
|
||||
func hdfsGatewayMain(ctx *cli.Context) {
|
||||
// Validate gateway arguments.
|
||||
if ctx.Args().First() == "help" {
|
||||
cli.ShowCommandHelpAndExit(ctx, hdfsBackend, 1)
|
||||
cli.ShowCommandHelpAndExit(ctx, minio.HDFSBackendGateway, 1)
|
||||
}
|
||||
|
||||
minio.StartGateway(ctx, &HDFS{args: ctx.Args()})
|
||||
@ -109,7 +107,7 @@ type HDFS struct {
|
||||
|
||||
// Name implements Gateway interface.
|
||||
func (g *HDFS) Name() string {
|
||||
return hdfsBackend
|
||||
return minio.HDFSBackendGateway
|
||||
}
|
||||
|
||||
func getKerberosClient() (*krb.Client, error) {
|
||||
|
@ -24,10 +24,6 @@ import (
|
||||
"github.com/minio/minio/pkg/auth"
|
||||
)
|
||||
|
||||
const (
|
||||
nasBackend = "nas"
|
||||
)
|
||||
|
||||
func init() {
|
||||
const nasGatewayTemplate = `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
@ -61,7 +57,7 @@ EXAMPLES:
|
||||
`
|
||||
|
||||
minio.RegisterGatewayCommand(cli.Command{
|
||||
Name: nasBackend,
|
||||
Name: minio.NASBackendGateway,
|
||||
Usage: "Network-attached storage (NAS)",
|
||||
Action: nasGatewayMain,
|
||||
CustomHelpTemplate: nasGatewayTemplate,
|
||||
@ -73,7 +69,7 @@ EXAMPLES:
|
||||
func nasGatewayMain(ctx *cli.Context) {
|
||||
// Validate gateway arguments.
|
||||
if !ctx.Args().Present() || ctx.Args().First() == "help" {
|
||||
cli.ShowCommandHelpAndExit(ctx, nasBackend, 1)
|
||||
cli.ShowCommandHelpAndExit(ctx, minio.NASBackendGateway, 1)
|
||||
}
|
||||
|
||||
minio.StartGateway(ctx, &NAS{ctx.Args().First()})
|
||||
@ -86,7 +82,7 @@ type NAS struct {
|
||||
|
||||
// Name implements Gateway interface.
|
||||
func (g *NAS) Name() string {
|
||||
return nasBackend
|
||||
return minio.NASBackendGateway
|
||||
}
|
||||
|
||||
// NewGatewayLayer returns nas gatewaylayer.
|
||||
|
@ -40,10 +40,6 @@ import (
|
||||
"github.com/minio/minio/pkg/bucket/policy"
|
||||
)
|
||||
|
||||
const (
|
||||
s3Backend = "s3"
|
||||
)
|
||||
|
||||
func init() {
|
||||
const s3GatewayTemplate = `NAME:
|
||||
{{.HelpName}} - {{.Usage}}
|
||||
@ -76,7 +72,7 @@ EXAMPLES:
|
||||
`
|
||||
|
||||
minio.RegisterGatewayCommand(cli.Command{
|
||||
Name: s3Backend,
|
||||
Name: minio.S3BackendGateway,
|
||||
Usage: "Amazon Simple Storage Service (S3)",
|
||||
Action: s3GatewayMain,
|
||||
CustomHelpTemplate: s3GatewayTemplate,
|
||||
@ -109,7 +105,7 @@ type S3 struct {
|
||||
|
||||
// Name implements Gateway interface.
|
||||
func (g *S3) Name() string {
|
||||
return s3Backend
|
||||
return minio.S3BackendGateway
|
||||
}
|
||||
|
||||
const letterBytes = "abcdefghijklmnopqrstuvwxyz01234569"
|
||||
|
@ -157,7 +157,7 @@ func healingMetricsPrometheus(ch chan<- prometheus.Metric) {
|
||||
// collects gateway specific metrics for MinIO instance in Prometheus specific format
|
||||
// and sends to given channel
|
||||
func gatewayMetricsPrometheus(ch chan<- prometheus.Metric) {
|
||||
if !globalIsGateway || (globalGatewayName != "s3" && globalGatewayName != "azure" && globalGatewayName != "gcs") {
|
||||
if !globalIsGateway || (globalGatewayName != S3BackendGateway && globalGatewayName != AzureBackendGateway && globalGatewayName != GCSBackendGateway) {
|
||||
return
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user