Add some conifguration and logging for the hub
This commit is contained in:
66
registrar/internal/persistence/fake_repo.go
Normal file
66
registrar/internal/persistence/fake_repo.go
Normal 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
|
||||
|
||||
}
|
||||
2
registrar/internal/services/app_registration.go
Normal file
2
registrar/internal/services/app_registration.go
Normal file
@@ -0,0 +1,2 @@
|
||||
package services
|
||||
|
||||
5
registrar/internal/services/approvals.go
Normal file
5
registrar/internal/services/approvals.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package services
|
||||
|
||||
type ApprovalRequester interface {
|
||||
SendApprovalRequest(appName string) error
|
||||
}
|
||||
14
registrar/internal/services/pubsub.go
Normal file
14
registrar/internal/services/pubsub.go
Normal 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
|
||||
}
|
||||
27
registrar/internal/services/repo.go
Normal file
27
registrar/internal/services/repo.go
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user