Skip to content

Commit

Permalink
fix errors [#613]
Browse files Browse the repository at this point in the history
  • Loading branch information
roberlander2 committed Dec 16, 2022
1 parent 2301a12 commit 7c9a94d
Show file tree
Hide file tree
Showing 20 changed files with 2,793 additions and 1,792 deletions.
10 changes: 7 additions & 3 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@
{
"path": "detect_secrets.filters.allowlist.is_line_allowlisted"
},
{
"path": "detect_secrets.filters.common.is_baseline_file",
"filename": ".secrets.baseline"
},
{
"path": "detect_secrets.filters.common.is_ignored_due_to_verification_policies",
"min_level": 2
Expand Down Expand Up @@ -155,14 +159,14 @@
"filename": "core/auth/auth.go",
"hashed_secret": "58f3388441fbce0e48aef2bf74413a6f43f6dc70",
"is_verified": false,
"line_number": 897
"line_number": 896
},
{
"type": "Secret Keyword",
"filename": "core/auth/auth.go",
"hashed_secret": "94a7f0195bbbd2260c4e4d02b6348fbcd90b2b30",
"is_verified": false,
"line_number": 2385
"line_number": 2424
}
],
"core/auth/auth_type_email.go": [
Expand Down Expand Up @@ -294,5 +298,5 @@
}
]
},
"generated_at": "2022-12-15T23:06:32Z"
"generated_at": "2022-12-16T02:31:31Z"
}
42 changes: 21 additions & 21 deletions core/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ package core

import (
"core-building-block/core/auth"
"core-building-block/core/interfaces"
"core-building-block/core/model"
"core-building-block/driven/storage"
"fmt"
"time"

Expand All @@ -29,14 +29,14 @@ import (

// APIs exposes to the drivers adapters access to the core functionality
type APIs struct {
Services Services //expose to the drivers adapters
Administration Administration //expose to the drivers adapters
Encryption Encryption //expose to the drivers adapters
BBs BBs //expose to the drivers adapters
TPS TPS //expose to the drivers adapters
System System //expose to the drivers adapters
Services interfaces.Services //expose to the drivers adapters
Administration interfaces.Administration //expose to the drivers adapters
Encryption interfaces.Encryption //expose to the drivers adapters
BBs interfaces.BBs //expose to the drivers adapters
TPS interfaces.TPS //expose to the drivers adapters
System interfaces.System //expose to the drivers adapters

Auth auth.APIs //expose to the drivers auth
Auth interfaces.Auth //expose to the drivers auth

app *application

Expand Down Expand Up @@ -73,34 +73,34 @@ func (c *APIs) GetVersion() string {
func (c *APIs) storeSystemData() error {
newDocuments := make(map[string]string)

transaction := func(context storage.TransactionContext) error {
transaction := func(storage interfaces.Storage) error {
createAccount := false

//1. insert email auth type if does not exist
emailAuthType, err := c.app.storage.FindAuthType(auth.AuthTypeEmail)
emailAuthType, err := storage.FindAuthType(auth.AuthTypeEmail)
if err != nil {
return errors.WrapErrorAction(logutils.ActionFind, model.TypeAuthType, nil, err)
}
if emailAuthType == nil {
newDocuments["auth_type"] = uuid.NewString()
emailAuthType = &model.AuthType{ID: newDocuments["auth_type"], Code: auth.AuthTypeEmail, Description: "Authentication type relying on email and password",
IsExternal: false, IsAnonymous: false, UseCredentials: true, IgnoreMFA: false}
_, err = c.app.storage.InsertAuthType(context, *emailAuthType)
_, err = storage.InsertAuthType(*emailAuthType)
if err != nil {
return errors.WrapErrorAction(logutils.ActionInsert, model.TypeAuthType, nil, err)
}
}

//2. insert system org if does not exist
systemOrg, err := c.app.storage.FindSystemOrganization()
systemOrg, err := storage.FindSystemOrganization()
if err != nil {
return errors.WrapErrorAction(logutils.ActionFind, model.TypeOrganization, nil, err)
}
if systemOrg == nil {
newDocuments["organization"] = uuid.NewString()
systemOrgConfig := model.OrganizationConfig{ID: uuid.NewString(), DateCreated: time.Now().UTC()}
newSystemOrg := model.Organization{ID: newDocuments["organization"], Name: "System", Type: "small", System: true, Config: systemOrgConfig, DateCreated: time.Now().UTC()}
_, err = c.app.storage.InsertOrganization(context, newSystemOrg)
_, err = storage.InsertOrganization(newSystemOrg)
if err != nil {
return errors.WrapErrorAction(logutils.ActionInsert, model.TypeOrganization, nil, err)
}
Expand All @@ -110,7 +110,7 @@ func (c *APIs) storeSystemData() error {
}

//3. insert system app and appOrg if they do not exist
systemAdminAppOrgs, err := c.app.storage.FindApplicationsOrganizationsByOrgID(systemOrg.ID)
systemAdminAppOrgs, err := storage.FindApplicationsOrganizationsByOrgID(systemOrg.ID)
if err != nil {
return errors.WrapErrorAction(logutils.ActionFind, model.TypeApplicationOrganization, nil, err)
}
Expand All @@ -123,7 +123,7 @@ func (c *APIs) storeSystemData() error {
newAndroidAppType := model.ApplicationType{ID: uuid.NewString(), Identifier: c.systemAppTypeIdentifier, Name: c.systemAppTypeName, Versions: nil}
newSystemAdminApp := model.Application{ID: newDocuments["application"], Name: "System Admin application", MultiTenant: false, Admin: true,
SharedIdentities: false, Types: []model.ApplicationType{newAndroidAppType}, DateCreated: time.Now().UTC()}
_, err = c.app.storage.InsertApplication(context, newSystemAdminApp)
_, err = storage.InsertApplication(newSystemAdminApp)
if err != nil {
return errors.WrapErrorAction(logutils.ActionInsert, model.TypeApplication, nil, err)
}
Expand All @@ -139,7 +139,7 @@ func (c *APIs) storeSystemData() error {
newDocuments["application_organization"] = uuid.NewString()
newSystemAdminAppOrg := model.ApplicationOrganization{ID: newDocuments["application_organization"], Application: *systemAdminApp, Organization: *systemOrg,
SupportedAuthTypes: supportedAuthTypes, DateCreated: time.Now().UTC()}
_, err = c.app.storage.InsertApplicationOrganization(context, newSystemAdminAppOrg)
_, err = storage.InsertApplicationOrganization(newSystemAdminAppOrg)
if err != nil {
return errors.WrapErrorAction(logutils.ActionSave, model.TypeApplicationOrganization, nil, err)
}
Expand All @@ -162,7 +162,7 @@ func (c *APIs) storeSystemData() error {
}
newDocuments["api_key"] = uuid.NewString()
newAPIKey := model.APIKey{ID: newDocuments["api_key"], AppID: systemAppOrg.Application.ID, Key: c.systemAPIKey}
_, err := c.app.storage.InsertAPIKey(context, newAPIKey)
_, err := storage.InsertAPIKey(newAPIKey)
if err != nil {
return errors.WrapErrorAction(logutils.ActionInsert, model.TypeAPIKey, nil, err)
}
Expand All @@ -173,7 +173,7 @@ func (c *APIs) storeSystemData() error {
model.PermissionAllSystemCore: "Gives access to all admin and system APIs",
model.PermissionGrantAllPermissions: "Gives the ability to grant any permission",
}
existingPermissions, err := c.app.storage.FindPermissionsByName(context, []string{model.PermissionAllSystemCore, model.PermissionGrantAllPermissions})
existingPermissions, err := storage.FindPermissionsByName([]string{model.PermissionAllSystemCore, model.PermissionGrantAllPermissions})
if err != nil {
return errors.WrapErrorAction(logutils.ActionFind, model.TypePermission, &logutils.FieldArgs{"name": model.PermissionAllSystemCore}, err)
}
Expand Down Expand Up @@ -204,7 +204,7 @@ func (c *APIs) storeSystemData() error {
names += p.Name
}

err = c.app.storage.InsertPermissions(context, insert)
err = storage.InsertPermissions(insert)
if err != nil {
return errors.WrapErrorAction(logutils.ActionCreate, model.TypePermission, logutils.StringArgs(names), err)
}
Expand All @@ -218,7 +218,7 @@ func (c *APIs) storeSystemData() error {
if c.systemAccountEmail == "" || c.systemAccountPassword == "" {
return errors.ErrorData(logutils.StatusMissing, "initial system account email or password", nil)
}
newDocuments["account"], err = c.Auth.InitializeSystemAccount(context, *emailAuthType, systemAppOrg, model.PermissionAllSystemCore, c.systemAccountEmail, c.systemAccountPassword, "", c.logger.NewRequestLog(nil))
newDocuments["account"], err = c.Auth.InitializeSystemAccount(storage, *emailAuthType, systemAppOrg, model.PermissionAllSystemCore, c.systemAccountEmail, c.systemAccountPassword, "", c.logger.NewRequestLog(nil))
if err != nil {
return errors.WrapErrorAction(logutils.ActionInitialize, "system account", nil, err)
}
Expand All @@ -245,7 +245,7 @@ func (c *APIs) storeSystemData() error {
}

// NewCoreAPIs creates new CoreAPIs
func NewCoreAPIs(env string, version string, build string, storage Storage, auth auth.APIs, systemInitSettings map[string]string, logger *logs.Logger) *APIs {
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{}
application := application{env: env, version: version, build: build, storage: storage, listeners: listeners, auth: auth}
Expand Down
11 changes: 6 additions & 5 deletions core/apis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ import (
"testing"

core "core-building-block/core"
genmocks "core-building-block/core/mocks"
"core-building-block/core/interfaces"
genmocks "core-building-block/core/interfaces/mocks"
"core-building-block/core/model"

"github.com/rokwire/logging-library-go/logs"
"gotest.tools/assert"
)

func buildTestCoreAPIs(storage core.Storage) *core.APIs {
func buildTestCoreAPIs(storage interfaces.Storage) *core.APIs {
return core.NewCoreAPIs("local", "1.1.1", "build", storage, nil, nil, nil)
}

Expand Down Expand Up @@ -85,7 +86,7 @@ func TestAdmGetTest(t *testing.T) {
func TestSysCreateGlobalConfig(t *testing.T) {
storage := genmocks.Storage{}
storage.On("GetGlobalConfig").Return(nil, nil)
storage.On("CreateGlobalConfig", nil, &model.GlobalConfig{Setting: "setting"}).Return(nil)
storage.On("CreateGlobalConfig", &model.GlobalConfig{Setting: "setting"}).Return(nil)

coreAPIs := buildTestCoreAPIs(&storage)

Expand All @@ -99,7 +100,7 @@ func TestSysCreateGlobalConfig(t *testing.T) {
//second case - error
storage2 := genmocks.Storage{}
storage2.On("GetGlobalConfig").Return(nil, nil)
storage2.On("CreateGlobalConfig", nil, &model.GlobalConfig{Setting: "setting"}).Return(errors.New("error occured"))
storage2.On("CreateGlobalConfig", &model.GlobalConfig{Setting: "setting"}).Return(errors.New("error occured"))

coreAPIs = buildTestCoreAPIs(&storage2)

Expand Down Expand Up @@ -161,7 +162,7 @@ func TestSysGetOrganizations(t *testing.T) {

func TestSysGetApplication(t *testing.T) {
storage := genmocks.Storage{}
storage.On("FindApplication", nil, "_id").Return(&model.Application{ID: "_id"}, nil)
storage.On("FindApplication", "_id").Return(&model.Application{ID: "_id"}, nil)
coreAPIs := buildTestCoreAPIs(&storage)

getApplication, _ := coreAPIs.System.SysGetApplication("_id")
Expand Down
8 changes: 3 additions & 5 deletions core/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,19 @@

package core

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

// application represents the core application code based on hexagonal architecture
type application struct {
env string
version string
build string

storage Storage
storage interfaces.Storage

listeners []ApplicationListener

auth auth.APIs
auth interfaces.Auth
}

// start starts the core part of the application
Expand Down
Loading

0 comments on commit 7c9a94d

Please sign in to comment.