|
@@ -5,21 +5,34 @@ import (
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
|
|
|
+ mqtt "github.com/eclipse/paho.mqtt.golang"
|
|
|
"github.com/gravitl/netmaker/logger"
|
|
|
)
|
|
|
|
|
|
-const DynamicSecTopic = "$CONTROL/dynamic-security/#"
|
|
|
+const DynamicSecSubTopic = "$CONTROL/dynamic-security/#"
|
|
|
+const DynamicSecPubTopic = "$CONTROL/dynamic-security/v1"
|
|
|
|
|
|
type DynSecActionType string
|
|
|
|
|
|
var (
|
|
|
CreateClient DynSecActionType = "CREATE_CLIENT"
|
|
|
+ DisableClient DynSecActionType = "DISABLE_CLIENT"
|
|
|
+ EnableClient DynSecActionType = "ENABLE_CLIENT"
|
|
|
+ DeleteClient DynSecActionType = "DELETE_CLIENT"
|
|
|
CreateAdminClient DynSecActionType = "CREATE_ADMIN_CLIENT"
|
|
|
+ ModifyClient DynSecActionType = "MODIFY_CLIENT"
|
|
|
DISABLE_EXISTING_ADMINS DynSecActionType = "DISABLE_EXISTING_ADMINS"
|
|
|
)
|
|
|
|
|
|
+var (
|
|
|
+ CreateClientCmd = "createClient"
|
|
|
+ DisableClientCmd = "disableClient"
|
|
|
+ DeleteClientCmd = "deleteClient"
|
|
|
+ ModifyClientCmd = "modifyClient"
|
|
|
+)
|
|
|
+
|
|
|
const mqDynSecAdmin = "Netmaker-Admin"
|
|
|
-const defaultAdminPassword = "hello-world"
|
|
|
+const defaultAdminPassword = "Netmaker-Admin"
|
|
|
|
|
|
type MqDynSecGroup struct {
|
|
|
Groupname string `json:"groupname"`
|
|
@@ -31,10 +44,19 @@ type MqDynSecRole struct {
|
|
|
Priority int `json:"priority"`
|
|
|
}
|
|
|
|
|
|
+type Acl struct {
|
|
|
+ AclType string `json:"acl_type"`
|
|
|
+ Topic string `json:"topic"`
|
|
|
+ Priority int `json:"priority"`
|
|
|
+ Allow bool `json:"allow"`
|
|
|
+}
|
|
|
+
|
|
|
type MqDynSecCmd struct {
|
|
|
Command string `json:"command"`
|
|
|
Username string `json:"username"`
|
|
|
Password string `json:"password"`
|
|
|
+ RoleName string `json:"rolename,omitempty"`
|
|
|
+ Acls []Acl `json:"acls,omitempty"`
|
|
|
Clientid string `json:"clientid"`
|
|
|
Textname string `json:"textname"`
|
|
|
Textdescription string `json:"textdescription"`
|
|
@@ -64,7 +86,7 @@ func DynamicSecManager(ctx context.Context) {
|
|
|
if err != nil {
|
|
|
continue
|
|
|
}
|
|
|
- if token := mqclient.Publish(DynamicSecTopic, 2, false, d); token.Error() != nil {
|
|
|
+ if token := mqclient.Publish(DynamicSecPubTopic, 2, false, d); token.Error() != nil {
|
|
|
logger.Log(0, fmt.Sprintf("failed to perform action [%s]: %v",
|
|
|
dynSecAction.ActionType, token.Error()))
|
|
|
}
|
|
@@ -72,3 +94,9 @@ func DynamicSecManager(ctx context.Context) {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func watchDynSecTopic(client mqtt.Client, msg mqtt.Message) {
|
|
|
+
|
|
|
+ logger.Log(1, fmt.Sprintf("----->WatchDynSecTopic Message: %+v", string(msg.Payload())))
|
|
|
+
|
|
|
+}
|