fix: enforce unique agent names per workspace (#5497)

This commit is contained in:
Dean Sheather
2022-12-22 15:20:35 -08:00
committed by GitHub
parent 461c0d0d39
commit 3e2e2ac49e
2 changed files with 16 additions and 1 deletions

View File

@ -854,8 +854,16 @@ func InsertWorkspaceResource(ctx context.Context, db database.Store, jobID uuid.
}
snapshot.WorkspaceResources = append(snapshot.WorkspaceResources, telemetry.ConvertWorkspaceResource(resource))
appSlugs := make(map[string]struct{})
var (
agentNames = make(map[string]struct{})
appSlugs = make(map[string]struct{})
)
for _, prAgent := range protoResource.Agents {
if _, ok := agentNames[prAgent.Name]; ok {
return xerrors.Errorf("duplicate agent name %q", prAgent.Name)
}
agentNames[prAgent.Name] = struct{}{}
var instanceID sql.NullString
if prAgent.GetInstanceId() != "" {
instanceID = sql.NullString{