💥 Add store
This commit is contained in:
parent
0e2d302804
commit
bdc625b57e
6 changed files with 127 additions and 6 deletions
8
app.go
8
app.go
|
|
@ -5,10 +5,10 @@ import (
|
|||
"fmt"
|
||||
|
||||
"codeberg.org/danjones000/lenore/config"
|
||||
"codeberg.org/danjones000/lenore/store"
|
||||
vocab "github.com/go-ap/activitypub"
|
||||
"github.com/go-ap/client"
|
||||
boxap "github.com/go-ap/fedbox/activitypub"
|
||||
proc "github.com/go-ap/processing"
|
||||
)
|
||||
|
||||
type App struct {
|
||||
|
|
@ -16,11 +16,11 @@ type App struct {
|
|||
self vocab.Service
|
||||
user vocab.Person
|
||||
version string
|
||||
storage proc.Store
|
||||
storage store.Store
|
||||
client client.C
|
||||
}
|
||||
|
||||
func NewApp(ver string, conf config.Config, db proc.Store) (*App, error) {
|
||||
func NewApp(ver string, conf config.Config, db store.Store) (*App, error) {
|
||||
if conf.BaseURL == "" {
|
||||
return nil, errors.New("Missing BaseURL")
|
||||
}
|
||||
|
|
@ -49,7 +49,7 @@ func (l *App) Environment() config.Env {
|
|||
return l.conf.Environment()
|
||||
}
|
||||
|
||||
func (l *App) Storage() proc.Store {
|
||||
func (l *App) Storage() store.Store {
|
||||
return l.storage
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
package testmocks
|
||||
|
||||
import (
|
||||
"codeberg.org/danjones000/lenore/store"
|
||||
vocab "github.com/go-ap/activitypub"
|
||||
"github.com/go-ap/filters"
|
||||
proc "github.com/go-ap/processing"
|
||||
)
|
||||
|
||||
type st struct{}
|
||||
|
|
@ -33,6 +33,9 @@ func (s *st) RemoveFrom(col vocab.IRI, it vocab.Item) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func GetStore() proc.Store {
|
||||
func (s *st) Close() {
|
||||
}
|
||||
|
||||
func GetStore() store.Store {
|
||||
return &st{}
|
||||
}
|
||||
|
|
|
|||
20
internal/testmocks/store_meta.go
Normal file
20
internal/testmocks/store_meta.go
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
package testmocks
|
||||
|
||||
import (
|
||||
"crypto"
|
||||
|
||||
vocab "github.com/go-ap/activitypub"
|
||||
proc "github.com/go-ap/processing"
|
||||
)
|
||||
|
||||
func (s *st) LoadKey(vocab.IRI) (crypto.PrivateKey, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *st) LoadMetadata(vocab.IRI) (*proc.Metadata, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *st) SaveMetadata(proc.Metadata, vocab.IRI) error {
|
||||
return nil
|
||||
}
|
||||
37
internal/testmocks/store_osin_auth.go
Normal file
37
internal/testmocks/store_osin_auth.go
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
package testmocks
|
||||
|
||||
import (
|
||||
"github.com/openshift/osin"
|
||||
)
|
||||
|
||||
func (s *st) LoadAccess(string) (*osin.AccessData, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *st) SaveAccess(*osin.AccessData) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *st) RemoveAccess(string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *st) LoadAuthorize(string) (*osin.AuthorizeData, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *st) SaveAuthorize(*osin.AuthorizeData) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *st) RemoveAuthorize(string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *st) LoadRefresh(string) (*osin.AccessData, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *st) RemoveRefresh(string) error {
|
||||
return nil
|
||||
}
|
||||
30
internal/testmocks/store_osin_client.go
Normal file
30
internal/testmocks/store_osin_client.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package testmocks
|
||||
|
||||
import (
|
||||
"github.com/openshift/osin"
|
||||
)
|
||||
|
||||
func (s *st) Clone() osin.Storage {
|
||||
n := *s
|
||||
return &n
|
||||
}
|
||||
|
||||
func (s *st) GetClient(string) (osin.Client, error) {
|
||||
return &osin.DefaultClient{}, nil
|
||||
}
|
||||
|
||||
func (s *st) CreateClient(osin.Client) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *st) UpdateClient(osin.Client) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *st) RemoveClient(string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *st) ListClients() (cl []osin.Client, er error) {
|
||||
return
|
||||
}
|
||||
31
store/store.go
Normal file
31
store/store.go
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package store
|
||||
|
||||
import (
|
||||
st "github.com/go-ap/fedbox/storage"
|
||||
proc "github.com/go-ap/processing"
|
||||
"github.com/openshift/osin"
|
||||
)
|
||||
|
||||
type ClientSaver interface {
|
||||
// UpdateClient updates the client (identified by it's id) and replaces the values with the values of client.
|
||||
UpdateClient(c osin.Client) error
|
||||
// CreateClient stores the client in the database and returns an error, if something went wrong.
|
||||
CreateClient(c osin.Client) error
|
||||
// RemoveClient removes a client (identified by id) from the database. Returns an error if something went wrong.
|
||||
RemoveClient(id string) error
|
||||
}
|
||||
|
||||
type ClientLister interface {
|
||||
// ListClients lists existing clients
|
||||
ListClients() ([]osin.Client, error)
|
||||
GetClient(id string) (osin.Client, error)
|
||||
}
|
||||
|
||||
type Store interface {
|
||||
ClientSaver
|
||||
ClientLister
|
||||
proc.Store
|
||||
proc.KeyLoader
|
||||
osin.Storage
|
||||
st.MetadataTyper
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue