Skip to content

Commit

Permalink
move default storage listener to model package [#613]
Browse files Browse the repository at this point in the history
  • Loading branch information
roberlander2 committed Dec 16, 2022
1 parent 7c9a94d commit 0c88452
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 80 deletions.
10 changes: 5 additions & 5 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -145,28 +145,28 @@
"filename": "core/auth/auth.go",
"hashed_secret": "417355fe2b66baa6826739a6d8006ab2ddcf5186",
"is_verified": false,
"line_number": 145
"line_number": 144
},
{
"type": "Secret Keyword",
"filename": "core/auth/auth.go",
"hashed_secret": "700f93e97a8aaf0664601a8f298ac5ad0ff13c37",
"is_verified": false,
"line_number": 147
"line_number": 146
},
{
"type": "Secret Keyword",
"filename": "core/auth/auth.go",
"hashed_secret": "58f3388441fbce0e48aef2bf74413a6f43f6dc70",
"is_verified": false,
"line_number": 896
"line_number": 895
},
{
"type": "Secret Keyword",
"filename": "core/auth/auth.go",
"hashed_secret": "94a7f0195bbbd2260c4e4d02b6348fbcd90b2b30",
"is_verified": false,
"line_number": 2424
"line_number": 2423
}
],
"core/auth/auth_type_email.go": [
Expand Down Expand Up @@ -298,5 +298,5 @@
}
]
},
"generated_at": "2022-12-16T02:31:31Z"
"generated_at": "2022-12-16T03:09:45Z"
}
4 changes: 2 additions & 2 deletions core/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (c *APIs) Start() {
}

// AddListener adds application listener
func (c *APIs) AddListener(listener ApplicationListener) {
func (c *APIs) AddListener(listener interfaces.ApplicationListener) {
c.app.addListener(listener)
}

Expand Down Expand Up @@ -247,7 +247,7 @@ func (c *APIs) storeSystemData() error {
// NewCoreAPIs creates new CoreAPIs
func NewCoreAPIs(env string, version string, build string, storage interfaces.Storage, auth interfaces.Auth, systemInitSettings map[string]string, logger *logs.Logger) *APIs {
//add application instance
listeners := []ApplicationListener{}
listeners := []interfaces.ApplicationListener{}
application := application{env: env, version: version, build: build, storage: storage, listeners: listeners, auth: auth}

//add coreAPIs instance
Expand Down
15 changes: 12 additions & 3 deletions core/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

package core

import "core-building-block/core/interfaces"
import (
"core-building-block/core/interfaces"
"core-building-block/core/model"
)

// application represents the core application code based on hexagonal architecture
type application struct {
Expand All @@ -24,7 +27,7 @@ type application struct {

storage interfaces.Storage

listeners []ApplicationListener
listeners []interfaces.ApplicationListener

auth interfaces.Auth
}
Expand All @@ -37,7 +40,7 @@ func (app *application) start() {
}

// addListener adds application listener
func (app *application) addListener(listener ApplicationListener) {
func (app *application) addListener(listener interfaces.ApplicationListener) {
//TODO
//logs.Println("Application -> AddListener")

Expand All @@ -49,3 +52,9 @@ func (app *application) notifyListeners(message string, data interface{}) {
// TODO
}()
}

// StorageListener listenes for change data storage events
type StorageListener struct {
app *application
model.DefaultStorageListener
}
3 changes: 1 addition & 2 deletions core/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package auth
import (
"core-building-block/core/interfaces"
"core-building-block/core/model"
"core-building-block/driven/storage"
"core-building-block/utils"
"crypto/rsa"
"encoding/json"
Expand Down Expand Up @@ -2620,7 +2619,7 @@ func NewLocalServiceRegLoader(storage interfaces.Storage) *LocalServiceRegLoader
// StorageListener represents storage listener implementation for the auth package
type StorageListener struct {
auth *Auth
storage.DefaultListenerImpl
model.DefaultStorageListener
}

// OnIdentityProvidersUpdated notifies that identity providers have been updated
Expand Down
1 change: 0 additions & 1 deletion core/auth/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package auth
import (
"core-building-block/core/interfaces"
"core-building-block/core/model"
// "core-building-block/driven/storage"
"time"

"github.com/rokwire/core-auth-library-go/v2/sigauth"
Expand Down
29 changes: 0 additions & 29 deletions core/interfaces.go

This file was deleted.

4 changes: 4 additions & 0 deletions core/interfaces/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,7 @@ type System interface {
SysGetAuthTypes() ([]model.AuthType, error)
SysUpdateAuthTypes(ID string, code string, description string, isExternal bool, isAnonymous bool, useCredentials bool, ignoreMFA bool, params map[string]interface{}) error
}

// ApplicationListener represents application listener
type ApplicationListener interface {
}
6 changes: 3 additions & 3 deletions core/interfaces/driven.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

// Storage interface to communicate with the storage
type Storage interface {
RegisterStorageListener(storageListener Listener)
RegisterStorageListener(listener StorageListener)

PerformTransaction(func(adapter Storage) error) error

Expand Down Expand Up @@ -223,8 +223,8 @@ type Storage interface {
DeleteAppConfig(ID string) error
}

// Listener represents storage listener
type Listener interface {
// StorageListener represents storage listener
type StorageListener interface {
OnAPIKeysUpdated()
OnAuthTypesUpdated()
OnIdentityProvidersUpdated()
Expand Down
6 changes: 3 additions & 3 deletions core/interfaces/mocks/Storage.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions core/model/listener.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright 2022 Board of Trustees of the University of Illinois.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package model

// DefaultStorageListener default storage listener implementation
type DefaultStorageListener struct{}

// OnAPIKeysUpdated notifies api keys have been updated
func (d *DefaultStorageListener) OnAPIKeysUpdated() {}

// OnAuthTypesUpdated notifies auth types have been updated
func (d *DefaultStorageListener) OnAuthTypesUpdated() {}

// OnIdentityProvidersUpdated notifies identity providers have been updated
func (d *DefaultStorageListener) OnIdentityProvidersUpdated() {}

// OnServiceRegsUpdated notifies services regs have been updated
func (d *DefaultStorageListener) OnServiceRegsUpdated() {}

// OnOrganizationsUpdated notifies organizations have been updated
func (d *DefaultStorageListener) OnOrganizationsUpdated() {}

// OnApplicationsUpdated notifies applications have been updated
func (d *DefaultStorageListener) OnApplicationsUpdated() {}

// OnApplicationsOrganizationsUpdated notifies applications organizations have been updated
func (d *DefaultStorageListener) OnApplicationsOrganizationsUpdated() {}

// OnApplicationConfigsUpdated notifies application configs have been updated
func (d *DefaultStorageListener) OnApplicationConfigsUpdated() {}
33 changes: 3 additions & 30 deletions driven/storage/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ func (sa *Adapter) Start() error {
}

// RegisterStorageListener registers a data change listener with the storage adapter
func (sa *Adapter) RegisterStorageListener(storageListener interfaces.Listener) {
sa.db.listeners = append(sa.db.listeners, storageListener)
func (sa *Adapter) RegisterStorageListener(listener interfaces.StorageListener) {
sa.db.listeners = append(sa.db.listeners, listener)
}

// PerformTransaction performs a transaction
Expand Down Expand Up @@ -3609,7 +3609,7 @@ func NewStorageAdapter(mongoDBAuth string, mongoDBName string, mongoTimeout stri

type storageListener struct {
adapter *Adapter
DefaultListenerImpl
model.DefaultStorageListener
}

func (sl *storageListener) OnAuthTypesUpdated() {
Expand Down Expand Up @@ -3638,30 +3638,3 @@ func (sl *storageListener) OnApplicationsOrganizationsUpdated() {
func (sl *storageListener) OnApplicationConfigsUpdated() {
sl.adapter.cacheApplicationConfigs()
}

// DefaultListenerImpl default listener implementation
type DefaultListenerImpl struct{}

// OnAPIKeysUpdated notifies api keys have been updated
func (d *DefaultListenerImpl) OnAPIKeysUpdated() {}

// OnAuthTypesUpdated notifies auth types have been updated
func (d *DefaultListenerImpl) OnAuthTypesUpdated() {}

// OnIdentityProvidersUpdated notifies identity providers have been updated
func (d *DefaultListenerImpl) OnIdentityProvidersUpdated() {}

// OnServiceRegsUpdated notifies services regs have been updated
func (d *DefaultListenerImpl) OnServiceRegsUpdated() {}

// OnOrganizationsUpdated notifies organizations have been updated
func (d *DefaultListenerImpl) OnOrganizationsUpdated() {}

// OnApplicationsUpdated notifies applications have been updated
func (d *DefaultListenerImpl) OnApplicationsUpdated() {}

// OnApplicationsOrganizationsUpdated notifies applications organizations have been updated
func (d *DefaultListenerImpl) OnApplicationsOrganizationsUpdated() {}

// OnApplicationConfigsUpdated notifies application configs have been updated
func (d *DefaultListenerImpl) OnApplicationConfigsUpdated() {}
4 changes: 2 additions & 2 deletions driven/storage/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type database struct {
applicationConfigs *collectionWrapper
permissions *collectionWrapper

listeners []interfaces.Listener
listeners []interfaces.StorageListener
}

func (m *database) start() error {
Expand Down Expand Up @@ -221,7 +221,7 @@ func (m *database) start() error {
go m.applicationsOrganizations.Watch(nil, m.logger)
go m.applicationConfigs.Watch(nil, m.logger)

m.listeners = []interfaces.Listener{}
m.listeners = []interfaces.StorageListener{}

return nil
}
Expand Down

0 comments on commit 0c88452

Please sign in to comment.