Files
tasks/service/frontend/validators.go
Roey BermanandGitHub 243effc6e1 Forbid the use of pborman/uuid and remove uses (#8541)
## What

Used the `depguard` linter to prevent importing the package and modified
all uses of it.

Also fixed a bug in the membership code where we were not updating the
next page token:

https://github.com/temporalio/temporal/pull/8541/files#diff-985dd64ffa4c6bfe0248b982dc47439b725862baa3e1f2c559b7ff522bf21969R350


## Why?

From the package README in GitHub:

> This package now leverages the github.com/google/uuid package (which
is based off an earlier version of this package).

Also, there's no point in having two uuid implementations in the
codebase.

## Test

Added the invalid import and confirmed it works:

```
../service/frontend/admin_handler_test.go:13:2: import 'github.com/pborman/uuid' is not allowed from list 'main': Importing github.com/pborman/uuid is disallowed; use github.com/google/uuid instead (depguard)
        _ "github.com/pborman/uuid"

```
2025-11-26 01:33:02 +00:00

95 lines
2.4 KiB
Go

package frontend
import (
"github.com/google/uuid"
commonpb "go.temporal.io/api/common/v1"
"go.temporal.io/api/serviceerror"
"go.temporal.io/api/workflowservice/v1"
"go.temporal.io/server/common/priorities"
)
var (
errFairnessKeyEmpty = serviceerror.NewInvalidArgument("fairness weight override key must not be empty")
)
func validateExecution(w *commonpb.WorkflowExecution) error {
if w == nil {
return errExecutionNotSet
}
if w.GetWorkflowId() == "" {
return errWorkflowIDNotSet
}
if w.GetRunId() != "" {
if err := uuid.Validate(w.GetRunId()); err != nil {
return errInvalidRunID
}
}
return nil
}
func validateRateLimit(update *workflowservice.UpdateTaskQueueConfigRequest_RateLimitUpdate, label string) error {
if update == nil || update.RateLimit == nil {
return nil
}
if update.RateLimit.GetRequestsPerSecond() < 0 {
return serviceerror.NewInvalidArgumentf("RequestsPerSecond for %s rate limit must be non-negative.", label)
}
return validateStringField(label+".Reason", update.GetReason(), maxReasonLength, false)
}
func validateStringField(fieldName string, value string, maxLen int, required bool) error {
if required && len(value) == 0 {
return serviceerror.NewInvalidArgumentf("%s field must be non-empty.", fieldName)
}
if len(value) > maxLen {
return serviceerror.NewInvalidArgumentf("%s field too long (max %d characters).", fieldName, maxLen)
}
return nil
}
func validateFairnessWeightUpdate(
set map[string]float32,
unset []string,
maxConfigLimit int,
) error {
total := len(set) + len(unset)
if total > maxConfigLimit {
return serviceerror.NewInvalidArgumentf(
"too many fairness weight overrides in request: got %d, maximum %d",
total, maxConfigLimit,
)
}
for k, w := range set {
if k == "" {
return errFairnessKeyEmpty
}
if err := priorities.ValidateFairnessKey(k); err != nil {
return err
}
if err := priorities.ValidateFairnessWeight(w); err != nil {
return serviceerror.NewInvalidArgumentf(
"invalid fairness weight weight for key %q: %v", k, err,
)
}
}
for _, k := range unset {
if k == "" {
return errFairnessKeyEmpty
}
if err := priorities.ValidateFairnessKey(k); err != nil {
return err
}
}
for _, u := range unset {
if _, ok := set[u]; ok {
return serviceerror.NewInvalidArgumentf(
"fairness weight override key %q present in both set and unset lists", u)
}
}
return nil
}