connectionMeta.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. "fmt"
  17. "strings"
  18. )
  19. func GetConnectionMeta(connectionName, language string) (ptrSourceProperty *uiSource, err error) {
  20. gSourcemetaLock.RLock()
  21. defer gSourcemetaLock.RUnlock()
  22. v, found := gSourcemetadata[connectionName+`.json`]
  23. if !found {
  24. return nil, fmt.Errorf(`%s%s`, getMsg(language, source, "not_found_plugin"), connectionName)
  25. }
  26. ret := make(map[string][]field)
  27. for kcfg, cfg := range v.ConfKeys {
  28. var sli []field
  29. for _, kvs := range cfg {
  30. if kvs.ConnectionRelated {
  31. sli = append(sli, kvs)
  32. }
  33. }
  34. ret[kcfg] = sli
  35. }
  36. ui := new(uiSource)
  37. *ui = *v
  38. ui.ConfKeys = ret
  39. return ui, nil
  40. }
  41. func GetConnectionPlugins() (sources []*pluginfo) {
  42. ConfigManager.lock.RLock()
  43. defer ConfigManager.lock.RUnlock()
  44. for key, conf := range ConfigManager.cfgOperators {
  45. if strings.HasPrefix(key, ConnectionCfgOperatorKeyPrefix) {
  46. plugName := conf.GetPluginName()
  47. uiSourceRepKey := plugName + `.json`
  48. gSourcemetaLock.RLock()
  49. v, found := gSourcemetadata[uiSourceRepKey]
  50. if !found {
  51. gSourcemetaLock.RUnlock()
  52. continue
  53. }
  54. gSourcemetaLock.RUnlock()
  55. node := new(pluginfo)
  56. node.Name = plugName
  57. if nil == v.About {
  58. continue
  59. }
  60. node.About = v.About
  61. i := 0
  62. for ; i < len(sources); i++ {
  63. if node.Name <= sources[i].Name {
  64. sources = append(sources, node)
  65. copy(sources[i+1:], sources[i:])
  66. sources[i] = node
  67. break
  68. }
  69. }
  70. if len(sources) == i {
  71. sources = append(sources, node)
  72. }
  73. }
  74. }
  75. return sources
  76. }