|
@@ -31,7 +31,7 @@ type cloudAcl struct {
|
|
|
|
|
|
func (e *EmqxCloud) GetType() servercfg.Emqxdeploy { return servercfg.EmqxCloudDeploy }
|
|
func (e *EmqxCloud) GetType() servercfg.Emqxdeploy { return servercfg.EmqxCloudDeploy }
|
|
|
|
|
|
-func (e *EmqxCloud) CreateEmqxUser(username, pass string, admin bool) error {
|
|
|
|
|
|
+func (e *EmqxCloud) CreateEmqxUser(username, pass string) error {
|
|
|
|
|
|
payload := userCreateReq{
|
|
payload := userCreateReq{
|
|
UserName: username,
|
|
UserName: username,
|
|
@@ -62,35 +62,92 @@ func (e *EmqxCloud) CreateEmqxUser(username, pass string, admin bool) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
-func (e *EmqxCloud) CreateEmqxDefaultAuthenticator() error { return nil } // ignore
|
|
|
|
-
|
|
|
|
-func (e *EmqxCloud) CreateEmqxDefaultAuthorizer() error { return nil } // ignore
|
|
|
|
|
|
+func (e *EmqxCloud) CreateEmqxUserforServer() error {
|
|
|
|
+ payload := userCreateReq{
|
|
|
|
+ UserName: servercfg.GetMqUserName(),
|
|
|
|
+ Password: servercfg.GetMqPassword(),
|
|
|
|
+ }
|
|
|
|
+ data, _ := json.Marshal(payload)
|
|
|
|
+ client := &http.Client{}
|
|
|
|
+ req, err := http.NewRequest(http.MethodPost, e.URL, strings.NewReader(string(data)))
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ req.SetBasicAuth(e.AppID, e.AppSecret)
|
|
|
|
+ req.Header.Add("Content-Type", "application/json")
|
|
|
|
|
|
-func (e *EmqxCloud) CreateDefaultDenyRule() error {
|
|
|
|
- return nil
|
|
|
|
-}
|
|
|
|
|
|
+ res, err := client.Do(req)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ defer res.Body.Close()
|
|
|
|
|
|
-func (e *EmqxCloud) CreateHostACL(hostID, serverName string) error {
|
|
|
|
|
|
+ body, err := io.ReadAll(res.Body)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ if res.StatusCode != http.StatusOK {
|
|
|
|
+ return errors.New("request failed " + string(body))
|
|
|
|
+ }
|
|
|
|
+ // add acls
|
|
acls := []cloudAcl{
|
|
acls := []cloudAcl{
|
|
{
|
|
{
|
|
- UserName: hostID,
|
|
|
|
- Topic: fmt.Sprintf("peers/host/%s/%s", hostID, serverName),
|
|
|
|
|
|
+ UserName: servercfg.GetMqUserName(),
|
|
|
|
+ Topic: fmt.Sprintf("update/%s/#", servercfg.GetServer()),
|
|
Access: "allow",
|
|
Access: "allow",
|
|
- Action: "pubsub",
|
|
|
|
|
|
+ Action: "sub",
|
|
},
|
|
},
|
|
{
|
|
{
|
|
- UserName: hostID,
|
|
|
|
- Topic: fmt.Sprintf("host/update/%s/%s", hostID, serverName),
|
|
|
|
|
|
+ UserName: servercfg.GetMqUserName(),
|
|
|
|
+ Topic: fmt.Sprintf("host/serverupdate/%s/#", servercfg.GetServer()),
|
|
Access: "allow",
|
|
Access: "allow",
|
|
- Action: "pubsub",
|
|
|
|
|
|
+ Action: "sub",
|
|
},
|
|
},
|
|
{
|
|
{
|
|
- UserName: hostID,
|
|
|
|
- Topic: fmt.Sprintf("host/serverupdate/%s/%s", serverName, hostID),
|
|
|
|
|
|
+ UserName: servercfg.GetMqUserName(),
|
|
|
|
+ Topic: fmt.Sprintf("signal/%s/#", servercfg.GetServer()),
|
|
Access: "allow",
|
|
Access: "allow",
|
|
- Action: "pubsub",
|
|
|
|
|
|
+ Action: "sub",
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ UserName: servercfg.GetMqUserName(),
|
|
|
|
+ Topic: fmt.Sprintf("metrics/%s/#", servercfg.GetServer()),
|
|
|
|
+ Access: "allow",
|
|
|
|
+ Action: "sub",
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ UserName: servercfg.GetMqUserName(),
|
|
|
|
+ Topic: "peers/host/#",
|
|
|
|
+ Access: "allow",
|
|
|
|
+ Action: "pub",
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ UserName: servercfg.GetMqUserName(),
|
|
|
|
+ Topic: "node/update/#",
|
|
|
|
+ Access: "allow",
|
|
|
|
+ Action: "pub",
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+
|
|
|
|
+ UserName: servercfg.GetMqUserName(),
|
|
|
|
+ Topic: "host/update/#",
|
|
|
|
+ Access: "allow",
|
|
|
|
+ Action: "pub",
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ return e.createacls(acls)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (e *EmqxCloud) CreateEmqxDefaultAuthenticator() error { return nil } // ignore
|
|
|
|
+
|
|
|
|
+func (e *EmqxCloud) CreateEmqxDefaultAuthorizer() error { return nil } // ignore
|
|
|
|
+
|
|
|
|
+func (e *EmqxCloud) CreateDefaultDenyRule() error {
|
|
|
|
+ return nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func (e *EmqxCloud) createacls(acls []cloudAcl) error {
|
|
payload, err := json.Marshal(acls)
|
|
payload, err := json.Marshal(acls)
|
|
if err != nil {
|
|
if err != nil {
|
|
return err
|
|
return err
|
|
@@ -118,6 +175,31 @@ func (e *EmqxCloud) CreateHostACL(hostID, serverName string) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func (e *EmqxCloud) CreateHostACL(hostID, serverName string) error {
|
|
|
|
+ acls := []cloudAcl{
|
|
|
|
+ {
|
|
|
|
+ UserName: hostID,
|
|
|
|
+ Topic: fmt.Sprintf("peers/host/%s/%s", hostID, serverName),
|
|
|
|
+ Access: "allow",
|
|
|
|
+ Action: "sub",
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ UserName: hostID,
|
|
|
|
+ Topic: fmt.Sprintf("host/update/%s/%s", hostID, serverName),
|
|
|
|
+ Access: "allow",
|
|
|
|
+ Action: "sub",
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ UserName: hostID,
|
|
|
|
+ Topic: fmt.Sprintf("host/serverupdate/%s/%s", serverName, hostID),
|
|
|
|
+ Access: "allow",
|
|
|
|
+ Action: "pub",
|
|
|
|
+ },
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return e.createacls(acls)
|
|
|
|
+}
|
|
|
|
+
|
|
func (e *EmqxCloud) AppendNodeUpdateACL(hostID, nodeNetwork, nodeID, serverName string) error {
|
|
func (e *EmqxCloud) AppendNodeUpdateACL(hostID, nodeNetwork, nodeID, serverName string) error {
|
|
acls := []cloudAcl{
|
|
acls := []cloudAcl{
|
|
{
|
|
{
|