emqx_cloud.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package mq
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "io"
  6. "net/http"
  7. "strings"
  8. "github.com/gravitl/netmaker/servercfg"
  9. )
  10. type EmqxCloud struct {
  11. URL string
  12. AppID string
  13. AppSecret string
  14. }
  15. type userCreateReq struct {
  16. UserName string `json:"username"`
  17. Password string `json:"password"`
  18. }
  19. func (e *EmqxCloud) GetType() servercfg.Emqxdeploy { return servercfg.EmqxCloudDeploy }
  20. func (e *EmqxCloud) CreateEmqxUser(username, pass string, admin bool) error {
  21. payload := userCreateReq{
  22. UserName: username,
  23. Password: pass,
  24. }
  25. data, _ := json.Marshal(payload)
  26. client := &http.Client{}
  27. req, err := http.NewRequest(http.MethodPost, e.URL, strings.NewReader(string(data)))
  28. if err != nil {
  29. fmt.Println(err)
  30. return err
  31. }
  32. req.SetBasicAuth(e.AppID, e.AppSecret)
  33. req.Header.Add("Content-Type", "application/json")
  34. res, err := client.Do(req)
  35. if err != nil {
  36. fmt.Println(err)
  37. return err
  38. }
  39. defer res.Body.Close()
  40. body, err := io.ReadAll(res.Body)
  41. if err != nil {
  42. fmt.Println(err)
  43. return err
  44. }
  45. fmt.Println(string(body))
  46. return nil
  47. }
  48. func (e *EmqxCloud) CreateEmqxDefaultAuthenticator() error { return nil }
  49. func (e *EmqxCloud) CreateEmqxDefaultAuthorizer() error { return nil }
  50. func (e *EmqxCloud) CreateDefaultDenyRule() error { return nil }
  51. func (e *EmqxCloud) CreateHostACL(hostID, serverName string) error { return nil }
  52. func (e *EmqxCloud) AppendNodeUpdateACL(hostID, nodeNetwork, nodeID, serverName string) error {
  53. return nil
  54. }
  55. func (e *EmqxCloud) GetUserACL(username string) (*aclObject, error) { return nil, nil }
  56. func (e *EmqxCloud) DeleteEmqxUser(username string) error { return nil }