SetHostGroups replaces host group memberships for a host.
(ctx context.Context, hostID string, groupIDs []string)
| 345 | |
| 346 | // SetHostGroups replaces host group memberships for a host. |
| 347 | func (s *HostsStore) SetHostGroups(ctx context.Context, hostID string, groupIDs []string) error { |
| 348 | d := s.db.DB(ctx) |
| 349 | if err := d.Queries.DeleteHostGroupMemberships(ctx, hostID); err != nil { |
| 350 | return err |
| 351 | } |
| 352 | for _, gid := range groupIDs { |
| 353 | if err := d.Queries.InsertHostGroupMembership(ctx, db.InsertHostGroupMembershipParams{ |
| 354 | ID: uuid.New().String(), |
| 355 | HostID: hostID, |
| 356 | HostGroupID: gid, |
| 357 | }); err != nil { |
| 358 | return err |
| 359 | } |
| 360 | } |
| 361 | return nil |
| 362 | } |
| 363 | |
| 364 | // SetHostGroupsBulk updates group memberships for multiple hosts. |
| 365 | func (s *HostsStore) SetHostGroupsBulk(ctx context.Context, hostIDs, groupIDs []string) error { |
no test coverage detected