dynsec_clients.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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: HostGenericRole,
  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. deleteHostRole(hostID)
  40. event := MqDynsecPayload{
  41. Commands: []MqDynSecCmd{
  42. {
  43. Command: DeleteClientCmd,
  44. Username: hostID,
  45. },
  46. },
  47. }
  48. return publishEventToDynSecTopic(event)
  49. }
  50. // CreateMqClient - creates an MQ DynSec client
  51. func CreateMqClient(client *MqClient) error {
  52. err := createHostRole(client.ID)
  53. if err != nil {
  54. return err
  55. }
  56. roles := []MqDynSecRole{
  57. {
  58. Rolename: HostGenericRole,
  59. Priority: -1,
  60. },
  61. {
  62. Rolename: getHostRoleName(client.ID),
  63. Priority: -1,
  64. },
  65. }
  66. for i := range client.Networks {
  67. roles = append(roles, MqDynSecRole{
  68. Rolename: client.Networks[i],
  69. Priority: -1,
  70. },
  71. )
  72. }
  73. event := MqDynsecPayload{
  74. Commands: []MqDynSecCmd{
  75. {
  76. Command: CreateClientCmd,
  77. Username: client.ID,
  78. Password: client.Password,
  79. Textname: client.Text,
  80. Roles: roles,
  81. Groups: make([]MqDynSecGroup, 0),
  82. },
  83. },
  84. }
  85. return publishEventToDynSecTopic(event)
  86. }