From 0e2d302804b10f65ea08800755f04582b5e1014e Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Sat, 14 Sep 2024 11:25:02 -0500 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=9B=A0=20Cache=20build?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + Taskfile.yml | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f1c37ad --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.task/ diff --git a/Taskfile.yml b/Taskfile.yml index 2b381c7..6b8852f 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -19,6 +19,8 @@ tasks: build: desc: Build server binary + sources: + - '**/*.go' generates: - build/lenore cmds: From bdc625b57e44431196f10ee6e76c571a4e3a5974 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Sat, 14 Sep 2024 11:27:28 -0500 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=92=A5=20Add=20store?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.go | 8 +++--- internal/testmocks/store.go | 7 +++-- internal/testmocks/store_meta.go | 20 +++++++++++++ internal/testmocks/store_osin_auth.go | 37 +++++++++++++++++++++++++ internal/testmocks/store_osin_client.go | 30 ++++++++++++++++++++ store/store.go | 31 +++++++++++++++++++++ 6 files changed, 127 insertions(+), 6 deletions(-) create mode 100644 internal/testmocks/store_meta.go create mode 100644 internal/testmocks/store_osin_auth.go create mode 100644 internal/testmocks/store_osin_client.go create mode 100644 store/store.go diff --git a/app.go b/app.go index c4b89ce..6390de9 100644 --- a/app.go +++ b/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 } diff --git a/internal/testmocks/store.go b/internal/testmocks/store.go index 9cdccb7..a7ae185 100644 --- a/internal/testmocks/store.go +++ b/internal/testmocks/store.go @@ -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{} } diff --git a/internal/testmocks/store_meta.go b/internal/testmocks/store_meta.go new file mode 100644 index 0000000..316ace0 --- /dev/null +++ b/internal/testmocks/store_meta.go @@ -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 +} diff --git a/internal/testmocks/store_osin_auth.go b/internal/testmocks/store_osin_auth.go new file mode 100644 index 0000000..a266cb1 --- /dev/null +++ b/internal/testmocks/store_osin_auth.go @@ -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 +} diff --git a/internal/testmocks/store_osin_client.go b/internal/testmocks/store_osin_client.go new file mode 100644 index 0000000..980379d --- /dev/null +++ b/internal/testmocks/store_osin_client.go @@ -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 +} diff --git a/store/store.go b/store/store.go new file mode 100644 index 0000000..6b5336b --- /dev/null +++ b/store/store.go @@ -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 +}