Add upload token config validation

This commit is contained in:
2026-06-08 04:27:49 +00:00
parent 4fa7d1ebb5
commit 033b2e5015
11 changed files with 278 additions and 40 deletions

View File

@@ -49,22 +49,21 @@ func newUploadHTTPHandler(ctx context.Context, cfg config.Config, environment co
func resolveUploadTokens(cfg config.Config, environment config.Environment) (map[string]string, error) {
tokens := make(map[string]string)
for _, pipeline := range cfg.Pipelines {
if pipeline.Source.Backend != config.BackendHTTPUpload {
continue
}
tokenName := pipeline.Source.Upload.TokenEnv
token, ok := environment.Lookup(tokenName)
for _, uploadToken := range cfg.UploadTokens {
token, ok := environment.Lookup(uploadToken.TokenEnv)
if !ok {
return nil, fmt.Errorf("upload token environment variable %s is not set", tokenName)
return nil, fmt.Errorf("upload token environment variable %s is not set", uploadToken.TokenEnv)
}
if token == "" {
return nil, fmt.Errorf("upload token environment variable %s is empty", tokenName)
return nil, fmt.Errorf("upload token environment variable %s is empty", uploadToken.TokenEnv)
}
if len(uploadToken.AllowPipelines) != 1 {
return nil, fmt.Errorf("upload token %s must allow exactly one pipeline for legacy upload routing", uploadToken.ID)
}
if existing, exists := tokens[token]; exists {
return nil, fmt.Errorf("upload token environment variables for pipelines %s and %s resolve to the same value", existing, pipeline.ID)
return nil, fmt.Errorf("upload token environment variables for pipelines %s and %s resolve to the same value", existing, uploadToken.AllowPipelines[0])
}
tokens[token] = pipeline.ID
tokens[token] = uploadToken.AllowPipelines[0]
}
return tokens, nil
}