Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions agent/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@ import "fmt"

const MaxDeploymentLength = 64

const MaxAgentNameLength = 64

// ValidateAgentName enforces that an agent name is usable as a single URL path
// segment, so a worker can be addressed at /agents/{agent_name}/{deployment}/...
// Unlike a deployment, an agent name commonly contains underscores, so they are
// permitted here.
func ValidateAgentName(agentName string) error {
if len(agentName) > MaxAgentNameLength {
return fmt.Errorf("agent name exceeds %d bytes", MaxAgentNameLength)
}
for i := 0; i < len(agentName); i++ {
c := agentName[i]
switch {
case c >= 'a' && c <= 'z', c >= 'A' && c <= 'Z', c >= '0' && c <= '9', c == '-', c == '.', c == '_':
default:
return fmt.Errorf("agent name contains invalid character %q at position %d", c, i)
}
}
return nil
}

func ValidateDeployment(deployment string) error {
if deployment == "" {
return nil
Expand All @@ -14,10 +35,13 @@ func ValidateDeployment(deployment string) error {
for i := 0; i < len(deployment); i++ {
c := deployment[i]
switch {
case c >= 'a' && c <= 'z', c >= 'A' && c <= 'Z', c >= '0' && c <= '9', c == '-', c == '.':
case c == '_':
return fmt.Errorf("deployment contains reserved character %q", c)
case c <= ' ' || c == 0x7f:
return fmt.Errorf("deployment contains whitespace or control byte at position %d", i)
default:
// deployments appear as a single URL path segment (/agents/{deployment}/...),
// so only alphanumerics, '-' and '.' are accepted
return fmt.Errorf("deployment contains invalid character %q at position %d", c, i)
}
}
return nil
Expand Down
Loading
Loading