-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Copyright © 2022 Meroxa, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package fromplugin | ||
|
||
import ( | ||
"github.com/conduitio/conduit-connector-protocol/cpluginv1" | ||
"github.com/conduitio/conduit/pkg/plugin" | ||
) | ||
|
||
func _() { | ||
// An "invalid array index" compiler error signifies that the constant values have changed. | ||
var vTypes [1]struct{} | ||
_ = vTypes[int(cpluginv1.ValidationTypeRequired)-int(plugin.ValidationTypeRequired)] | ||
Check failure on line 25 in pkg/plugin/builtin/v1/internal/fromplugin/specifier.go GitHub Actions / test
|
||
_ = vTypes[int(cpluginv1.ValidationTypeLessThan)-int(plugin.ValidationTypeLessThan)] | ||
Check failure on line 26 in pkg/plugin/builtin/v1/internal/fromplugin/specifier.go GitHub Actions / test
|
||
_ = vTypes[int(cpluginv1.ValidationTypeGreaterThan)-int(plugin.ValidationTypeGreaterThan)] | ||
Check failure on line 27 in pkg/plugin/builtin/v1/internal/fromplugin/specifier.go GitHub Actions / test
|
||
_ = vTypes[int(cpluginv1.ValidationTypeInclusion)-int(plugin.ValidationTypeInclusion)] | ||
Check failure on line 28 in pkg/plugin/builtin/v1/internal/fromplugin/specifier.go GitHub Actions / test
|
||
_ = vTypes[int(cpluginv1.ValidationTypeExclusion)-int(plugin.ValidationTypeExclusion)] | ||
Check failure on line 29 in pkg/plugin/builtin/v1/internal/fromplugin/specifier.go GitHub Actions / test
|
||
_ = vTypes[int(cpluginv1.ValidationTypeRegex)-int(plugin.ValidationTypeRegex)] | ||
Check failure on line 30 in pkg/plugin/builtin/v1/internal/fromplugin/specifier.go GitHub Actions / test
|
||
// parameter types | ||
_ = vTypes[int(cpluginv1.ParameterTypeString)-int(plugin.ParameterTypeString)] | ||
Check failure on line 32 in pkg/plugin/builtin/v1/internal/fromplugin/specifier.go GitHub Actions / test
|
||
_ = vTypes[int(cpluginv1.ParameterTypeInt)-int(plugin.ParameterTypeInt)] | ||
_ = vTypes[int(cpluginv1.ParameterTypeFloat)-int(plugin.ParameterTypeFloat)] | ||
_ = vTypes[int(cpluginv1.ParameterTypeBool)-int(plugin.ParameterTypeBool)] | ||
_ = vTypes[int(cpluginv1.ParameterTypeFile)-int(plugin.ParameterTypeFile)] | ||
_ = vTypes[int(cpluginv1.ParameterTypeDuration)-int(plugin.ParameterTypeDuration)] | ||
} | ||
|
||
func SpecifierSpecifyResponse(in cpluginv1.SpecifierSpecifyResponse) (plugin.Specification, error) { | ||
Check failure on line 40 in pkg/plugin/builtin/v1/internal/fromplugin/specifier.go GitHub Actions / test
|
||
specMap := func(params map[string]cpluginv1.SpecifierParameter) map[string]plugin.Parameter { | ||
out := make(map[string]plugin.Parameter) | ||
for k, v := range params { | ||
out[k] = SpecifierParameter(v) | ||
} | ||
return out | ||
} | ||
|
||
return plugin.Specification{ | ||
Name: in.Name, | ||
Summary: in.Summary, | ||
Description: in.Description, | ||
Version: in.Version, | ||
Author: in.Author, | ||
DestinationParams: specMap(in.DestinationParams), | ||
SourceParams: specMap(in.SourceParams), | ||
}, nil | ||
} | ||
|
||
func SpecifierParameter(in cpluginv1.SpecifierParameter) plugin.Parameter { | ||
Check failure on line 60 in pkg/plugin/builtin/v1/internal/fromplugin/specifier.go GitHub Actions / test
|
||
validations := make([]plugin.Validation, len(in.Validations)) | ||
|
||
requiredExists := false | ||
for i, v := range in.Validations { | ||
validations[i] = plugin.Validation{ | ||
Type: plugin.ValidationType(v.Type), | ||
Value: v.Value, | ||
} | ||
if v.Type == cpluginv1.ValidationTypeRequired { | ||
requiredExists = true | ||
} | ||
} | ||
//nolint:staticcheck // needed for backward compatibility, in.Required is | ||
// converted to a validation of type ValidationTypeRequired making sure not | ||
// to duplicate the required validation | ||
if in.Required && !requiredExists { | ||
//nolint:makezero // false positive, we actually want to append here | ||
validations = append(validations, plugin.Validation{ | ||
Type: plugin.ValidationTypeRequired, | ||
}) | ||
} | ||
|
||
return plugin.Parameter{ | ||
Default: in.Default, | ||
Type: cpluginv1ParamTypeToPluginParamType(in.Type), | ||
Description: in.Description, | ||
Validations: validations, | ||
} | ||
} | ||
|
||
func cpluginv1ParamTypeToPluginParamType(t cpluginv1.ParameterType) plugin.ParameterType { | ||
// default type should be string | ||
if t == 0 { | ||
return plugin.ParameterTypeString | ||
} | ||
return plugin.ParameterType(t) | ||
} |