Add some conifguration and logging for the hub

This commit is contained in:
2023-07-04 22:05:24 -04:00
parent f82d3f18c6
commit 31f6cc0a0d
18 changed files with 250 additions and 151 deletions

View File

@@ -0,0 +1,66 @@
package persistence
import (
"github.com/google/uuid"
svc "go.fixergrid.net/servicedemon/registrar/internal/services"
)
type FakeRepo struct {
apps []*svc.Application
}
func NewFakeRepo() *FakeRepo {
return &FakeRepo{
apps: make([]*svc.Application, 0),
}
}
func (repo FakeRepo) IsRegistered(name string) bool {
for _, app := range repo.apps {
if name == app.Name && app.State == "registered" {
return true
}
}
return false
}
func (repo FakeRepo) GetApp(name string) (svc.Application, error) {
for _, app := range repo.apps {
if name == app.Name {
return *app, nil
}
}
return svc.Application{}, svc.ErrApplicationNotFound
}
func (repo FakeRepo) PendingApprovalCount() int {
count := 0
for _, app := range repo.apps {
if app.State == "pending_approval" {
count += 1
}
}
return count
}
func (repo *FakeRepo) StartAppRegistration(name string) uuid.UUID {
newApp := &svc.Application{
ID: uuid.New(),
Name: name,
State: "pending_approval",
}
repo.apps = append(repo.apps, newApp)
return newApp.ID
}
func (repo *FakeRepo) ApproveApp(id uuid.UUID) (svc.Application, error) {
for _, application := range repo.apps {
if application.ID == id {
application.State = "registered"
return *application, nil
}
}
return svc.Application{}, svc.ErrApplicationNotFound
}

View File

@@ -0,0 +1,2 @@
package services

View File

@@ -0,0 +1,5 @@
package services
type ApprovalRequester interface {
SendApprovalRequest(appName string) error
}

View File

@@ -0,0 +1,14 @@
package services
type Publisher interface {
Publish(topic string, message string)
}
type PubSub interface {
Publisher
Subscriber
}
type Subscriber interface {
Subscribe(topic string) <-chan string
}

View File

@@ -0,0 +1,27 @@
package services
import (
"errors"
"fmt"
"github.com/google/uuid"
)
var (
ErrAppRepo = errors.New("AppRepo")
ErrApplicationNotFound = fmt.Errorf("%w: application not found", ErrAppRepo)
)
type Application struct {
ID uuid.UUID
Name string
State string
}
type AppRepo interface {
IsRegistered(name string) bool
PendingApprovalCount() int
GetApp(name string) (Application, error)
StartAppRegistration(name string) uuid.UUID
ApproveApp(id uuid.UUID) (Application, error)
}