Skip to content

Commit

Permalink
Merge pull request #70 from GreenmaskIO/interaction_api_fixes
Browse files Browse the repository at this point in the history
Added interaction API default if not set
  • Loading branch information
wwoytenko committed Apr 17, 2024
2 parents 2ff47db + b3c6ae7 commit e514ff4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
3 changes: 0 additions & 3 deletions internal/db/postgres/transformers/custom/custom_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ func (ct *CmdTransformer) Init(ctx context.Context) (err error) {
args := make([]string, len(ct.args))
copy(args, ct.args)
args = append(args, TransformArgName)
if err != nil {
return fmt.Errorf("cannot get metatda: %w", err)
}
err = ct.BaseInit(ct.executable, args)
if err != nil {
return err
Expand Down
39 changes: 33 additions & 6 deletions pkg/toolkit/definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,48 @@ type DriverParams struct {
CsvAttributesFormat string `json:"csv_attributes_format,omitempty"`
}

// Validate - validate driver params and set default values if needed
func (dp *DriverParams) Validate() error {
if dp.Name != JsonModeName && dp.Name != CsvModeName && dp.Name != TextModeName {
return fmt.Errorf(`unexpected driver name "%s"`, dp.Name)
}

if dp.JsonDataFormat != JsonBytesDataFormatName && dp.JsonDataFormat != JsonTextDataFormatName {
return fmt.Errorf(`unexpected format "%s"`, dp.JsonDataFormat)
}
if dp.JsonAttributesFormat != JsonAttributesNamesFormatName && dp.JsonAttributesFormat != JsonAttributesIndexesFormatName {
return fmt.Errorf(`unexpected json_attributes_format "%s"`, dp.JsonAttributesFormat)
switch dp.Name {
case JsonModeName:
return dp.validateJson()
case CsvModeName:
return dp.validateCsv()
}

return nil
}

func (dp *DriverParams) validateCsv() error {
if dp.CsvAttributesFormat != CsvAttributesDirectNumeratingFormatName && dp.CsvAttributesFormat != CsvAttributesConfigNumeratingFormatName {
return fmt.Errorf(`unexpected csv_attributes_format "%s"`, dp.CsvAttributesFormat)
if dp.CsvAttributesFormat == "" {
dp.CsvAttributesFormat = CsvAttributesDirectNumeratingFormatName
} else {
return fmt.Errorf(`unexpected csv_attributes_format "%s"`, dp.CsvAttributesFormat)
}
}
return nil
}

func (dp *DriverParams) validateJson() error {
if dp.JsonDataFormat != JsonBytesDataFormatName && dp.JsonDataFormat != JsonTextDataFormatName {
if dp.JsonDataFormat == "" {
dp.JsonDataFormat = JsonBytesDataFormatName
} else {
return fmt.Errorf(`unexpected format "%s"`, dp.JsonDataFormat)
}
}
if dp.JsonAttributesFormat != JsonAttributesNamesFormatName && dp.JsonAttributesFormat != JsonAttributesIndexesFormatName {
if dp.JsonAttributesFormat == "" {
dp.JsonAttributesFormat = JsonAttributesIndexesFormatName
} else {
return fmt.Errorf(`unexpected json_attributes_format "%s"`, dp.JsonAttributesFormat)
}
}
return nil
}

Expand Down

0 comments on commit e514ff4

Please sign in to comment.