model.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2021 EMQ Technologies Co., Ltd.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package portable
  15. import (
  16. "fmt"
  17. "github.com/lf-edge/ekuiper/internal/plugin/portable/runtime"
  18. )
  19. type PluginInfo struct {
  20. runtime.PluginMeta
  21. Sources []string `json:"sources"`
  22. Sinks []string `json:"sinks"`
  23. Functions []string `json:"functions"`
  24. }
  25. var langMap = map[string]bool{
  26. "go": true,
  27. "python": true,
  28. }
  29. // Validate TODO validate duplication of source, sink and functions
  30. func (p *PluginInfo) Validate(expectedName string) error {
  31. if p.Name != expectedName {
  32. return fmt.Errorf("invalid plugin, expect name '%s' but got '%s'", expectedName, p.Name)
  33. }
  34. if p.Language == "" {
  35. return fmt.Errorf("invalid plugin, missing language")
  36. }
  37. if p.Executable == "" {
  38. return fmt.Errorf("invalid plugin, missing executable")
  39. }
  40. if len(p.Sources)+len(p.Sinks)+len(p.Functions) == 0 {
  41. return fmt.Errorf("invalid plugin, must define at lease one source, sink or function")
  42. }
  43. if l, ok := langMap[p.Language]; !ok || !l {
  44. return fmt.Errorf("invalid plugin, language '%s' is not supported", p.Language)
  45. }
  46. return nil
  47. }