(ctx context.Context, req *api.AllocateIDsRequest)
| 18 | ) |
| 19 | |
| 20 | func (s *Server) AllocateIDs(ctx context.Context, req *api.AllocateIDsRequest) ( |
| 21 | *api.AllocateIDsResponse, error) { |
| 22 | |
| 23 | // For now, we only allow users in superadmin group to do this operation in v25 |
| 24 | if err := AuthSuperAdmin(ctx); err != nil { |
| 25 | s := status.Convert(err) |
| 26 | return nil, status.Error(s.Code(), |
| 27 | "v25.AllocateIDs can only be called by the superadmin group. "+s.Message()) |
| 28 | } |
| 29 | |
| 30 | num := &pb.Num{Val: req.HowMany} |
| 31 | switch req.LeaseType { |
| 32 | case api.LeaseType_NS: |
| 33 | num.Type = pb.Num_NS_ID |
| 34 | case api.LeaseType_UID: |
| 35 | num.Type = pb.Num_UID |
| 36 | case api.LeaseType_TS: |
| 37 | num.Type = pb.Num_TXN_TS |
| 38 | default: |
| 39 | return nil, fmt.Errorf("invalid lease type: %v", req.LeaseType) |
| 40 | } |
| 41 | |
| 42 | resp, err := worker.AssignUidsOverNetwork(ctx, num) |
| 43 | if err != nil { |
| 44 | return nil, errors.Wrapf(err, "Failed to allocate IDs") |
| 45 | } |
| 46 | |
| 47 | return &api.AllocateIDsResponse{Start: resp.StartId, End: resp.EndId}, nil |
| 48 | } |
nothing calls this directly
no test coverage detected