dynsec_clients.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. Rolename: getHostRoleName(client.ID),
  18. Priority: -1,
  19. },
  20. }
  21. for i := range client.Networks {
  22. roles = append(roles, MqDynSecRole{
  23. Rolename: client.Networks[i],
  24. Priority: -1,
  25. },
  26. )
  27. }
  28. event := MqDynsecPayload{
  29. Commands: []MqDynSecCmd{
  30. {
  31. Command: ModifyClientCmd,
  32. Username: client.ID,
  33. Textname: client.Text,
  34. Roles: roles,
  35. Groups: make([]MqDynSecGroup, 0),
  36. },
  37. },
  38. }
  39. return publishEventToDynSecTopic(event)
  40. }
  41. // DeleteMqClient - removes a client from the DynSec system
  42. func DeleteMqClient(hostID string) error {
  43. deleteHostRole(hostID)
  44. event := MqDynsecPayload{
  45. Commands: []MqDynSecCmd{
  46. {
  47. Command: DeleteClientCmd,
  48. Username: hostID,
  49. },
  50. },
  51. }
  52. return publishEventToDynSecTopic(event)
  53. }
  54. // CreateMqClient - creates an MQ DynSec client
  55. func CreateMqClient(client *MqClient) error {
  56. err := createHostRole(client.ID)
  57. if err != nil {
  58. return err
  59. }
  60. roles := []MqDynSecRole{
  61. {
  62. Rolename: HostGenericRole,
  63. Priority: -1,
  64. },
  65. {
  66. Rolename: getHostRoleName(client.ID),
  67. Priority: -1,
  68. },
  69. }
  70. for i := range client.Networks {
  71. roles = append(roles, MqDynSecRole{
  72. Rolename: client.Networks[i],
  73. Priority: -1,
  74. },
  75. )
  76. }
  77. event := MqDynsecPayload{
  78. Commands: []MqDynSecCmd{
  79. {
  80. Command: CreateClientCmd,
  81. Username: client.ID,
  82. Password: client.Password,
  83. Textname: client.Text,
  84. Roles: roles,
  85. Groups: make([]MqDynSecGroup, 0),
  86. },
  87. },
  88. }
  89. return publishEventToDynSecTopic(event)
  90. }