drone/registry/app/api/utils/path_utils.go
Shivanand Sonnad 8b277e62d7 feat: [AH-1223]: Implement delete version for non oci package types (#3684)
* feat: [AH-1223]: fix failing go lint
* feat: [AH-1223]: fix failing go lint
* feat: [AH-1223]: file name change
* feat: [AH-1223]: file name change
* feat: [AH-1223]: fix go lint errors
* feat: [AH-1223]: add RPM package type in switch case
* feat: [AH-1223]: cascade delete download_stats and bandwidth_stats
* feat: [AH-1223]: resolve PR comments
* feat: [AH-1223]: resolve PR comments
* feat: [AH-1223]: fix failing go lint checks
* feat: [AH-1223]: add different switch case for delete based on package type
* feat: [AH-1223]: Implement delete version for non oci package types
2025-04-18 09:01:07 +00:00

66 lines
2.1 KiB
Go

// Copyright 2023 Harness, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package utils
import (
"fmt"
"strings"
"github.com/harness/gitness/registry/app/api/openapi/contracts/artifact"
)
func GetMavenFilePath(imageName string, version string) string {
artifactName := strings.ReplaceAll(imageName, ".", "/")
artifactName = strings.ReplaceAll(artifactName, ":", "/")
filePathPrefix := "/" + artifactName
if version != "" {
filePathPrefix += "/" + version
}
return filePathPrefix
}
func GetGenericFilePath(imageName string, version string) string {
filePathPrefix := "/" + imageName
if version != "" {
filePathPrefix += "/" + version
}
return filePathPrefix
}
func GetFilePath(
packageType artifact.PackageType,
imageName string, version string) (string, error) {
switch packageType {
case artifact.PackageTypeDOCKER:
return "", fmt.Errorf("docker package type not supported")
case artifact.PackageTypeHELM:
return "", fmt.Errorf("helm package type not supported")
case artifact.PackageTypeNPM:
return GetGenericFilePath(imageName, version), nil
case artifact.PackageTypeMAVEN:
return GetMavenFilePath(imageName, version), nil
case artifact.PackageTypePYTHON:
return GetGenericFilePath(imageName, version), nil
case artifact.PackageTypeGENERIC:
return GetGenericFilePath(imageName, version), nil
case artifact.PackageTypeNUGET:
return "", fmt.Errorf("nuget package type not supported")
case artifact.PackageTypeRPM:
return "", fmt.Errorf("rpm package type not supported")
default:
return "", fmt.Errorf("unsupported package type: %s", packageType)
}
}