storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/cmd/gateway/nas/gateway-nas.go (about)

     1  /*
     2   * MinIO Cloud Storage, (C) 2018 MinIO, Inc.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package nas
    18  
    19  import (
    20  	"context"
    21  
    22  	"github.com/minio/cli"
    23  
    24  	minio "storj.io/minio/cmd"
    25  	"storj.io/minio/pkg/auth"
    26  	"storj.io/minio/pkg/madmin"
    27  )
    28  
    29  func init() {
    30  	const nasGatewayTemplate = `NAME:
    31    {{.HelpName}} - {{.Usage}}
    32  
    33  USAGE:
    34    {{.HelpName}} {{if .VisibleFlags}}[FLAGS]{{end}} PATH
    35  {{if .VisibleFlags}}
    36  FLAGS:
    37    {{range .VisibleFlags}}{{.}}
    38    {{end}}{{end}}
    39  PATH:
    40    path to NAS mount point
    41  
    42  EXAMPLES:
    43    1. Start minio gateway server for NAS backend
    44       {{.Prompt}} {{.EnvVarSetCommand}} MINIO_ROOT_USER{{.AssignmentOperator}}accesskey
    45       {{.Prompt}} {{.EnvVarSetCommand}} MINIO_ROOT_PASSWORD{{.AssignmentOperator}}secretkey
    46       {{.Prompt}} {{.HelpName}} /shared/nasvol
    47  
    48    2. Start minio gateway server for NAS with edge caching enabled
    49       {{.Prompt}} {{.EnvVarSetCommand}} MINIO_ROOT_USER{{.AssignmentOperator}}accesskey
    50       {{.Prompt}} {{.EnvVarSetCommand}} MINIO_ROOT_PASSWORD{{.AssignmentOperator}}secretkey
    51       {{.Prompt}} {{.EnvVarSetCommand}} MINIO_CACHE_DRIVES{{.AssignmentOperator}}"/mnt/drive1,/mnt/drive2,/mnt/drive3,/mnt/drive4"
    52       {{.Prompt}} {{.EnvVarSetCommand}} MINIO_CACHE_EXCLUDE{{.AssignmentOperator}}"bucket1/*,*.png"
    53       {{.Prompt}} {{.EnvVarSetCommand}} MINIO_CACHE_QUOTA{{.AssignmentOperator}}90
    54       {{.Prompt}} {{.EnvVarSetCommand}} MINIO_CACHE_AFTER{{.AssignmentOperator}}3
    55       {{.Prompt}} {{.EnvVarSetCommand}} MINIO_CACHE_WATERMARK_LOW{{.AssignmentOperator}}75
    56       {{.Prompt}} {{.EnvVarSetCommand}} MINIO_CACHE_WATERMARK_HIGH{{.AssignmentOperator}}85
    57       {{.Prompt}} {{.HelpName}} /shared/nasvol
    58  `
    59  
    60  	minio.RegisterGatewayCommand(cli.Command{
    61  		Name:               minio.NASBackendGateway,
    62  		Usage:              "Network-attached storage (NAS)",
    63  		Action:             nasGatewayMain,
    64  		CustomHelpTemplate: nasGatewayTemplate,
    65  		HideHelpCommand:    true,
    66  	})
    67  }
    68  
    69  // Handler for 'minio gateway nas' command line.
    70  func nasGatewayMain(ctx *cli.Context) {
    71  	// Validate gateway arguments.
    72  	if !ctx.Args().Present() || ctx.Args().First() == "help" {
    73  		cli.ShowCommandHelpAndExit(ctx, minio.NASBackendGateway, 1)
    74  	}
    75  
    76  	minio.StartGateway(ctx, &NAS{ctx.Args().First()})
    77  }
    78  
    79  // NAS implements Gateway.
    80  type NAS struct {
    81  	path string
    82  }
    83  
    84  // Name implements Gateway interface.
    85  func (g *NAS) Name() string {
    86  	return minio.NASBackendGateway
    87  }
    88  
    89  // NewGatewayLayer returns nas gatewaylayer.
    90  func (g *NAS) NewGatewayLayer(creds auth.Credentials) (minio.ObjectLayer, error) {
    91  	var err error
    92  	newObject, err := minio.NewFSObjectLayer(g.path)
    93  	if err != nil {
    94  		return nil, err
    95  	}
    96  	return &nasObjects{newObject}, nil
    97  }
    98  
    99  // Production - nas gateway is production ready.
   100  func (g *NAS) Production() bool {
   101  	return true
   102  }
   103  
   104  // IsListenSupported returns whether listen bucket notification is applicable for this gateway.
   105  func (n *nasObjects) IsListenSupported() bool {
   106  	return false
   107  }
   108  
   109  func (n *nasObjects) StorageInfo(ctx context.Context) (si minio.StorageInfo, _ []error) {
   110  	si, errs := n.ObjectLayer.StorageInfo(ctx)
   111  	si.Backend.GatewayOnline = si.Backend.Type == madmin.FS
   112  	si.Backend.Type = madmin.Gateway
   113  	return si, errs
   114  }
   115  
   116  // nasObjects implements gateway for MinIO and S3 compatible object storage servers.
   117  type nasObjects struct {
   118  	minio.ObjectLayer
   119  }
   120  
   121  func (n *nasObjects) IsTaggingSupported() bool {
   122  	return true
   123  }