|
| 1 | +/* |
| 2 | +Copyright 2022 The Flux authors |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package v1beta2 |
| 18 | + |
| 19 | +import ( |
| 20 | + "path" |
| 21 | + "strings" |
| 22 | + |
| 23 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 24 | +) |
| 25 | + |
| 26 | +// Artifact represents the output of a Source synchronisation. |
| 27 | +type Artifact struct { |
| 28 | + // Path is the relative file path of this Artifact. |
| 29 | + // It can be used to locate the Artifact file in the root of the Artifact |
| 30 | + // storage on the local file system of the controller managing the Source. |
| 31 | + // +required |
| 32 | + Path string `json:"path"` |
| 33 | + |
| 34 | + // URL is the HTTP address of this artifact. |
| 35 | + // It is used by the consumers of the artifacts to fetch and use the |
| 36 | + // artifacts. It is expected to be resolvable from within the cluster. |
| 37 | + // +required |
| 38 | + URL string `json:"url"` |
| 39 | + |
| 40 | + // Revision is a human readable identifier traceable in the origin source |
| 41 | + // system. It can be a Git commit SHA, Git tag, a Helm index timestamp, a Helm |
| 42 | + // chart version, etc. |
| 43 | + // +optional |
| 44 | + Revision string `json:"revision"` |
| 45 | + |
| 46 | + // Checksum is the SHA256 checksum of the artifact. |
| 47 | + // +optional |
| 48 | + Checksum string `json:"checksum"` |
| 49 | + |
| 50 | + // LastUpdateTime is the timestamp corresponding to the last update of this |
| 51 | + // artifact. |
| 52 | + // +required |
| 53 | + LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"` |
| 54 | +} |
| 55 | + |
| 56 | +// HasRevision returns true if the given revision matches the current Revision |
| 57 | +// of the Artifact. |
| 58 | +func (in *Artifact) HasRevision(revision string) bool { |
| 59 | + if in == nil { |
| 60 | + return false |
| 61 | + } |
| 62 | + return in.Revision == revision |
| 63 | +} |
| 64 | + |
| 65 | +// ArtifactDir returns the artifact dir path in the form of |
| 66 | +// <source-kind>/<source-namespace>/<source-name>. |
| 67 | +func ArtifactDir(kind, namespace, name string) string { |
| 68 | + kind = strings.ToLower(kind) |
| 69 | + return path.Join(kind, namespace, name) |
| 70 | +} |
| 71 | + |
| 72 | +// ArtifactPath returns the artifact path in the form of |
| 73 | +// <source-kind>/<source-namespace>/<source-name>/<artifact-filename>. |
| 74 | +func ArtifactPath(kind, namespace, name, filename string) string { |
| 75 | + return path.Join(ArtifactDir(kind, namespace, name), filename) |
| 76 | +} |
0 commit comments