azblobretriever

package
v1.40.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 13, 2024 License: MIT Imports: 7 Imported by: 0

README

Azure Blob Storage Feature Flag Retriever

This retriever is used to retrieve data from a Container on Azure Blob Storage.

Installation

go get github.com/thomaspoignant/go-feature-flag/retriever/azblobstorageretriever

Usage

Configuration

Create a Retriever struct with the following fields:

  • Container: Name of the Azure Blob Storage container
  • AccountName: Azure Storage Account Name
  • AccountKey: (Optional) Storage Account Key
  • ServiceURL: (Optional) Custom service URL
  • Object: Name of the feature flag file in the container
Authentication Methods
1. Shared Key Authentication
retriever := &azblobretriever.Retriever{
    Container:    "your-container",
    AccountName:  "your-account-name",
    AccountKey:   "your-account-key",
    Object:       "feature-flags.json",
}
retriever := &azblobretriever.Retriever{
    Container:    "your-container",
    AccountName:  "your-account-name",
    Object:       "feature-flags.json",
}
Retrieving Feature Flags
package main

import (
    "context"
    "fmt"
    "log"
    "time"

    "github.com/thomaspoignant/go-feature-flag/retriever/azblobstorageretriever"
)

func main() {
    retriever := &azblobretriever.Retriever{
        Container:   "feature-flags",
        AccountName: "mystorageaccount",
        AccountKey:  "your-account-key",
        Object:      "flags.json",
    }

    ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
    defer cancel()

    err := retriever.Init(ctx, nil)
    defer func() { _ = r.Shutdown(ctx) }()
    if err != nil {
        log.Fatalf("Failed to initialize retriever:", err)
    }

    data, err := retriever.Retrieve(ctx)
    if err != nil {
        log.Fatalf("Failed to retrieve feature flags: %v", err)
    }

    fmt.Println("Retrieved feature flags:")
    fmt.Println(string(data))
}

Key Features

  • Supports both shared key and default Azure credential authentication
  • Automatic retry mechanism for blob downloads
  • Flexible configuration with optional custom service URL

Error Handling

The Retrieve method returns an error if:

  • AccountName is empty
  • Container or Object is not specified
  • There's an issue initializing the Azure client.
  • There's a problem downloading or reading the file from Azure Blob Storage.

Best Practices

  • Security Never hard-code your AccountKey in your source code. Use environment variables or a secure secret management system.
  • Error Handling: Always check for errors returned by the Retrieve method.
  • Context: Use a context with timeout for better control over the retrieval process.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Retriever

type Retriever struct {
	// Container is the name of your Azure Blob Storage Container.
	Container string

	// Storage Account Name and Key
	AccountName string
	AccountKey  string

	// ServiceURL is the URL of the storage account e.g. https://<account>.blob.core.windows.net/
	// It can be overridden by the user to use a custom URL.
	// Default: https://<account>.blob.core.windows.net/
	ServiceURL string

	// Object is the name of your file in your container.
	Object string
	// contains filtered or unexported fields
}

func (*Retriever) Init

func (r *Retriever) Init(_ context.Context, _ *fflog.FFLogger) error

func (*Retriever) Retrieve

func (r *Retriever) Retrieve(ctx context.Context) ([]byte, error)

func (*Retriever) Shutdown

func (r *Retriever) Shutdown(_ context.Context) error

func (*Retriever) Status

func (r *Retriever) Status() retriever.Status

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL