2022-12-29 01:10:03 +08:00
|
|
|
package mq
|
|
|
|
|
|
|
|
// MqClient - type for taking in an MQ client's data
|
|
|
|
type MqClient struct {
|
|
|
|
ID string
|
|
|
|
Text string
|
|
|
|
Password string
|
|
|
|
Networks []string
|
|
|
|
}
|
|
|
|
|
|
|
|
// ModifyClient - modifies an existing client's network roles
|
|
|
|
func ModifyClient(client *MqClient) error {
|
|
|
|
|
|
|
|
roles := []MqDynSecRole{
|
|
|
|
{
|
2023-01-04 12:35:05 +08:00
|
|
|
Rolename: HostGenericRole,
|
2022-12-29 01:10:03 +08:00
|
|
|
Priority: -1,
|
|
|
|
},
|
2023-01-19 00:39:29 +08:00
|
|
|
{
|
|
|
|
Rolename: getHostRoleName(client.ID),
|
|
|
|
Priority: -1,
|
|
|
|
},
|
2022-12-29 01:10:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
for i := range client.Networks {
|
|
|
|
roles = append(roles, MqDynSecRole{
|
|
|
|
Rolename: client.Networks[i],
|
|
|
|
Priority: -1,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
event := MqDynsecPayload{
|
|
|
|
Commands: []MqDynSecCmd{
|
|
|
|
{
|
|
|
|
Command: ModifyClientCmd,
|
|
|
|
Username: client.ID,
|
|
|
|
Textname: client.Text,
|
|
|
|
Roles: roles,
|
|
|
|
Groups: make([]MqDynSecGroup, 0),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return publishEventToDynSecTopic(event)
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteMqClient - removes a client from the DynSec system
|
|
|
|
func DeleteMqClient(hostID string) error {
|
2023-01-04 12:37:29 +08:00
|
|
|
deleteHostRole(hostID)
|
2022-12-29 01:10:03 +08:00
|
|
|
event := MqDynsecPayload{
|
|
|
|
Commands: []MqDynSecCmd{
|
|
|
|
{
|
|
|
|
Command: DeleteClientCmd,
|
|
|
|
Username: hostID,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return publishEventToDynSecTopic(event)
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateMqClient - creates an MQ DynSec client
|
|
|
|
func CreateMqClient(client *MqClient) error {
|
|
|
|
|
2023-01-04 12:35:05 +08:00
|
|
|
err := createHostRole(client.ID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-12-29 01:10:03 +08:00
|
|
|
roles := []MqDynSecRole{
|
|
|
|
{
|
2023-01-04 12:35:05 +08:00
|
|
|
Rolename: HostGenericRole,
|
|
|
|
Priority: -1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Rolename: getHostRoleName(client.ID),
|
2022-12-29 01:10:03 +08:00
|
|
|
Priority: -1,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range client.Networks {
|
|
|
|
roles = append(roles, MqDynSecRole{
|
|
|
|
Rolename: client.Networks[i],
|
|
|
|
Priority: -1,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
event := MqDynsecPayload{
|
|
|
|
Commands: []MqDynSecCmd{
|
|
|
|
{
|
|
|
|
Command: CreateClientCmd,
|
|
|
|
Username: client.ID,
|
|
|
|
Password: client.Password,
|
|
|
|
Textname: client.Text,
|
|
|
|
Roles: roles,
|
|
|
|
Groups: make([]MqDynSecGroup, 0),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return publishEventToDynSecTopic(event)
|
|
|
|
}
|