Use constants for gateway names to avoid bugs caused by spelling. (#10355)

This commit is contained in:
飞雪无情 2020-08-26 23:52:46 +08:00 committed by GitHub
parent ea5094e842
commit ea1803417f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 31 additions and 37 deletions

View File

@ -81,7 +81,7 @@ func (sys *BucketMetadataSys) Update(bucket string, configFile string, configDat
// This code is needed only for gateway implementations. // This code is needed only for gateway implementations.
switch configFile { switch configFile {
case bucketSSEConfig: case bucketSSEConfig:
if globalGatewayName == "nas" { if globalGatewayName == NASBackendGateway {
meta, err := loadBucketMetadata(GlobalContext, objAPI, bucket) meta, err := loadBucketMetadata(GlobalContext, objAPI, bucket)
if err != nil { if err != nil {
return err return err
@ -90,7 +90,7 @@ func (sys *BucketMetadataSys) Update(bucket string, configFile string, configDat
return meta.Save(GlobalContext, objAPI) return meta.Save(GlobalContext, objAPI)
} }
case bucketLifecycleConfig: case bucketLifecycleConfig:
if globalGatewayName == "nas" { if globalGatewayName == NASBackendGateway {
meta, err := loadBucketMetadata(GlobalContext, objAPI, bucket) meta, err := loadBucketMetadata(GlobalContext, objAPI, bucket)
if err != nil { if err != nil {
return err return err
@ -99,7 +99,7 @@ func (sys *BucketMetadataSys) Update(bucket string, configFile string, configDat
return meta.Save(GlobalContext, objAPI) return meta.Save(GlobalContext, objAPI)
} }
case bucketTaggingConfig: case bucketTaggingConfig:
if globalGatewayName == "nas" { if globalGatewayName == NASBackendGateway {
meta, err := loadBucketMetadata(GlobalContext, objAPI, bucket) meta, err := loadBucketMetadata(GlobalContext, objAPI, bucket)
if err != nil { if err != nil {
return err return err
@ -108,7 +108,7 @@ func (sys *BucketMetadataSys) Update(bucket string, configFile string, configDat
return meta.Save(GlobalContext, objAPI) return meta.Save(GlobalContext, objAPI)
} }
case bucketNotificationConfig: case bucketNotificationConfig:
if globalGatewayName == "nas" { if globalGatewayName == NASBackendGateway {
meta, err := loadBucketMetadata(GlobalContext, objAPI, bucket) meta, err := loadBucketMetadata(GlobalContext, objAPI, bucket)
if err != nil { if err != nil {
return err return err
@ -273,7 +273,7 @@ func (sys *BucketMetadataSys) GetLifecycleConfig(bucket string) (*lifecycle.Life
// GetNotificationConfig returns configured notification config // GetNotificationConfig returns configured notification config
// The returned object may not be modified. // The returned object may not be modified.
func (sys *BucketMetadataSys) GetNotificationConfig(bucket string) (*event.Config, error) { func (sys *BucketMetadataSys) GetNotificationConfig(bucket string) (*event.Config, error) {
if globalIsGateway && globalGatewayName == "nas" { if globalIsGateway && globalGatewayName == NASBackendGateway {
// Only needed in case of NAS gateway. // Only needed in case of NAS gateway.
objAPI := newObjectLayerWithoutSafeModeFn() objAPI := newObjectLayerWithoutSafeModeFn()
if objAPI == nil { if objAPI == nil {

View File

@ -21,7 +21,14 @@ import (
) )
// GatewayMinioSysTmp prefix is used in Azure/GCS gateway for save metadata sent by Initialize Multipart Upload API. // 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. // Gateway represents a gateway backend.
type Gateway interface { type Gateway interface {

View File

@ -262,8 +262,8 @@ func StartGateway(ctx *cli.Context, gw Gateway) {
} }
// Currently only NAS and S3 gateway support encryption headers. // Currently only NAS and S3 gateway support encryption headers.
encryptionEnabled := gatewayName == "s3" || gatewayName == "nas" encryptionEnabled := gatewayName == S3BackendGateway || gatewayName == NASBackendGateway
allowSSEKMS := gatewayName == "s3" // Only S3 can support SSE-KMS (as pass-through) allowSSEKMS := gatewayName == S3BackendGateway // Only S3 can support SSE-KMS (as pass-through)
// Add API router. // Add API router.
registerAPIRouter(router, encryptionEnabled, allowSSEKMS) registerAPIRouter(router, encryptionEnabled, allowSSEKMS)
@ -310,7 +310,7 @@ func StartGateway(ctx *cli.Context, gw Gateway) {
// Calls all New() for all sub-systems. // Calls all New() for all sub-systems.
newAllSubsystems() newAllSubsystems()
if gatewayName == "nas" { if gatewayName == NASBackendGateway {
buckets, err := newObject.ListBuckets(GlobalContext) buckets, err := newObject.ListBuckets(GlobalContext)
if err != nil { if err != nil {
logger.Fatal(err, "Unable to list buckets") logger.Fatal(err, "Unable to list buckets")

View File

@ -73,7 +73,6 @@ const (
azureBlockSize = 100 * humanize.MiByte azureBlockSize = 100 * humanize.MiByte
azureS3MinPartSize = 5 * humanize.MiByte azureS3MinPartSize = 5 * humanize.MiByte
metadataObjectNameTemplate = minio.GatewayMinioSysTmp + "multipart/v1/%s.%x/azure.json" metadataObjectNameTemplate = minio.GatewayMinioSysTmp + "multipart/v1/%s.%x/azure.json"
azureBackend = "azure"
azureMarkerPrefix = "{minio}" azureMarkerPrefix = "{minio}"
metadataPartNamePrefix = minio.GatewayMinioSysTmp + "multipart/v1/%s.%x" metadataPartNamePrefix = minio.GatewayMinioSysTmp + "multipart/v1/%s.%x"
maxPartsCount = 10000 maxPartsCount = 10000
@ -113,7 +112,7 @@ EXAMPLES:
` `
minio.RegisterGatewayCommand(cli.Command{ minio.RegisterGatewayCommand(cli.Command{
Name: azureBackend, Name: minio.AzureBackendGateway,
Usage: "Microsoft Azure Blob Storage", Usage: "Microsoft Azure Blob Storage",
Action: azureGatewayMain, Action: azureGatewayMain,
CustomHelpTemplate: azureGatewayTemplate, CustomHelpTemplate: azureGatewayTemplate,
@ -170,7 +169,7 @@ type Azure struct {
// Name implements Gateway interface. // Name implements Gateway interface.
func (g *Azure) Name() string { func (g *Azure) Name() string {
return azureBackend return minio.AzureBackendGateway
} }
// NewGatewayLayer initializes azure blob storage client and returns AzureObjects. // NewGatewayLayer initializes azure blob storage client and returns AzureObjects.

View File

@ -91,8 +91,6 @@ const (
// Project ID key in credentials.json // Project ID key in credentials.json
gcsProjectIDKey = "project_id" gcsProjectIDKey = "project_id"
gcsBackend = "gcs"
) )
func init() { func init() {
@ -132,7 +130,7 @@ EXAMPLES:
` `
minio.RegisterGatewayCommand(cli.Command{ minio.RegisterGatewayCommand(cli.Command{
Name: gcsBackend, Name: minio.GCSBackendGateway,
Usage: "Google Cloud Storage", Usage: "Google Cloud Storage",
Action: gcsGatewayMain, Action: gcsGatewayMain,
CustomHelpTemplate: gcsGatewayTemplate, CustomHelpTemplate: gcsGatewayTemplate,
@ -145,13 +143,13 @@ func gcsGatewayMain(ctx *cli.Context) {
projectID := ctx.Args().First() projectID := ctx.Args().First()
if projectID == "" && os.Getenv("GOOGLE_APPLICATION_CREDENTIALS") == "" { if projectID == "" && os.Getenv("GOOGLE_APPLICATION_CREDENTIALS") == "" {
logger.LogIf(minio.GlobalContext, errGCSProjectIDNotFound, logger.Application) logger.LogIf(minio.GlobalContext, errGCSProjectIDNotFound, logger.Application)
cli.ShowCommandHelpAndExit(ctx, "gcs", 1) cli.ShowCommandHelpAndExit(ctx, minio.GCSBackendGateway, 1)
} }
if projectID != "" && !isValidGCSProjectIDFormat(projectID) { if projectID != "" && !isValidGCSProjectIDFormat(projectID) {
reqInfo := (&logger.ReqInfo{}).AppendTags("projectID", ctx.Args().First()) reqInfo := (&logger.ReqInfo{}).AppendTags("projectID", ctx.Args().First())
contxt := logger.SetReqInfo(minio.GlobalContext, reqInfo) contxt := logger.SetReqInfo(minio.GlobalContext, reqInfo)
logger.LogIf(contxt, errGCSInvalidProjectID, logger.Application) logger.LogIf(contxt, errGCSInvalidProjectID, logger.Application)
cli.ShowCommandHelpAndExit(ctx, "gcs", 1) cli.ShowCommandHelpAndExit(ctx, minio.GCSBackendGateway, 1)
} }
minio.StartGateway(ctx, &GCS{projectID}) minio.StartGateway(ctx, &GCS{projectID})
@ -164,7 +162,7 @@ type GCS struct {
// Name returns the name of gcs ObjectLayer. // Name returns the name of gcs ObjectLayer.
func (g *GCS) Name() string { func (g *GCS) Name() string {
return gcsBackend return minio.GCSBackendGateway
} }
// NewGatewayLayer returns gcs ObjectLayer. // NewGatewayLayer returns gcs ObjectLayer.

View File

@ -47,8 +47,6 @@ import (
) )
const ( const (
hdfsBackend = "hdfs"
hdfsSeparator = minio.SlashSeparator hdfsSeparator = minio.SlashSeparator
) )
@ -84,7 +82,7 @@ EXAMPLES:
` `
minio.RegisterGatewayCommand(cli.Command{ minio.RegisterGatewayCommand(cli.Command{
Name: hdfsBackend, Name: minio.HDFSBackendGateway,
Usage: "Hadoop Distributed File System (HDFS)", Usage: "Hadoop Distributed File System (HDFS)",
Action: hdfsGatewayMain, Action: hdfsGatewayMain,
CustomHelpTemplate: hdfsGatewayTemplate, CustomHelpTemplate: hdfsGatewayTemplate,
@ -96,7 +94,7 @@ EXAMPLES:
func hdfsGatewayMain(ctx *cli.Context) { func hdfsGatewayMain(ctx *cli.Context) {
// Validate gateway arguments. // Validate gateway arguments.
if ctx.Args().First() == "help" { if ctx.Args().First() == "help" {
cli.ShowCommandHelpAndExit(ctx, hdfsBackend, 1) cli.ShowCommandHelpAndExit(ctx, minio.HDFSBackendGateway, 1)
} }
minio.StartGateway(ctx, &HDFS{args: ctx.Args()}) minio.StartGateway(ctx, &HDFS{args: ctx.Args()})
@ -109,7 +107,7 @@ type HDFS struct {
// Name implements Gateway interface. // Name implements Gateway interface.
func (g *HDFS) Name() string { func (g *HDFS) Name() string {
return hdfsBackend return minio.HDFSBackendGateway
} }
func getKerberosClient() (*krb.Client, error) { func getKerberosClient() (*krb.Client, error) {

View File

@ -24,10 +24,6 @@ import (
"github.com/minio/minio/pkg/auth" "github.com/minio/minio/pkg/auth"
) )
const (
nasBackend = "nas"
)
func init() { func init() {
const nasGatewayTemplate = `NAME: const nasGatewayTemplate = `NAME:
{{.HelpName}} - {{.Usage}} {{.HelpName}} - {{.Usage}}
@ -61,7 +57,7 @@ EXAMPLES:
` `
minio.RegisterGatewayCommand(cli.Command{ minio.RegisterGatewayCommand(cli.Command{
Name: nasBackend, Name: minio.NASBackendGateway,
Usage: "Network-attached storage (NAS)", Usage: "Network-attached storage (NAS)",
Action: nasGatewayMain, Action: nasGatewayMain,
CustomHelpTemplate: nasGatewayTemplate, CustomHelpTemplate: nasGatewayTemplate,
@ -73,7 +69,7 @@ EXAMPLES:
func nasGatewayMain(ctx *cli.Context) { func nasGatewayMain(ctx *cli.Context) {
// Validate gateway arguments. // Validate gateway arguments.
if !ctx.Args().Present() || ctx.Args().First() == "help" { 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()}) minio.StartGateway(ctx, &NAS{ctx.Args().First()})
@ -86,7 +82,7 @@ type NAS struct {
// Name implements Gateway interface. // Name implements Gateway interface.
func (g *NAS) Name() string { func (g *NAS) Name() string {
return nasBackend return minio.NASBackendGateway
} }
// NewGatewayLayer returns nas gatewaylayer. // NewGatewayLayer returns nas gatewaylayer.

View File

@ -40,10 +40,6 @@ import (
"github.com/minio/minio/pkg/bucket/policy" "github.com/minio/minio/pkg/bucket/policy"
) )
const (
s3Backend = "s3"
)
func init() { func init() {
const s3GatewayTemplate = `NAME: const s3GatewayTemplate = `NAME:
{{.HelpName}} - {{.Usage}} {{.HelpName}} - {{.Usage}}
@ -76,7 +72,7 @@ EXAMPLES:
` `
minio.RegisterGatewayCommand(cli.Command{ minio.RegisterGatewayCommand(cli.Command{
Name: s3Backend, Name: minio.S3BackendGateway,
Usage: "Amazon Simple Storage Service (S3)", Usage: "Amazon Simple Storage Service (S3)",
Action: s3GatewayMain, Action: s3GatewayMain,
CustomHelpTemplate: s3GatewayTemplate, CustomHelpTemplate: s3GatewayTemplate,
@ -109,7 +105,7 @@ type S3 struct {
// Name implements Gateway interface. // Name implements Gateway interface.
func (g *S3) Name() string { func (g *S3) Name() string {
return s3Backend return minio.S3BackendGateway
} }
const letterBytes = "abcdefghijklmnopqrstuvwxyz01234569" const letterBytes = "abcdefghijklmnopqrstuvwxyz01234569"

View File

@ -157,7 +157,7 @@ func healingMetricsPrometheus(ch chan<- prometheus.Metric) {
// collects gateway specific metrics for MinIO instance in Prometheus specific format // collects gateway specific metrics for MinIO instance in Prometheus specific format
// and sends to given channel // and sends to given channel
func gatewayMetricsPrometheus(ch chan<- prometheus.Metric) { func gatewayMetricsPrometheus(ch chan<- prometheus.Metric) {
if !globalIsGateway || (globalGatewayName != "s3" && globalGatewayName != "azure" && globalGatewayName != "gcs") { if !globalIsGateway || (globalGatewayName != S3BackendGateway && globalGatewayName != AzureBackendGateway && globalGatewayName != GCSBackendGateway) {
return return
} }