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.
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.
Index ¶
- Variables
- func ConnectDBPool(ctx context.Context, URL string) (*pgxpool.Pool, error)
- type AuthStoreInterface
- type AuthStoreMock
- func (db *AuthStoreMock) Commit(ctx context.Context) error
- func (db *AuthStoreMock) GetAccessObject(ctx context.Context, objectID uuid.UUID) ([]byte, []byte, error)
- func (db *AuthStoreMock) GetUserTag(ctx context.Context, userID uuid.UUID) ([]byte, error)
- func (db *AuthStoreMock) InsertAcccessObject(ctx context.Context, objectID uuid.UUID, data, tag []byte) error
- func (db *AuthStoreMock) Rollback(ctx context.Context) error
- func (db *AuthStoreMock) UpdateAccessObject(ctx context.Context, objectID uuid.UUID, data, tag []byte) error
- func (db *AuthStoreMock) UpsertUser(ctx context.Context, userID uuid.UUID, tag []byte) error
- type DBAuthStore
- func (storage *DBAuthStore) Commit(ctx context.Context) error
- func (storage *DBAuthStore) GetAccessObject(ctx context.Context, objectID uuid.UUID) ([]byte, []byte, error)
- func (storage *DBAuthStore) GetUserTag(ctx context.Context, userID uuid.UUID) ([]byte, error)
- func (storage *DBAuthStore) InsertAcccessObject(ctx context.Context, objectID uuid.UUID, data, tag []byte) error
- func (storage *DBAuthStore) NewQuery(query string) string
- func (storage *DBAuthStore) Rollback(ctx context.Context) error
- func (storage *DBAuthStore) UpdateAccessObject(ctx context.Context, objectID uuid.UUID, data, tag []byte) error
- func (storage *DBAuthStore) UpsertUser(ctx context.Context, userID uuid.UUID, tag []byte) error
- type MemoryAuthStore
- func (m *MemoryAuthStore) Commit(ctx context.Context) error
- func (m *MemoryAuthStore) GetAccessObject(ctx context.Context, objectID uuid.UUID) ([]byte, []byte, error)
- func (m *MemoryAuthStore) GetUserTag(ctx context.Context, userID uuid.UUID) ([]byte, error)
- func (m *MemoryAuthStore) InsertAcccessObject(ctx context.Context, objectID uuid.UUID, data, tag []byte) error
- func (m *MemoryAuthStore) Rollback(ctx context.Context) error
- func (m *MemoryAuthStore) UpdateAccessObject(ctx context.Context, objectID uuid.UUID, data, tag []byte) error
- func (m *MemoryAuthStore) UpsertUser(ctx context.Context, userID uuid.UUID, tag []byte) error
Constants ¶
This section is empty.
Variables ¶
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 ¶
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) GetAccessObject ¶
func (*AuthStoreMock) GetUserTag ¶
func (*AuthStoreMock) InsertAcccessObject ¶
func (*AuthStoreMock) UpdateAccessObject ¶
func (*AuthStoreMock) UpsertUser ¶
type DBAuthStore ¶
type DBAuthStore struct {
// contains filtered or unexported fields
}
DBAuthStore encapsulates a DB Tx for the authentication storage
func NewDBAuthStore ¶
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 ¶
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 ¶
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 ¶
MemoryAuthStore is used by tests to mock the AutnStore in memory
func NewMemoryAuthStore ¶
func NewMemoryAuthStore() *MemoryAuthStore