operator_meta.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 meta
  15. import (
  16. "bytes"
  17. "os"
  18. "path"
  19. "strings"
  20. "github.com/lf-edge/ekuiper/internal/conf"
  21. )
  22. type fileContent []byte
  23. func readOpsMetaDir() ([]fileContent, error) {
  24. var filesByte []fileContent
  25. confDir, err := conf.GetConfLoc()
  26. if nil != err {
  27. return nil, err
  28. }
  29. dir := path.Join(confDir, "ops")
  30. files, err := os.ReadDir(dir)
  31. if nil != err {
  32. return nil, err
  33. }
  34. for _, file := range files {
  35. fname := file.Name()
  36. if !strings.HasSuffix(fname, ".json") {
  37. continue
  38. }
  39. filesByte = append(filesByte, readOpsMetaFile(path.Join(dir, fname)))
  40. }
  41. return filesByte, nil
  42. }
  43. func readOpsMetaFile(filePath string) fileContent {
  44. fiName := path.Base(filePath)
  45. sliByte, _ := os.ReadFile(filePath)
  46. conf.Log.Infof("operatorMeta file : %s", fiName)
  47. return sliByte
  48. }
  49. func GetOperators() bytes.Buffer {
  50. files, _ := readOpsMetaDir()
  51. return ConstructJsonArray(files)
  52. }