github.com/weaviate/weaviate@v1.24.6/modules/backup-azure/module.go (about)

     1  //                           _       _
     2  // __      _____  __ ___   ___  __ _| |_ ___
     3  // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \
     4  //  \ V  V /  __/ (_| |\ V /| | (_| | ||  __/
     5  //   \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___|
     6  //
     7  //  Copyright © 2016 - 2024 Weaviate B.V. All rights reserved.
     8  //
     9  //  CONTACT: hello@weaviate.io
    10  //
    11  
    12  package modstgazure
    13  
    14  import (
    15  	"context"
    16  	"net/http"
    17  	"os"
    18  
    19  	"github.com/pkg/errors"
    20  	"github.com/sirupsen/logrus"
    21  	"github.com/weaviate/weaviate/entities/modulecapabilities"
    22  	"github.com/weaviate/weaviate/entities/moduletools"
    23  )
    24  
    25  const (
    26  	Name           = "backup-azure"
    27  	AltName1       = "azure"
    28  	azureContainer = "BACKUP_AZURE_CONTAINER"
    29  
    30  	// this is an optional value, allowing for
    31  	// the backup to be stored in a specific
    32  	// directory inside the provided container.
    33  	//
    34  	// if left unset, the backup files will
    35  	// be stored directly in the root of the
    36  	// container.
    37  	azurePath = "BACKUP_AZURE_PATH"
    38  )
    39  
    40  type clientConfig struct {
    41  	Container string
    42  
    43  	// this is an optional value, allowing for
    44  	// the backup to be stored in a specific
    45  	// directory inside the provided bucket
    46  	BackupPath string
    47  }
    48  
    49  type Module struct {
    50  	logger logrus.FieldLogger
    51  	*azureClient
    52  	dataPath string
    53  }
    54  
    55  func New() *Module {
    56  	return &Module{}
    57  }
    58  
    59  func (m *Module) Name() string {
    60  	return Name
    61  }
    62  
    63  func (m *Module) IsExternal() bool {
    64  	return true
    65  }
    66  
    67  func (m *Module) AltNames() []string {
    68  	return []string{AltName1}
    69  }
    70  
    71  func (m *Module) Type() modulecapabilities.ModuleType {
    72  	return modulecapabilities.Backup
    73  }
    74  
    75  func (m *Module) Init(ctx context.Context,
    76  	params moduletools.ModuleInitParams,
    77  ) error {
    78  	m.logger = params.GetLogger()
    79  	m.dataPath = params.GetStorageProvider().DataPath()
    80  
    81  	config := &clientConfig{
    82  		Container:  os.Getenv(azureContainer),
    83  		BackupPath: os.Getenv(azurePath),
    84  	}
    85  	if config.Container == "" {
    86  		return errors.Errorf("backup init: '%s' must be set", azureContainer)
    87  	}
    88  
    89  	client, err := newClient(ctx, config, m.dataPath)
    90  	if err != nil {
    91  		return errors.Wrap(err, "init Azure client")
    92  	}
    93  	m.azureClient = client
    94  	return nil
    95  }
    96  
    97  func (m *Module) RootHandler() http.Handler {
    98  	// TODO: remove once this is a capability interface
    99  	return nil
   100  }
   101  
   102  func (m *Module) MetaInfo() (map[string]interface{}, error) {
   103  	metaInfo := make(map[string]interface{})
   104  	metaInfo["containerName"] = m.config.Container
   105  	if root := m.config.BackupPath; root != "" {
   106  		metaInfo["rootName"] = root
   107  	}
   108  	return metaInfo, nil
   109  }
   110  
   111  // verify we implement the modules.Module interface
   112  var (
   113  	_ = modulecapabilities.Module(New())
   114  	_ = modulecapabilities.BackupBackend(New())
   115  	_ = modulecapabilities.MetaProvider(New())
   116  )