scopes

Paddy 2015-12-13 Parent:b93938562a17

2:a64a25ae2db1 Go to Latest

scopes/scope.go

Port over Postgres storage and tests. Do the minimum possible port of the code from auth to get Postgres working and make the tests run and pass again. This leaves a bug where the ErrScopeAlreadyExists type, when populatd from Postgres, contains the entire error string returned from the database, instead of parsing the ID itself out. Which is a thing we should do and add a test for.

History
paddy@0 1 package scopes
paddy@0 2
paddy@0 3 import (
paddy@0 4 "errors"
paddy@0 5 "fmt"
paddy@0 6
paddy@1 7 "code.secondbit.org/scopes.hg/types"
paddy@1 8
paddy@0 9 "golang.org/x/net/context"
paddy@0 10 )
paddy@0 11
paddy@0 12 var (
paddy@0 13 ErrNoStorer = errors.New("Storer not set in Context")
paddy@0 14 ErrScopeNotFound = errors.New("Scope not found")
paddy@0 15 )
paddy@0 16
paddy@0 17 type ErrScopeAlreadyExists string
paddy@0 18
paddy@0 19 func (e ErrScopeAlreadyExists) Error() string {
paddy@0 20 return fmt.Sprintf("scope %s already exists", string(e))
paddy@0 21 }
paddy@0 22
paddy@1 23 type Storer interface {
paddy@1 24 CreateScopes(scopes []scopeTypes.Scope, ctx context.Context) error
paddy@1 25 GetScopes(ids []string, ctx context.Context) (map[string]scopeTypes.Scope, error)
paddy@1 26 UpdateScope(change scopeTypes.ScopeChange, ctx context.Context) error
paddy@1 27 RemoveScopes(ids []string, ctx context.Context) error
paddy@1 28 ListScopes(ctx context.Context) ([]scopeTypes.Scope, error)
paddy@0 29 }