authstorage

package
v0.0.0-...-e1ceea9 Latest Latest
Warning

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

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

Documentation

Overview

Copyright 2020 CYBERCRYPT

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.

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

This section is empty.

Variables

View Source
var ErrNoRows = errors.New("no rows in result set")

ErrNoRows : Return this error when an empty record set is returned for the DB e.g. when a users isn't found

Functions

func ConnectDBPool

func ConnectDBPool(ctx context.Context, URL string) (*pgxpool.Pool, error)

ConnectDBPool creates a new DB pool for the DB URL (postgresql://...). Additionally, it configures the pool to use `gofrs-uuid` for handling UUIDs. TODO: configure connection pool (min, max connections etc.)

Types

type AuthStoreInterface

type AuthStoreInterface interface {
	Rollback(ctx context.Context) error
	Commit(ctx context.Context) error

	// User handling
	GetUserTag(ctx context.Context, userID uuid.UUID) ([]byte, error)
	UpsertUser(ctx context.Context, userID uuid.UUID, tag []byte) error

	// Access Object handling
	GetAccessObject(ctx context.Context, objectID uuid.UUID) ([]byte, []byte, error)
	InsertAcccessObject(ctx context.Context, objectID uuid.UUID, data, tag []byte) error
	UpdateAccessObject(ctx context.Context, objectID uuid.UUID, data, tag []byte) error
}

Abstraction interface mainly used for testing

type AuthStoreMock

type AuthStoreMock struct {
	CommitFunc   func(ctx context.Context) error
	RollbackFunc func(ctx context.Context) error

	GetUserTagFunc func(ctx context.Context, userID uuid.UUID) ([]byte, error)
	UpsertUserFunc func(ctx context.Context, userID uuid.UUID, tag []byte) error

	GetAccessObjectFunc     func(ctx context.Context, objectID uuid.UUID) ([]byte, []byte, error)
	InsertAcccessObjectFunc func(ctx context.Context, objectID uuid.UUID, data, tag []byte) error
	UpdateAccessObjectFunc  func(ctx context.Context, objectID uuid.UUID, data, tag []byte) error
}

AuthStoreMock allows to mock Auth Storage for testing

func (*AuthStoreMock) Commit

func (db *AuthStoreMock) Commit(ctx context.Context) error

func (*AuthStoreMock) GetAccessObject

func (db *AuthStoreMock) GetAccessObject(ctx context.Context, objectID uuid.UUID) ([]byte, []byte, error)

func (*AuthStoreMock) GetUserTag

func (db *AuthStoreMock) GetUserTag(ctx context.Context, userID uuid.UUID) ([]byte, error)

func (*AuthStoreMock) InsertAcccessObject

func (db *AuthStoreMock) InsertAcccessObject(ctx context.Context, objectID uuid.UUID, data, tag []byte) error

func (*AuthStoreMock) Rollback

func (db *AuthStoreMock) Rollback(ctx context.Context) error

func (*AuthStoreMock) UpdateAccessObject

func (db *AuthStoreMock) UpdateAccessObject(ctx context.Context, objectID uuid.UUID, data, tag []byte) error

func (*AuthStoreMock) UpsertUser

func (db *AuthStoreMock) UpsertUser(ctx context.Context, userID uuid.UUID, tag []byte) error

type DBAuthStore

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

DBAuthStore encapsulates a DB Tx for the authentication storage

func NewDBAuthStore

func NewDBAuthStore(ctx context.Context, pool *pgxpool.Pool) (*DBAuthStore, error)

NewDBAuthStore starts a new Transaction (tx) in the pool and instances an DBAuthStore with it

func (*DBAuthStore) Commit

func (storage *DBAuthStore) Commit(ctx context.Context) error

Commit commits the encapsulated transcation

func (*DBAuthStore) GetAccessObject

func (storage *DBAuthStore) GetAccessObject(ctx context.Context, objectID uuid.UUID) ([]byte, []byte, error)

GetAccessObject fetches data, tag of an Access Object with given Object ID

func (*DBAuthStore) GetUserTag

func (storage *DBAuthStore) GetUserTag(ctx context.Context, userID uuid.UUID) ([]byte, error)

Fetches a tag from the database If no user is found it returns the ErrNoRows error

func (*DBAuthStore) InsertAcccessObject

func (storage *DBAuthStore) InsertAcccessObject(ctx context.Context, objectID uuid.UUID, data, tag []byte) error

InsertAcccessObject inserts an Access Object (Object ID, data, tag)

func (*DBAuthStore) NewQuery

func (storage *DBAuthStore) NewQuery(query string) string

Enriches the query with request id for tracing to the SQL audit log

func (*DBAuthStore) Rollback

func (storage *DBAuthStore) Rollback(ctx context.Context) error

Used as a defer function to rollback an unfinished transaction

func (*DBAuthStore) UpdateAccessObject

func (storage *DBAuthStore) UpdateAccessObject(ctx context.Context, objectID uuid.UUID, data, tag []byte) error

UpdateAccessObject updates an Access Object with Object ID and sets data, tag

func (*DBAuthStore) UpsertUser

func (storage *DBAuthStore) UpsertUser(ctx context.Context, userID uuid.UUID, tag []byte) error

Creates a user with a tag, updates the tag if the user exists Returns an error if SQL query fails to execute in authstorage DB

type MemoryAuthStore

type MemoryAuthStore struct {
	Data map[uuid.UUID][][]byte
}

MemoryAuthStore is used by tests to mock the AutnStore in memory

func NewMemoryAuthStore

func NewMemoryAuthStore() *MemoryAuthStore

func (*MemoryAuthStore) Commit

func (m *MemoryAuthStore) Commit(ctx context.Context) error

func (*MemoryAuthStore) GetAccessObject

func (m *MemoryAuthStore) GetAccessObject(ctx context.Context, objectID uuid.UUID) ([]byte, []byte, error)

func (*MemoryAuthStore) GetUserTag

func (m *MemoryAuthStore) GetUserTag(ctx context.Context, userID uuid.UUID) ([]byte, error)

func (*MemoryAuthStore) InsertAcccessObject

func (m *MemoryAuthStore) InsertAcccessObject(ctx context.Context, objectID uuid.UUID, data, tag []byte) error

func (*MemoryAuthStore) Rollback

func (m *MemoryAuthStore) Rollback(ctx context.Context) error

func (*MemoryAuthStore) UpdateAccessObject

func (m *MemoryAuthStore) UpdateAccessObject(ctx context.Context, objectID uuid.UUID, data, tag []byte) error

func (*MemoryAuthStore) UpsertUser

func (m *MemoryAuthStore) UpsertUser(ctx context.Context, userID uuid.UUID, tag []byte) error

Jump to

Keyboard shortcuts

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