store

package
v0.0.0-...-5331e25 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2019 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Copyright 2019 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2019 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2017 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2019 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2019 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Copyright 2019 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Index

Constants

View Source
const (
	DBStoreName = "mender-store"
)
View Source
const (
	RsaKeyLength = 3072
)

Variables

View Source
var (
	ErrDBStoreNotInitialized = errors.New("DB store not initialized")
)
View Source
var LmdbNoSync bool = false

Can be set by tests to avoid expensive sync'ing.

View Source
var NoTransactionSupport error = errors.New("No transaction support in this Store")

Functions

func IsNoKeys

func IsNoKeys(e error) bool

Types

type DBStore

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

DBStore is an opaque structure representing a database backed storage. Implements `Store` interface.

func NewDBStore

func NewDBStore(dirpath string) *DBStore

NewDBStore creates an instance of Store backed by LMDB database. DBStore uses a single file for DB data (named `DBStoreName`). Parameter `dirpath` is a directory where the file will be stored. Returns nil if initialization failed.

func (*DBStore) Close

func (db *DBStore) Close() error

func (*DBStore) OpenRead

func (db *DBStore) OpenRead(name string) (io.ReadCloser, error)

func (*DBStore) OpenWrite

func (db *DBStore) OpenWrite(name string) (WriteCloserCommitter, error)

func (*DBStore) ReadAll

func (db *DBStore) ReadAll(name string) ([]byte, error)

func (*DBStore) ReadTransaction

func (db *DBStore) ReadTransaction(txnFunc func(txn Transaction) error) error

func (*DBStore) Remove

func (db *DBStore) Remove(name string) error

func (*DBStore) WriteAll

func (db *DBStore) WriteAll(name string, data []byte) error

func (*DBStore) WriteTransaction

func (db *DBStore) WriteTransaction(txnFunc func(txn Transaction) error) error

type DBStoreWrite

type DBStoreWrite struct {
	io.WriteCloser
	// contains filtered or unexported fields
}

func (*DBStoreWrite) Close

func (dbw *DBStoreWrite) Close() error

func (*DBStoreWrite) Commit

func (dbw *DBStoreWrite) Commit() error

func (*DBStoreWrite) Write

func (dbw *DBStoreWrite) Write(data []byte) (int, error)

type DirFile

type DirFile struct {
	io.WriteCloser
	// contains filtered or unexported fields
}

func (DirFile) Commit

func (df DirFile) Commit() error

type DirStore

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

func NewDirStore

func NewDirStore(path string) *DirStore

func (DirStore) Close

func (d DirStore) Close() error

func (DirStore) CommitFile

func (d DirStore) CommitFile(name string) error

Commit a file from temporary copy to the actual name. Under the hood, does a os.Rename() from a temp file (one with ~ suffix) to the actual name

func (DirStore) OpenRead

func (d DirStore) OpenRead(name string) (io.ReadCloser, error)

Open an entry for reading.

func (DirStore) OpenWrite

func (d DirStore) OpenWrite(name string) (WriteCloserCommitter, error)

Open an entry for writing. Under the hood, opens a temporary file (with 'name~' name) using os.O_WRONLY|os.O_CREAT flags, with default mode 0600. Once writing to temp file is done, the caller should run Commit() method of the WriteCloserCommitter interface.

func (DirStore) ReadAll

func (d DirStore) ReadAll(name string) ([]byte, error)

func (*DirStore) ReadTransaction

func (d *DirStore) ReadTransaction(txnFunc func(txn Transaction) error) error

func (DirStore) Remove

func (d DirStore) Remove(name string) error

func (DirStore) WriteAll

func (d DirStore) WriteAll(name string, data []byte) error

func (*DirStore) WriteTransaction

func (d *DirStore) WriteTransaction(txnFunc func(txn Transaction) error) error

type Keystore

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

func NewKeystore

func NewKeystore(store Store, name string) *Keystore

func (*Keystore) Generate

func (k *Keystore) Generate() error

func (*Keystore) GetKeyName

func (k *Keystore) GetKeyName() string

func (*Keystore) GetPrivateKey

func (k *Keystore) GetPrivateKey() *rsa.PrivateKey

func (*Keystore) GetStore

func (k *Keystore) GetStore() Store

func (*Keystore) Load

func (k *Keystore) Load() error

func (*Keystore) Private

func (k *Keystore) Private() *rsa.PrivateKey

func (*Keystore) Public

func (k *Keystore) Public() crypto.PublicKey

func (*Keystore) PublicPEM

func (k *Keystore) PublicPEM() (string, error)

func (*Keystore) Save

func (k *Keystore) Save() error

func (*Keystore) Sign

func (k *Keystore) Sign(data []byte) ([]byte, error)

type MemStore

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

in-memory store for testing purposes

func NewMemStore

func NewMemStore() *MemStore

func (*MemStore) Close

func (ms *MemStore) Close() error

func (*MemStore) Commit

func (ms *MemStore) Commit(name string, data []byte) error

func (*MemStore) Disable

func (ms *MemStore) Disable(disable bool)

func (*MemStore) OpenRead

func (ms *MemStore) OpenRead(name string) (io.ReadCloser, error)

func (*MemStore) OpenWrite

func (ms *MemStore) OpenWrite(name string) (WriteCloserCommitter, error)

func (*MemStore) ReadAll

func (ms *MemStore) ReadAll(name string) ([]byte, error)

func (*MemStore) ReadOnly

func (ms *MemStore) ReadOnly(ro bool)

func (*MemStore) ReadTransaction

func (ms *MemStore) ReadTransaction(txnFunc func(txn Transaction) error) error

func (*MemStore) Remove

func (ms *MemStore) Remove(name string) error

func (*MemStore) WriteAll

func (ms *MemStore) WriteAll(name string, data []byte) error

func (*MemStore) WriteTransaction

func (ms *MemStore) WriteTransaction(txnFunc func(txn Transaction) error) error

type MemStoreData

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

type MemStoreWriter

type MemStoreWriter struct {
	bytes.Buffer
	// contains filtered or unexported fields
}

func (*MemStoreWriter) Close

func (msw *MemStoreWriter) Close() error

func (*MemStoreWriter) Commit

func (msw *MemStoreWriter) Commit() error

type MockStore

type MockStore struct {
	mock.Mock
}

func (*MockStore) Close

func (ms *MockStore) Close() error

func (*MockStore) OpenRead

func (ms *MockStore) OpenRead(name string) (io.ReadCloser, error)

func (*MockStore) OpenWrite

func (ms *MockStore) OpenWrite(name string) (WriteCloserCommitter, error)

func (*MockStore) ReadAll

func (ms *MockStore) ReadAll(name string) ([]byte, error)

func (*MockStore) ReadTransaction

func (ms *MockStore) ReadTransaction(txnFunc func(txn Transaction) error) error

func (*MockStore) Remove

func (ms *MockStore) Remove(name string) error

func (*MockStore) WriteAll

func (ms *MockStore) WriteAll(name string, data []byte) error

func (*MockStore) WriteTransaction

func (ms *MockStore) WriteTransaction(txnFunc func(txn Transaction) error) error

type Store

type Store interface {
	// Works as a transaction interface as well, which auto-creates a
	// transaction for each operation.
	Transaction

	// open entry 'name' for reading
	OpenRead(name string) (io.ReadCloser, error)
	// open entry 'name' for writing, this may create a temporary entry for
	// writing data, once finished, one should call Commit() from
	// WriteCloserCommitter interface.
	OpenWrite(name string) (WriteCloserCommitter, error)

	// close the store
	Close() error

	// Runs the txnFunc function as one transaction by passing the
	// Transaction object to it. Stores that don't support transactions may
	// return NoTransactionSupport. Other errors may also be returned by the
	// txnFunc function, which will ultimately be returned by the
	// Transaction function. If an error is returned by txnFunc, the
	// transaction will be aborted instead of committed.
	WriteTransaction(txnFunc func(txn Transaction) error) error
	// Same as above, for read transactions.
	ReadTransaction(txnFunc func(txn Transaction) error) error
}

Store is a wrapper for data store exposing a common set of methods. Errors returned by Store methods should preserve semantics of os I/O errors, for instance, OpenRead() on an entry that does not exist shall return os.ErrNotExist

type Transaction

type Transaction interface {
	// read in contents of entry 'name'
	ReadAll(name string) ([]byte, error)
	// write all of data to entry 'name'
	WriteAll(name string, data []byte) error
	// remove an entry
	Remove(name string) error
}

type WriteCloserCommitter

type WriteCloserCommitter interface {
	io.WriteCloser
	// commit written data to data store
	Commit() error
}

wrapper for io.WriteCloser with extra Commit() method

Jump to

Keyboard shortcuts

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