ebsfile

package module
v0.0.0-...-d5fbb1d Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: MIT Imports: 9 Imported by: 9

README

go-ebs-file

Abstracting AWS Elastic block store with io.ReadSeeker.

Quick Start


package main

import (
    "context"
    "encoding/hex"
    "fmt"
    "io"
    "log"
    "os"
    
    "github.com/aws/aws-sdk-go-v2/aws"
    "github.com/aws/aws-sdk-go-v2/config"
    
    ebsfile "github.com/masahiro331/go-ebs-file"
)

var _ aws.CredentialsProvider = &DummyCredentialProvider{}

type DummyCredentialProvider struct{}

func (p *DummyCredentialProvider) Retrieve(ctx context.Context) (aws.Credentials, error) {
    return aws.Credentials{
        AccessKeyID:     "YOUR_ACCESS_KEY",
        SecretAccessKey: "YOUR_SECRET_KEY",
    }, nil
}

func main() {
    var rs io.ReadSeeker
    cli, err := ebsfile.New(context.TODO(),
            config.WithRegion("YOUR_REGION"),
            config.WithCredentialsProvider(&DummyCredentialProvider{}),
        )
    if err != nil {
        log.Fatal(err)
    }
    
    rs, err = ebsfile.Open(os.Args[1], context.Background(), nil, cli)
    if err != nil {
        log.Fatal(err)
    }
    
    buf := make([]byte, 512)
    rs.Read(buf)
    fmt.Println(hex.Dump(buf))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(snapID string, ctx context.Context, cache Cache[string, []byte], e EBSAPI) (*io.SectionReader, error)

Types

type Cache

type Cache[K string, V any] interface {
	// Add cache data
	Add(key K, value V) bool

	// Get returns key's value from the cache
	Get(key K) (value V, ok bool)
}

type EBS

type EBS struct {
	*ebs.Client
}

func New

func New(ctx context.Context, optFns ...func(*config.LoadOptions) error) (*EBS, error)

func (EBS) WalkSnapshotBlocks

func (e EBS) WalkSnapshotBlocks(ctx context.Context, input *ebs.ListSnapshotBlocksInput, table map[int32]string) (*ebs.ListSnapshotBlocksOutput, map[int32]string, error)

type EBSAPI

type EBSAPI interface {
	ListSnapshotBlocks(ctx context.Context, params *ebs.ListSnapshotBlocksInput, optFns ...func(*ebs.Options)) (*ebs.ListSnapshotBlocksOutput, error)
	GetSnapshotBlock(ctx context.Context, params *ebs.GetSnapshotBlockInput, optFns ...func(*ebs.Options)) (*ebs.GetSnapshotBlockOutput, error)
	WalkSnapshotBlocks(ctx context.Context, input *ebs.ListSnapshotBlocksInput, table map[int32]string) (*ebs.ListSnapshotBlocksOutput, map[int32]string, error)
}

func NewMockEBS

func NewMockEBS(filePath string, blockSize int32, volumeSize int64) EBSAPI

type File

type File struct {
	// contains filtered or unexported fields
}

func (*File) ReadAt

func (f *File) ReadAt(p []byte, off int64) (n int, err error)

func (*File) Size

func (f *File) Size() int64

type MockEBS

type MockEBS struct {
	EBSAPI

	BlockSize  *int32
	NextToken  *string
	VolumeSize *int64
	// contains filtered or unexported fields
}

func (MockEBS) GetSnapshotBlock

func (m MockEBS) GetSnapshotBlock(_ context.Context, params *ebs.GetSnapshotBlockInput, optFns ...func(*ebs.Options)) (*ebs.GetSnapshotBlockOutput, error)

func (MockEBS) WalkSnapshotBlocks

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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