Skip to content
Snippets Groups Projects
Commit 5873eefb authored by Semyon Krestyaninov's avatar Semyon Krestyaninov :dog2:
Browse files

pkg setup moved from pkg

parent 0dd516f1
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"context" "context"
"io/fs" "io/fs"
setup2 "git.perx.ru/perxis/perxis-go/setup"
"go.uber.org/zap" "go.uber.org/zap"
"git.perx.ru/perxis/perxis-go" "git.perx.ru/perxis/perxis-go"
...@@ -11,7 +12,6 @@ import ( ...@@ -11,7 +12,6 @@ import (
"git.perx.ru/perxis/perxis-go/pkg/content" "git.perx.ru/perxis/perxis-go/pkg/content"
"git.perx.ru/perxis/perxis-go/pkg/errors" "git.perx.ru/perxis/perxis-go/pkg/errors"
"git.perx.ru/perxis/perxis-go/pkg/schema" "git.perx.ru/perxis/perxis-go/pkg/schema"
"git.perx.ru/perxis/perxis-go/pkg/setup"
pb "git.perx.ru/perxis/perxis-go/proto/extensions" pb "git.perx.ru/perxis/perxis-go/proto/extensions"
) )
...@@ -87,10 +87,10 @@ func isSameExtension(s1, s2 *schema.Schema) bool { ...@@ -87,10 +87,10 @@ func isSameExtension(s1, s2 *schema.Schema) bool {
} }
// UpdateExtensionCollections возвращает опцию для обновления коллекций расширения // UpdateExtensionCollections возвращает опцию для обновления коллекций расширения
func UpdateExtensionCollections() setup.CollectionOption { func UpdateExtensionCollections() setup2.CollectionOption {
return func(e *setup.Collection) { return func(e *setup2.Collection) {
next := e.UpdateFunc next := e.UpdateFunc
e.UpdateFunc = func(s *setup.Setup, old, new *collections.Collection) (*collections.Collection, bool) { e.UpdateFunc = func(s *setup2.Setup, old, new *collections.Collection) (*collections.Collection, bool) {
if !s.IsForce() && !new.IsView() && !old.IsView() && !isSameExtension(new.Schema, old.Schema) { if !s.IsForce() && !new.IsView() && !old.IsView() && !isSameExtension(new.Schema, old.Schema) {
s.Logger().Warn("Collection is already exists and not updated", zap.String("ID", new.ID)) s.Logger().Warn("Collection is already exists and not updated", zap.String("ID", new.ID))
return nil, false return nil, false
......
...@@ -3,6 +3,7 @@ package extension ...@@ -3,6 +3,7 @@ package extension
import ( import (
"testing" "testing"
setup2 "git.perx.ru/perxis/perxis-go/setup"
"go.uber.org/zap" "go.uber.org/zap"
"go.uber.org/zap/zaptest/observer" "go.uber.org/zap/zaptest/observer"
...@@ -10,7 +11,6 @@ import ( ...@@ -10,7 +11,6 @@ import (
"git.perx.ru/perxis/perxis-go/pkg/collections" "git.perx.ru/perxis/perxis-go/pkg/collections"
"git.perx.ru/perxis/perxis-go/pkg/schema" "git.perx.ru/perxis/perxis-go/pkg/schema"
"git.perx.ru/perxis/perxis-go/pkg/schema/field" "git.perx.ru/perxis/perxis-go/pkg/schema/field"
"git.perx.ru/perxis/perxis-go/pkg/setup"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
...@@ -110,12 +110,12 @@ func TestDefaultUpdate_ExtensionCollections(t *testing.T) { ...@@ -110,12 +110,12 @@ func TestDefaultUpdate_ExtensionCollections(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
cfg := setup.NewConfig() cfg := setup2.NewConfig()
cfg.Collections.Add(tt.collection, UpdateExtensionCollections()) cfg.Collections.Add(tt.collection, UpdateExtensionCollections())
core, ob := observer.New(zap.DebugLevel) core, ob := observer.New(zap.DebugLevel)
logger := zap.New(core) logger := zap.New(core)
set := setup.NewSetup(nil, "sp", "env", logger).WithForce(tt.force) set := setup2.NewSetup(nil, "sp", "env", logger).WithForce(tt.force)
_, update := cfg.Collections[0].UpdateFunc(set, tt.exist, tt.collection) _, update := cfg.Collections[0].UpdateFunc(set, tt.exist, tt.collection)
assert.Equal(t, tt.update, update) assert.Equal(t, tt.update, update)
......
...@@ -2,7 +2,7 @@ package extension ...@@ -2,7 +2,7 @@ package extension
import ( import (
assets "git.perx.ru/perxis/perxis-go/assets/extension-manager" assets "git.perx.ru/perxis/perxis-go/assets/extension-manager"
"git.perx.ru/perxis/perxis-go/pkg/setup" "git.perx.ru/perxis/perxis-go/setup"
) )
var ( var (
......
...@@ -9,7 +9,7 @@ import ( ...@@ -9,7 +9,7 @@ import (
"git.perx.ru/perxis/perxis-go/pkg/content" "git.perx.ru/perxis/perxis-go/pkg/content"
"git.perx.ru/perxis/perxis-go/pkg/extension" "git.perx.ru/perxis/perxis-go/pkg/extension"
"git.perx.ru/perxis/perxis-go/pkg/roles" "git.perx.ru/perxis/perxis-go/pkg/roles"
"git.perx.ru/perxis/perxis-go/pkg/setup" setup2 "git.perx.ru/perxis/perxis-go/setup"
"go.uber.org/zap" "go.uber.org/zap"
) )
...@@ -21,7 +21,7 @@ const ( ...@@ -21,7 +21,7 @@ const (
clientDesc = "Клиент используется при работе расширения \"%s\"" clientDesc = "Клиент используется при работе расширения \"%s\""
) )
type SetupFunc func(spaceID, envID string) *setup.Setup type SetupFunc func(spaceID, envID string) *setup2.Setup
type SignatureFunc func(spaceID string) string type SignatureFunc func(spaceID string) string
// Extension реализация сервиса с одним расширением // Extension реализация сервиса с одним расширением
...@@ -78,7 +78,7 @@ func (s *Extension) GetKey(spaceID string) string { ...@@ -78,7 +78,7 @@ func (s *Extension) GetKey(spaceID string) string {
} }
// setupExtensionClient добавляет роль и клиента для авторизации расширения // setupExtensionClient добавляет роль и клиента для авторизации расширения
func (s *Extension) setupExtensionClient(set *setup.Setup, spaceID string) { func (s *Extension) setupExtensionClient(set *setup2.Setup, spaceID string) {
if !s.withClient { if !s.withClient {
return return
} }
...@@ -98,7 +98,7 @@ func (s *Extension) setupExtensionClient(set *setup.Setup, spaceID string) { ...@@ -98,7 +98,7 @@ func (s *Extension) setupExtensionClient(set *setup.Setup, spaceID string) {
role := *s.role role := *s.role
role.SpaceID = spaceID role.SpaceID = spaceID
set.AddRole(&role, setup.DeleteRoleIfRemoveFlag()) set.AddRole(&role, setup2.DeleteRoleIfRemoveFlag())
if s.client == nil { if s.client == nil {
s.client = &clients.Client{} s.client = &clients.Client{}
...@@ -130,14 +130,14 @@ func (s *Extension) setupExtensionClient(set *setup.Setup, spaceID string) { ...@@ -130,14 +130,14 @@ func (s *Extension) setupExtensionClient(set *setup.Setup, spaceID string) {
} }
} }
set.AddClient(&client, setup.OverwriteClient(), setup.DeleteClientIfRemoveFlag()) set.AddClient(&client, setup2.OverwriteClient(), setup2.DeleteClientIfRemoveFlag())
} }
func (s *Extension) GetSetup(spaceID, envID string) (*setup.Setup, error) { func (s *Extension) GetSetup(spaceID, envID string) (*setup2.Setup, error) {
set := s.setupFunc(spaceID, envID) set := s.setupFunc(spaceID, envID)
set.Config.Collections.WithOptions( set.Config.Collections.WithOptions(
func(c *collections.Collection) bool { return true }, func(c *collections.Collection) bool { return true },
setup.AddMetadata(extension.MetadataKey, s.GetName()), setup2.AddMetadata(extension.MetadataKey, s.GetName()),
) )
if set.HasErrors() { if set.HasErrors() {
s.Logger.Error("Invalid setup config", zap.Errors("Errors", set.Errors())) s.Logger.Error("Invalid setup config", zap.Errors("Errors", set.Errors()))
......
...@@ -7,8 +7,8 @@ import ( ...@@ -7,8 +7,8 @@ import (
"git.perx.ru/perxis/perxis-go/pkg/collections" "git.perx.ru/perxis/perxis-go/pkg/collections"
"git.perx.ru/perxis/perxis-go/pkg/data" "git.perx.ru/perxis/perxis-go/pkg/data"
"git.perx.ru/perxis/perxis-go/pkg/errors" "git.perx.ru/perxis/perxis-go/pkg/errors"
"git.perx.ru/perxis/perxis-go/pkg/setup"
pb "git.perx.ru/perxis/perxis-go/proto/extensions" pb "git.perx.ru/perxis/perxis-go/proto/extensions"
setup2 "git.perx.ru/perxis/perxis-go/setup"
"go.uber.org/zap" "go.uber.org/zap"
"git.perx.ru/perxis/perxis-go/pkg/content" "git.perx.ru/perxis/perxis-go/pkg/content"
...@@ -134,7 +134,7 @@ func (s *storage) init(ctx context.Context, spaceID, envID string) error { ...@@ -134,7 +134,7 @@ func (s *storage) init(ctx context.Context, spaceID, envID string) error {
// миграция окружения не должна запуститься, поскольку окружение может быть сломано // миграция окружения не должна запуститься, поскольку окружение может быть сломано
// расширениями - нужно дать возможность восстановиться // расширениями - нужно дать возможность восстановиться
cfg := Config.Clone() cfg := Config.Clone()
cfg.Collections.WithOptions(func(c *collections.Collection) bool { return true }, setup.SkipMigration()) cfg.Collections.WithOptions(func(c *collections.Collection) bool { return true }, setup2.SkipMigration())
stp := setup.NewSetup(s.content, spaceID, envID, s.logger).WithConfig(cfg) stp := setup2.NewSetup(s.content, spaceID, envID, s.logger).WithConfig(cfg)
return stp.Install(ctx) return stp.Install(ctx)
} }
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment