From 6503ca3c670e139f5128998f7f5090a63abb0556 Mon Sep 17 00:00:00 2001 From: Piotr Janus Date: Wed, 17 Jul 2024 11:47:03 +0200 Subject: [PATCH] fix filter overrides with nil --- internal/cac/storage/multi.go | 1 + internal/cac/storage/tenant_storage.go | 6 +----- internal/cac/storage/tenant_storage_test.go | 2 +- internal/cac/utils/model.go | 4 +++- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/internal/cac/storage/multi.go b/internal/cac/storage/multi.go index b8e4a5d..8888c62 100644 --- a/internal/cac/storage/multi.go +++ b/internal/cac/storage/multi.go @@ -3,6 +3,7 @@ package storage import ( "context" "fmt" + "github.com/cloudentity/acp-client-go/clients/hub/models" "github.com/cloudentity/cac/internal/cac/api" "github.com/imdario/mergo" diff --git a/internal/cac/storage/tenant_storage.go b/internal/cac/storage/tenant_storage.go index 321c49d..dc245ea 100644 --- a/internal/cac/storage/tenant_storage.go +++ b/internal/cac/storage/tenant_storage.go @@ -115,10 +115,6 @@ func (t *TenantStorage) Read(ctx context.Context, opts ...api.SourceOpt) (models return nil, err } - if err = readFilesToMap(tenant, "themes", filepath.Join(path, "themes")); err != nil { - return nil, err - } - if themeDirs, err = listDirsInPath(filepath.Join(path, "themes")); err != nil { return nil, err } @@ -144,7 +140,7 @@ func (t *TenantStorage) Read(ctx context.Context, opts ...api.SourceOpt) (models templatesConfig map[string]any ) - if templatesConfig, err = readFiles(filepath.Join(path, "themes", normalize(theme.Name), "templates")); err != nil { + if templatesConfig, err = readFiles(filepath.Join(path, "themes", dir, "templates")); err != nil { return nil, err } diff --git a/internal/cac/storage/tenant_storage_test.go b/internal/cac/storage/tenant_storage_test.go index 5f6001e..6031673 100644 --- a/internal/cac/storage/tenant_storage_test.go +++ b/internal/cac/storage/tenant_storage_test.go @@ -195,7 +195,7 @@ updated_at: 0001-01-01T00:00:00.000Z st, err := storage.InitMultiStorage(&storage.MultiStorageConfiguration{ DirPath: []string{t.TempDir(), t.TempDir()}, }, storage.InitTenantStorage) - +q require.NoError(t, err) patchData, err := utils.FromModelToPatch(tc.data) diff --git a/internal/cac/utils/model.go b/internal/cac/utils/model.go index c58b864..6b74f82 100644 --- a/internal/cac/utils/model.go +++ b/internal/cac/utils/model.go @@ -85,7 +85,9 @@ func FilterPatch(patch models.Rfc7396PatchOperation, filters []string) (models.R filter = mapped } - newPatch[filter] = patch[filter] + if _, ok := patch[filter]; ok { + newPatch[filter] = patch[filter] + } } return newPatch, nil