storage

package module
v1.2.8 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

README

local-fs

Local File System Database

Health Check

godoc for jancajthaml-openbank/local-fs

codebeat badge

Usage

both plaintext and encrypted storage have same api

import (
  localfs "github.com/jancajthaml-openbank/local-fs"
)

...

storage := localfs.NewPlaintextStorage("/tmp")

// list nodes at /tmp/foo in ascending order
asc, err := storage.ListDirectory("foo", true)

// list nodes at /tmp/foo in descending order
desc, err := storage.ListDirectory("foo", false)

// count files at /tmp/foo
count, err := storage.CountFiles("foo")

// check if /tmp/foo exists
ok, err := storage.Exists("foo")

// delete file /tmp/foo
err := storage.Delete("foo")

// creates file /tmp/foo if not exists
err := storage.TouchFile("foo")

// ovewrites file /tmp/foo with "abc", creates file if it does not exist
err := storage.WriteFile("foo", []byte("abc"))

// crates and writes file /tmp/foo with "abc", fails if file exists
err := storage.WriteFileExclusive("foo", []byte("abc"))

// appends "abc" to end of /tmp/foo file, fails if file does not exist
err := storage.AppendFile("foo", []byte("abc"))

// read all bytes of file /tmp/foo
data, err := storage.ReadFileFully("tmp")

// read all bytes of file /tmp/foo
data, err := storage.ReadFileFully("tmp")

// returns reader for /tmp/foo
fd, err := storage.GetFileReader("tmp")

Encryption of data at rest

Generate some key

openssl rand -hex 32 | xargs --no-run-if-empty echo -n > /tmp/secrets/key

Write and read encrypted data at /tmp/data/foo

import (
  localfs "github.com/jancajthaml-openbank/local-fs"
)

...

storage := localfs.NewEncryptedStorage("/tmp/data", "/tmp/secrets/key")
err := storage.WriteFile("foo", []byte("pii"))

...

data, err := storage.ReadFileFully("/tmp/data/foo")

License

Licensed under Apache 2.0 see LICENSE.md for details

FOSSA Status

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EncryptedStorage added in v1.1.0

type EncryptedStorage struct {
	Storage
	// contains filtered or unexported fields
}

EncryptedStorage is a fascade to access encrypted storage

func (EncryptedStorage) AppendFile added in v1.1.0

func (storage EncryptedStorage) AppendFile(path string, data []byte) error

AppendFile appens data given absolute path to a file, creates it if it does not exist

func (EncryptedStorage) Chmod added in v1.1.8

func (storage EncryptedStorage) Chmod(path string, mod os.FileMode) error

Chmod sets chmod flag on given file

func (EncryptedStorage) CountFiles added in v1.1.0

func (storage EncryptedStorage) CountFiles(path string) (int, error)

CountFiles returns number of items in directory

func (EncryptedStorage) Delete added in v1.2.5

func (storage EncryptedStorage) Delete(path string) error

Delete removes given absolute path if that file does exists

func (EncryptedStorage) Exists added in v1.1.0

func (storage EncryptedStorage) Exists(path string) (bool, error)

Exists returns true if path exists

func (EncryptedStorage) LastModification added in v1.1.4

func (storage EncryptedStorage) LastModification(path string) (time.Time, error)

LastModification returns time of last modification

func (EncryptedStorage) ListDirectory added in v1.1.0

func (storage EncryptedStorage) ListDirectory(path string, ascending bool) ([]string, error)

ListDirectory returns sorted slice of item names in given absolute path default sorting is ascending

func (EncryptedStorage) Mkdir added in v1.2.7

func (storage EncryptedStorage) Mkdir(path string) error

Mkdir creates directory given absolute path

func (EncryptedStorage) ReadFileFully added in v1.1.0

func (storage EncryptedStorage) ReadFileFully(path string) ([]byte, error)

ReadFileFully reads whole file given path

func (EncryptedStorage) TouchFile added in v1.1.0

func (storage EncryptedStorage) TouchFile(path string) error

TouchFile creates file given absolute path if file does not already exist

func (EncryptedStorage) WriteFile added in v1.1.0

func (storage EncryptedStorage) WriteFile(path string, data []byte) error

WriteFile writes data given absolute path to a file, creates it if it does not exist

func (EncryptedStorage) WriteFileExclusive added in v1.1.0

func (storage EncryptedStorage) WriteFileExclusive(path string, data []byte) error

WriteFileExclusive writes data given path to a file if that file does not already exists

type NilStorage added in v1.1.7

type NilStorage struct {
	Storage
}

NilStorage is a nil storage fascade

func (NilStorage) AppendFile added in v1.1.7

func (storage NilStorage) AppendFile(path string, data []byte) error

AppendFile stub

func (NilStorage) Chmod added in v1.1.8

func (storage NilStorage) Chmod(path string, mod os.FileMode) error

Chmod sbut

func (NilStorage) CountFiles added in v1.1.7

func (storage NilStorage) CountFiles(path string) (int, error)

CountFiles stub

func (NilStorage) DeleteFile added in v1.1.7

func (storage NilStorage) DeleteFile(path string) error

DeleteFile stub

func (NilStorage) Exists added in v1.1.7

func (storage NilStorage) Exists(path string) (bool, error)

Exists stub

func (NilStorage) LastModification added in v1.1.7

func (storage NilStorage) LastModification(path string) (time.Time, error)

LastModification stub

func (NilStorage) ListDirectory added in v1.1.7

func (storage NilStorage) ListDirectory(path string, ascending bool) ([]string, error)

ListDirectory stub

func (NilStorage) ReadFileFully added in v1.1.7

func (storage NilStorage) ReadFileFully(path string) ([]byte, error)

ReadFileFully stub

func (NilStorage) TouchFile added in v1.1.7

func (storage NilStorage) TouchFile(path string) error

TouchFile stub

func (NilStorage) WriteFile added in v1.1.7

func (storage NilStorage) WriteFile(path string, data []byte) error

WriteFile stub

func (NilStorage) WriteFileExclusive added in v1.1.7

func (storage NilStorage) WriteFileExclusive(path string, data []byte) error

WriteFileExclusive stub

type PlaintextStorage added in v1.1.0

type PlaintextStorage struct {
	Storage
	// contains filtered or unexported fields
}

PlaintextStorage is a fascade to access plaintext storage

func (PlaintextStorage) AppendFile added in v1.1.0

func (storage PlaintextStorage) AppendFile(path string, data []byte) error

AppendFile appens data given absolute path to a file, creates it if it does not exist

func (PlaintextStorage) Chmod added in v1.1.8

func (storage PlaintextStorage) Chmod(path string, mod os.FileMode) error

Chmod sets chmod flag on given file

func (PlaintextStorage) CountFiles added in v1.1.0

func (storage PlaintextStorage) CountFiles(path string) (int, error)

CountFiles returns number of items in directory

func (PlaintextStorage) Delete added in v1.2.6

func (storage PlaintextStorage) Delete(path string) error

Delete removes given absolute path if that file does exists

func (PlaintextStorage) Exists added in v1.1.0

func (storage PlaintextStorage) Exists(path string) (bool, error)

Exists returns true if path exists

func (PlaintextStorage) LastModification added in v1.1.4

func (storage PlaintextStorage) LastModification(path string) (time.Time, error)

LastModification returns time of last modification

func (PlaintextStorage) ListDirectory added in v1.1.0

func (storage PlaintextStorage) ListDirectory(path string, ascending bool) ([]string, error)

ListDirectory returns sorted slice of item names in given absolute path default sorting is ascending

func (PlaintextStorage) Mkdir added in v1.2.7

func (storage PlaintextStorage) Mkdir(path string) error

Mkdir creates directory given absolute path

func (PlaintextStorage) ReadFileFully added in v1.1.0

func (storage PlaintextStorage) ReadFileFully(path string) ([]byte, error)

ReadFileFully reads whole file given path

func (PlaintextStorage) TouchFile added in v1.1.0

func (storage PlaintextStorage) TouchFile(path string) error

TouchFile creates files given absolute path if file does not already exist

func (PlaintextStorage) WriteFile added in v1.1.0

func (storage PlaintextStorage) WriteFile(path string, data []byte) error

WriteFile writes data given absolute path to a file, creates it if it does not exist

func (PlaintextStorage) WriteFileExclusive added in v1.1.0

func (storage PlaintextStorage) WriteFileExclusive(path string, data []byte) error

WriteFileExclusive writes data given path to a file if that file does not already exists

type Storage

type Storage interface {
	Chmod(absPath string, mod os.FileMode) error
	ListDirectory(string, bool) ([]string, error)
	CountFiles(string) (int, error)
	Exists(string) (bool, error)
	TouchFile(string) error
	Mkdir(string) error
	ReadFileFully(string) ([]byte, error)
	WriteFileExclusive(string, []byte) error
	WriteFile(string, []byte) error
	Delete(string) error
	AppendFile(string, []byte) error
	LastModification(string) (time.Time, error)
}

Storage represents contract

func NewEncryptedStorage added in v1.1.0

func NewEncryptedStorage(root string, key []byte) (Storage, error)

NewEncryptedStorage returns new storage over given root

func NewPlaintextStorage added in v1.1.0

func NewPlaintextStorage(root string) (Storage, error)

NewPlaintextStorage returns new storage over given root

Jump to

Keyboard shortcuts

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