dynsec_clients.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. package mq
  2. // MqClient - type for taking in an MQ client's data
  3. type MqClient struct {
  4. ID string
  5. Text string
  6. Password string
  7. Networks []string
  8. }
  9. // ModifyClient - modifies an existing client's network roles
  10. func ModifyClient(client *MqClient) error {
  11. roles := []MqDynSecRole{
  12. {
  13. Rolename: HostRole,
  14. Priority: -1,
  15. },
  16. }
  17. for i := range client.Networks {
  18. roles = append(roles, MqDynSecRole{
  19. Rolename: client.Networks[i],
  20. Priority: -1,
  21. },
  22. )
  23. }
  24. event := MqDynsecPayload{
  25. Commands: []MqDynSecCmd{
  26. {
  27. Command: ModifyClientCmd,
  28. Username: client.ID,
  29. Textname: client.Text,
  30. Roles: roles,
  31. Groups: make([]MqDynSecGroup, 0),
  32. },
  33. },
  34. }
  35. return publishEventToDynSecTopic(event)
  36. }
  37. // DeleteMqClient - removes a client from the DynSec system
  38. func DeleteMqClient(hostID string) error {
  39. event := MqDynsecPayload{
  40. Commands: []MqDynSecCmd{
  41. {
  42. Command: DeleteClientCmd,
  43. Username: hostID,
  44. },
  45. },
  46. }
  47. return publishEventToDynSecTopic(event)
  48. }
  49. // CreateMqClient - creates an MQ DynSec client
  50. func CreateMqClient(client *MqClient) error {
  51. roles := []MqDynSecRole{
  52. {
  53. Rolename: HostRole,
  54. Priority: -1,
  55. },
  56. }
  57. for i := range client.Networks {
  58. roles = append(roles, MqDynSecRole{
  59. Rolename: client.Networks[i],
  60. Priority: -1,
  61. },
  62. )
  63. }
  64. event := MqDynsecPayload{
  65. Commands: []MqDynSecCmd{
  66. {
  67. Command: CreateClientCmd,
  68. Username: client.ID,
  69. Password: client.Password,
  70. Textname: client.Text,
  71. Roles: roles,
  72. Groups: make([]MqDynSecGroup, 0),
  73. },
  74. },
  75. }
  76. return publishEventToDynSecTopic(event)
  77. }