feat: [CDE-722]: Truncate gitspace config identifier to accommodate the unique identifier and -disk suffixes (#3667)

* feat: [CDE-722]: Truncate gitspace config name to accommodate the unique identifier and -disk suffixes
This commit is contained in:
Vikyath Harekal 2025-04-11 12:59:41 +00:00 committed by Harness
parent 961687e883
commit 31519b68d3
2 changed files with 14 additions and 4 deletions

View File

@ -104,11 +104,10 @@ func (c *Controller) Create(
return nil, err return nil, err
} }
} }
suffixUID, err := gonanoid.Generate(gitspace.AllowedUIDAlphabet, 6) identifier, err := buildIdentifier(in.Identifier)
if err != nil { if err != nil {
return nil, fmt.Errorf("could not generate UID for gitspace config : %q %w", in.Identifier, err) return nil, fmt.Errorf("could not generate identrifier for gitspace config : %q %w", in.Identifier, err)
} }
identifier := strings.ToLower(in.Identifier + "-" + suffixUID)
now := time.Now().UnixMilli() now := time.Now().UnixMilli()
var gitspaceConfig *types.GitspaceConfig var gitspaceConfig *types.GitspaceConfig
// assume resource to be in same space if it's not explicitly specified. // assume resource to be in same space if it's not explicitly specified.
@ -281,3 +280,14 @@ func (c *Controller) sanitizeCreateInput(in *CreateInput) error {
return nil return nil
} }
func buildIdentifier(identifier string) (string, error) {
suffixUID, err := gonanoid.Generate(gitspace.AllowedUIDAlphabet, 6)
if err != nil {
return "", fmt.Errorf("could not generate UID for gitspace config : %q %w", identifier, err)
}
if len(identifier) > 50 {
identifier = identifier[:50]
}
return strings.ToLower(identifier + "-" + suffixUID), nil
}

View File

@ -95,7 +95,7 @@ const (
UpstreamConfigSourceDockerhub UpstreamConfigSource = "Dockerhub" UpstreamConfigSourceDockerhub UpstreamConfigSource = "Dockerhub"
UpstreamConfigSourceMavenCentral UpstreamConfigSource = "MavenCentral" UpstreamConfigSourceMavenCentral UpstreamConfigSource = "MavenCentral"
UpstreamConfigSourcePyPi UpstreamConfigSource = "PyPi" UpstreamConfigSourcePyPi UpstreamConfigSource = "PyPi"
UpstreamConfigSourceNpmjs UpstreamConfigSource = "NpmJs" UpstreamConfigSourceNpmjs UpstreamConfigSource = "NpmJs"
) )
// Defines values for WebhookExecResult. // Defines values for WebhookExecResult.