in tools/mconnect/commands/groups/groups.go [137:168]
func (gc *mcGroupCreator) updateLabel(ctx context.Context, groupID string) error {
groupPath := gc.pal.Path() + "/groups/" + groupID
getReq := &migrationcenterpb.GetGroupRequest{Name: groupPath}
oldGroup, err := gc.client.GetGroup(ctx, getReq)
if err != nil {
return err
}
labels := oldGroup.Labels
// If there are no labels the Labels field will be nil
if labels == nil {
labels = make(map[string]string)
}
// Check if this group was already created by this tool.
if _, ok := labels[LabelKey]; ok {
fmt.Println(messages.GroupDetectedLabel{Group: groupID, Label: LabelKey})
return nil
}
labels[LabelKey] = labelValue
updateReq := &migrationcenterpb.UpdateGroupRequest{UpdateMask: &fieldmaskpb.FieldMask{Paths: []string{"labels"}}, Group: &migrationcenterpb.Group{Name: groupPath, Labels: labels}}
op, err := gc.client.UpdateGroup(ctx, updateReq)
if err != nil {
return fmt.Errorf("failed updating group: '%v', err: %v", groupID, err)
}
_, err = op.Wait(ctx)
if err != nil {
return fmt.Errorf("failed updating group: '%v', err: %v", groupID, err)
}
fmt.Println(messages.GroupUpdated{Name: groupID})
return nil
}