Skip to content

Commit

Permalink
rename packages
Browse files Browse the repository at this point in the history
  • Loading branch information
agalitsyn committed Jan 23, 2023
1 parent 7e8ffb5 commit b3e7879
Show file tree
Hide file tree
Showing 28 changed files with 397 additions and 386 deletions.
6 changes: 3 additions & 3 deletions cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
useraction "soldr/pkg/app/api/user_action"
"soldr/pkg/app/api/worker"
"soldr/pkg/app/api/worker/events"
"soldr/pkg/log"
"soldr/pkg/logtooling"
"soldr/pkg/mysql"
"soldr/pkg/observability"
"soldr/pkg/secret"
Expand Down Expand Up @@ -161,8 +161,8 @@ func main() {
MaxAge: 14,
Compress: true,
}
logrus.SetLevel(log.ParseLevel(cfg.Log.Level))
logrus.SetFormatter(log.ParseFormat(cfg.Log.Format))
logrus.SetLevel(logtooling.ParseLevel(cfg.Log.Level))
logrus.SetFormatter(logtooling.ParseFormat(cfg.Log.Format))
logrus.SetOutput(io.MultiWriter(os.Stdout, logFile))

dsn := fmt.Sprintf("%s:%s@%s/%s?parseTime=true",
Expand Down
20 changes: 11 additions & 9 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ import (
"soldr/pkg/app/server/mmodule"
"soldr/pkg/controller"
"soldr/pkg/db"
"soldr/pkg/filestorage"
"soldr/pkg/filestorage/fs"
"soldr/pkg/filestorage/s3"
"soldr/pkg/observability"
"soldr/pkg/s3"
"soldr/pkg/system"
"soldr/pkg/utils"
"soldr/pkg/vxproto"
Expand Down Expand Up @@ -104,7 +106,7 @@ func (s *Server) Init(env svc.Environment) (err error) {
case loaderTypeFS:
cl, err = controller.NewConfigFromFS(s.config.Base)
case loaderTypeS3:
var s3ConnParams *s3.RemoteStorageConfig
var s3ConnParams *s3.Config
s3ConnParams, err = s3ConnParamsFromConfig(&s.config.S3)
if err != nil {
err = fmt.Errorf("failed to compose s3 connection params from config: %w", err)
Expand Down Expand Up @@ -133,7 +135,7 @@ func (s *Server) Init(env svc.Environment) (err error) {
case loaderTypeFS:
fl, err = controller.NewFilesFromFS(s.config.Base)
case loaderTypeS3:
var s3ConnParams *s3.RemoteStorageConfig
var s3ConnParams *s3.Config
s3ConnParams, err = s3ConnParamsFromConfig(&s.config.S3)
if err != nil {
err = fmt.Errorf("failed to compose s3 connection params from config: %w", err)
Expand All @@ -150,7 +152,7 @@ func (s *Server) Init(env svc.Environment) (err error) {
logger.Info("modules files loader was created")

utils.RemoveUnusedTempDir()
store, err := s3.NewRemoteStorage(&s3.RemoteStorageConfig{
store, err := s3.New(&s3.Config{
Endpoint: s.config.S3.Endpoint,
AccessKey: s.config.S3.AccessKey,
SecretKey: s.config.S3.SecretKey,
Expand Down Expand Up @@ -214,7 +216,7 @@ func dsnFromConfig(c *config.DB) (*db.DSN, error) {
}, nil
}

func s3ConnParamsFromConfig(c *config.S3) (*s3.RemoteStorageConfig, error) {
func s3ConnParamsFromConfig(c *config.S3) (*s3.Config, error) {
if c == nil {
return nil, fmt.Errorf("passed config is nil")
}
Expand All @@ -230,19 +232,19 @@ func s3ConnParamsFromConfig(c *config.S3) (*s3.RemoteStorageConfig, error) {
if len(c.BucketName) == 0 {
return nil, fmt.Errorf("bucket name is empty")
}
return &s3.RemoteStorageConfig{
return &s3.Config{
Endpoint: c.Endpoint,
AccessKey: c.AccessKey,
SecretKey: c.SecretKey,
BucketName: c.BucketName,
}, nil
}

func initCertProvider(c *config.CertsConfig, s3FileReader s3.FileReader) (certs.Provider, error) {
func initCertProvider(c *config.CertsConfig, s3FileReader filestorage.Reader) (certs.Provider, error) {
if c == nil {
return nil, fmt.Errorf("passed config object is nil")
}
createFileProvider := func(store s3.FileReader, base string) (certs.Provider, error) {
createFileProvider := func(store filestorage.Reader, base string) (certs.Provider, error) {
conf := &certsConfig.Config{
StaticProvider: &certsConfig.StaticProvider{
Reader: store,
Expand All @@ -257,7 +259,7 @@ func initCertProvider(c *config.CertsConfig, s3FileReader s3.FileReader) (certs.
}
switch c.Type {
case loaderTypeFS:
store, err := s3.NewLocalStorage()
store, err := fs.New()
if err != nil {
return nil, fmt.Errorf("failed to initialize a file store: %w", err)
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/app/api/client/agent_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import (

"soldr/pkg/app/api/models"
"soldr/pkg/app/api/storage/mem"
"soldr/pkg/filestorage"
"soldr/pkg/filestorage/s3"
"soldr/pkg/mysql"
"soldr/pkg/s3"
"soldr/pkg/secret"
)

Expand Down Expand Up @@ -70,7 +71,7 @@ func (c *AgentServerClient) GetDB(ctx context.Context, hash string) (*gorm.DB, e
return dbWithORM, nil
}

func (c *AgentServerClient) GetS3(hash string) (s3.FileStorage, error) {
func (c *AgentServerClient) GetS3(hash string) (filestorage.Storage, error) {
s3Conn, err := c.s3Conns.Get(hash)
if err == nil {
return s3Conn, nil
Expand All @@ -81,9 +82,9 @@ func (c *AgentServerClient) GetS3(hash string) (s3.FileStorage, error) {
return nil, fmt.Errorf("could not get service by hash '%s': %w", hash, err)
}

s3Conn, err = s3.NewRemoteStorage(service.Info.S3.ToS3ConnParams())
s3Conn, err = s3.New(service.Info.S3.ToS3ConnParams())
if err != nil {
return nil, fmt.Errorf("could not create RemoteStorage client: %w", err)
return nil, fmt.Errorf("could not create Client client: %w", err)
}
c.s3Conns.Set(hash, s3Conn)

Expand Down
8 changes: 4 additions & 4 deletions pkg/app/api/models/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/jinzhu/gorm"

"soldr/pkg/s3"
"soldr/pkg/filestorage/s3"
)

// ServiceInfoDB is model to contain service external config to connetion to DB
Expand All @@ -23,7 +23,7 @@ func (sidb ServiceInfoDB) Valid() error {
return validate.Struct(sidb)
}

// ServiceInfoS3 is model to contain service external config to connetion to RemoteStorage
// ServiceInfoS3 is model to contain service external config to connetion to Client
type ServiceInfoS3 struct {
Endpoint string `form:"endpoint" json:"endpoint" validate:"max=100,required"`
AccessKey string `form:"access_key" json:"access_key" validate:"max=50,required"`
Expand All @@ -32,8 +32,8 @@ type ServiceInfoS3 struct {
}

// ToS3ConnParams is a helper function to convert the structure to the vxcommon version one
func (sis3 *ServiceInfoS3) ToS3ConnParams() *s3.RemoteStorageConfig {
return &s3.RemoteStorageConfig{
func (sis3 *ServiceInfoS3) ToS3ConnParams() *s3.Config {
return &s3.Config{
Endpoint: sis3.Endpoint,
AccessKey: sis3.AccessKey,
SecretKey: sis3.SecretKey,
Expand Down
34 changes: 17 additions & 17 deletions pkg/app/api/modules/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"soldr/pkg/app/api/models"
"soldr/pkg/app/api/utils"
"soldr/pkg/crypto"
"soldr/pkg/s3"
"soldr/pkg/filestorage/s3"
)

type agentModuleDetails struct {
Expand Down Expand Up @@ -50,9 +50,9 @@ func joinPath(args ...string) string {
}

func CopyModuleAFilesToInstanceS3(mi *models.ModuleInfo, sv *models.Service) error {
gS3, err := s3.NewRemoteStorage(nil)
gS3, err := s3.New(nil)
if err != nil {
return errors.New("failed to initialize global RemoteStorage driver: " + err.Error())
return errors.New("failed to initialize global Client driver: " + err.Error())
}

mfiles, err := gS3.ReadDirRec(joinPath(mi.Name, mi.Version.String()))
Expand All @@ -67,24 +67,24 @@ func CopyModuleAFilesToInstanceS3(mi *models.ModuleInfo, sv *models.Service) err
return errors.New("failed to read utils files: " + err.Error())
}

iS3, err := s3.NewRemoteStorage(sv.Info.S3.ToS3ConnParams())
iS3, err := s3.New(sv.Info.S3.ToS3ConnParams())
if err != nil {
return errors.New("failed to initialize instance RemoteStorage driver: " + err.Error())
return errors.New("failed to initialize instance Client driver: " + err.Error())
}

if iS3.RemoveDir(joinPath(mi.Name, mi.Version.String())); err != nil {
return errors.New("failed to remove module directory from instance RemoteStorage: " + err.Error())
return errors.New("failed to remove module directory from instance Client: " + err.Error())
}

for fpath, fdata := range mfiles {
if err := iS3.WriteFile(joinPath(mi.Name, mi.Version.String(), fpath), fdata); err != nil {
return errors.New("failed to write system module file to RemoteStorage: " + err.Error())
return errors.New("failed to write system module file to Client: " + err.Error())
}
}

for fpath, fdata := range ufiles {
if err := iS3.WriteFile(joinPath("utils", fpath), fdata); err != nil {
return errors.New("failed to write utils file to RemoteStorage: " + err.Error())
return errors.New("failed to write utils file to Client: " + err.Error())
}
}

Expand Down Expand Up @@ -156,8 +156,8 @@ func clearMapKeysList(curMap, defMap map[string]interface{}) map[string]interfac

// args:
//
// cc is Current module RemoteStorageConfig from old module version which we tried to keep
// dc is Default module RemoteStorageConfig from actual module version which we are using as a reference
// cc is Current module Config from old module version which we tried to keep
// dc is Default module Config from actual module version which we are using as a reference
// sh is JSON Schema structure from actual module version which wa are using to check result document
func mergeModuleACurrentConfig(cc, dc models.ModuleConfig, sh models.Schema) models.ModuleConfig {
// add new config values from default
Expand Down Expand Up @@ -204,8 +204,8 @@ func mergeModuleASecureCurrentConfig(cc, dc models.ModuleSecureConfig, sh models

// args:
//
// cac is Current Action RemoteStorageConfig from old module version which we tried to keep
// dac is Default Action RemoteStorageConfig from actual module version which we are using as a reference
// cac is Current Action Config from old module version which we tried to keep
// dac is Default Action Config from actual module version which we are using as a reference
// sh is JSON Schema structure from actual module version which wa are using to check result document
func mergeModuleACurrentActionConfig(cac, dac models.ActionConfig, sh models.Schema) models.ActionConfig {
for acn, daci := range dac {
Expand Down Expand Up @@ -239,8 +239,8 @@ func mergeModuleACurrentActionConfig(cac, dac models.ActionConfig, sh models.Sch

// args:
//
// ceci is Current Event RemoteStorageConfig Item from old module version which we tried to keep
// deci is Default Event RemoteStorageConfig Item from actual module version which we are using as a reference
// ceci is Current Event Config Item from old module version which we tried to keep
// deci is Default Event Config Item from actual module version which we are using as a reference
// sh is JSON Schema structure from actual module version which wa are using to check result document
func mergeModuleAEventConfigItem(ceci, deci models.EventConfigItem, sh models.Schema) models.EventConfigItem {
reci := models.EventConfigItem{}
Expand All @@ -256,8 +256,8 @@ func mergeModuleAEventConfigItem(ceci, deci models.EventConfigItem, sh models.Sc

// args:
//
// cec is Current Event RemoteStorageConfig from old module version which we tried to keep
// dec is Default Event RemoteStorageConfig from actual module version which we are using as a reference
// cec is Current Event Config from old module version which we tried to keep
// dec is Default Event Config from actual module version which we are using as a reference
// sh is JSON Schema structure from actual module version which wa are using to check result document
func mergeModuleACurrentEventConfig(cec, dec models.EventConfig, sh models.Schema) models.EventConfig {
ecsh := copySchema(&sh.Type, models.GetECSDefinitions(sh.Definitions))
Expand Down Expand Up @@ -291,7 +291,7 @@ func mergeModuleACurrentEventConfig(cec, dec models.EventConfig, sh models.Schem
// args:
//
// dd is Dynamic Dependencies from old module version which we tried to keep
// cec is Current Event RemoteStorageConfig which was got after merging to default (result Current Event RemoteStorageConfig)
// cec is Current Event Config which was got after merging to default (result Current Event Config)
func clearModuleADynamicDependencies(dd models.Dependencies, cec models.EventConfig) models.Dependencies {
rdd := models.Dependencies{}
checkDepInActions := func(ec models.EventConfigItem, moduleName string) bool {
Expand Down
6 changes: 3 additions & 3 deletions pkg/app/api/server/private/agents.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"soldr/pkg/app/api/server/response"
"soldr/pkg/app/api/storage"
useraction "soldr/pkg/app/api/user_action"
"soldr/pkg/semver"
"soldr/pkg/semvertooling"
)

type agentDetails struct {
Expand Down Expand Up @@ -158,8 +158,8 @@ func getAgentConsistency(modules []models.ModuleAShort, agent *models.Agent) (bo
}

var sdeps bool
switch semver.CompareVersions(agent.Version, dep.MinAgentVersion) {
case semver.TargetVersionEmpty, semver.VersionsEqual, semver.SourceVersionGreat:
switch semvertooling.CompareVersions(agent.Version, dep.MinAgentVersion) {
case semvertooling.TargetVersionEmpty, semvertooling.VersionsEqual, semvertooling.SourceVersionGreat:
sdeps = true
default:
rdeps = false
Expand Down
6 changes: 3 additions & 3 deletions pkg/app/api/server/private/binaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"soldr/pkg/app/api/server/response"
storage2 "soldr/pkg/app/api/storage"
useraction "soldr/pkg/app/api/user_action"
"soldr/pkg/s3"
"soldr/pkg/filestorage/s3"
)

type binaries struct {
Expand Down Expand Up @@ -215,9 +215,9 @@ func (s *BinariesService) GetAgentBinaryFile(c *gin.Context) {
return
}

s3Client, err := s3.NewRemoteStorage(nil)
s3Client, err := s3.New(nil)
if err != nil {
logger.FromContext(c).WithError(err).Errorf("error openning connection to RemoteStorage")
logger.FromContext(c).WithError(err).Errorf("error openning connection to Client")
response.Error(c, response.ErrInternal, err)
return
}
Expand Down
Loading

0 comments on commit b3e7879

Please sign in to comment.