api/artifact: add ArtifactDir helper func
To make it easier to construct just the directory path for the artifact (relative to the storage base path).
This commit is contained in:
parent
ecaa98012f
commit
f8c4bd31ca
|
@ -17,7 +17,8 @@ limitations under the License.
|
|||
package v1alpha1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
)
|
||||
|
@ -44,8 +45,15 @@ type Artifact struct {
|
|||
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
|
||||
}
|
||||
|
||||
// ArtifactDir returns the artifact dir path in the form of
|
||||
// <source-kind>/<source-namespace>/<source-name>
|
||||
func ArtifactDir(kind, namespace, name string) string {
|
||||
kind = strings.ToLower(kind)
|
||||
return path.Join(kind, namespace, name)
|
||||
}
|
||||
|
||||
// ArtifactPath returns the artifact path in the form of
|
||||
// <source-kind>/<source-namespace>/<source-name>/<artifact-filename>
|
||||
func ArtifactPath(kind, namespace, name, filename string) string {
|
||||
return fmt.Sprintf("%s/%s/%s/%s", kind, namespace, name, filename)
|
||||
return path.Join(ArtifactDir(kind, namespace, name), filename)
|
||||
}
|
||||
|
|
|
@ -71,7 +71,6 @@ func NewStorage(basePath string, hostname string, timeout time.Duration) (*Stora
|
|||
|
||||
// ArtifactFor returns an artifact for the given Kubernetes object
|
||||
func (s *Storage) ArtifactFor(kind string, metadata metav1.Object, fileName, revision string) sourcev1.Artifact {
|
||||
kind = strings.ToLower(kind)
|
||||
path := sourcev1.ArtifactPath(kind, metadata.GetNamespace(), metadata.GetName(), fileName)
|
||||
localPath := filepath.Join(s.BasePath, path)
|
||||
url := fmt.Sprintf("http://%s/%s", s.Hostname, path)
|
||||
|
|
Loading…
Reference in New Issue