Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't enrich id if it's not provided #1845

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions pkg/provisioning/config/enrich.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ func enrichConnectors(mp []Connector, pipelineID string) []Connector {
if cfg.Settings == nil {
cfg.Settings = make(map[string]string)
}
// attach the pipelineID to the connectorID
cfg.ID = pipelineID + ":" + cfg.ID
if cfg.ID != "" {
// attach the pipelineID to the connectorID only if the connectorID
// is actually provided, otherwise the validation will miss it later
cfg.ID = pipelineID + ":" + cfg.ID
}
cfg.Processors = enrichProcessors(cfg.Processors, cfg.ID)
out[i] = cfg
}
Expand All @@ -86,7 +89,11 @@ func enrichProcessors(mp []Processor, parentID string) []Processor {
if cfg.Settings == nil {
cfg.Settings = make(map[string]string)
}
cfg.ID = parentID + ":" + cfg.ID
if cfg.ID != "" {
// attach the parentID to the processorID only if the processorID
// is actually provided, otherwise the validation will miss it later
cfg.ID = parentID + ":" + cfg.ID
}
out[i] = cfg
}
return out
Expand Down
6 changes: 3 additions & 3 deletions pkg/provisioning/config/enrich_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func TestEnrich_DefaultValues(t *testing.T) {
Status: "stopped",
Description: "empty",
Connectors: []Connector{
{ID: "con1"},
{ID: ""},
},
Processors: []Processor{
{ID: "proc1"},
Expand All @@ -151,8 +151,8 @@ func TestEnrich_DefaultValues(t *testing.T) {
},
Connectors: []Connector{
{
ID: "pipeline3:con1",
Name: "con1",
ID: "",
Name: "",
Settings: map[string]string{},
},
},
Expand Down
27 changes: 15 additions & 12 deletions pkg/provisioning/config/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,24 @@ func Validate(cfg Pipeline) error {
func validateConnectors(mp []Connector) []error {
var errs []error
ids := make(map[string]bool)
for _, cfg := range mp {
for i, cfg := range mp {
if cfg.ID == "" {
errs = append(errs, cerrors.Errorf(`id is mandatory: %w`, ErrMandatoryField))
errs = append(errs, cerrors.Errorf("connector %d: id is mandatory: %w", i+1, ErrMandatoryField))
}
if len(cfg.ID) > connector.IDLengthLimit {
errs = append(errs, connector.ErrIDOverLimit)
errs = append(errs, cerrors.Errorf("connector %q: %w", cfg.ID, connector.ErrIDOverLimit))
}
if len(cfg.Name) > connector.NameLengthLimit {
errs = append(errs, connector.ErrNameOverLimit)
errs = append(errs, cerrors.Errorf("connector %q: %w", cfg.ID, connector.ErrNameOverLimit))
}
if cfg.Plugin == "" {
errs = append(errs, cerrors.Errorf("connector %q: \"plugin\" is mandatory: %w", cfg.ID, ErrMandatoryField))
errs = append(errs, cerrors.Errorf(`connector %q: "plugin" is mandatory: %w`, cfg.ID, ErrMandatoryField))
}
if cfg.Type == "" {
errs = append(errs, cerrors.Errorf("connector %q: \"type\" is mandatory: %w", cfg.ID, ErrMandatoryField))
errs = append(errs, cerrors.Errorf(`connector %q: "type" is mandatory: %w`, cfg.ID, ErrMandatoryField))
}
if cfg.Type != "" && cfg.Type != TypeSource && cfg.Type != TypeDestination {
errs = append(errs, cerrors.Errorf("connector %q: \"type\" is invalid: %w", cfg.ID, ErrInvalidField))
errs = append(errs, cerrors.Errorf(`connector %q: "type" is invalid: %w`, cfg.ID, ErrInvalidField))
}

pErrs := validateProcessors(cfg.Processors)
Expand All @@ -82,7 +82,7 @@ func validateConnectors(mp []Connector) []error {
}

if ids[cfg.ID] {
errs = append(errs, cerrors.Errorf("connector %q: \"id\" must be unique: %w", cfg.ID, ErrDuplicateID))
errs = append(errs, cerrors.Errorf(`connector %q: "id" must be unique: %w`, cfg.ID, ErrDuplicateID))
}
ids[cfg.ID] = true
}
Expand All @@ -93,15 +93,18 @@ func validateConnectors(mp []Connector) []error {
func validateProcessors(mp []Processor) []error {
var errs []error
ids := make(map[string]bool)
for _, cfg := range mp {
for i, cfg := range mp {
if cfg.ID == "" {
errs = append(errs, cerrors.Errorf("processor %d: id is mandatory: %w", i+1, ErrMandatoryField))
}
if cfg.Plugin == "" {
errs = append(errs, cerrors.Errorf("processor %q: \"plugin\" is mandatory: %w", cfg.ID, ErrMandatoryField))
errs = append(errs, cerrors.Errorf(`processor %q: "plugin" is mandatory: %w`, cfg.ID, ErrMandatoryField))
}
if cfg.Workers < 0 {
errs = append(errs, cerrors.Errorf("processor %q: \"workers\" can't be negative: %w", cfg.ID, ErrInvalidField))
errs = append(errs, cerrors.Errorf(`processor %q: "workers" can't be negative: %w`, cfg.ID, ErrInvalidField))
}
if ids[cfg.ID] {
errs = append(errs, cerrors.Errorf("processor %q: \"id\" must be unique: %w", cfg.ID, ErrDuplicateID))
errs = append(errs, cerrors.Errorf(`processor %q: "id" must be unique: %w`, cfg.ID, ErrDuplicateID))
}
ids[cfg.ID] = true
}
Expand Down