@@ -29,6 +29,10 @@ import (
29
29
30
30
const OCI_SCHEME = "oci"
31
31
const DEFAULT_OCI_ARTIFACT_TYPE = "application/vnd.oci.image.layer.v1.tar"
32
+ const (
33
+ OciErrorCodeNameUnknown = "NAME_UNKNOWN"
34
+ OciErrorCodeRepoNotFound = "NOT_FOUND"
35
+ )
32
36
33
37
// Login will login 'hostname' by 'username' and 'password'.
34
38
func Login (hostname , username , password string , setting * settings.Settings ) error {
@@ -180,6 +184,21 @@ func (ociClient *OciClient) TheLatestTag() (string, error) {
180
184
return tagSelected , nil
181
185
}
182
186
187
+ // RepoIsNotExist will check if the error is caused by the repo not found.
188
+ func RepoIsNotExist (err error ) bool {
189
+ errRes , ok := err .(* errcode.ErrorResponse )
190
+ if ok {
191
+ if len (errRes .Errors ) == 1 &&
192
+ // docker.io and gchr.io will return NAME_UNKNOWN
193
+ (errRes .Errors [0 ].Code == OciErrorCodeNameUnknown ||
194
+ // harbor will return NOT_FOUND
195
+ errRes .Errors [0 ].Code == OciErrorCodeRepoNotFound ) {
196
+ return true
197
+ }
198
+ }
199
+ return false
200
+ }
201
+
183
202
// ContainsTag will check if the tag exists in the repo.
184
203
func (ociClient * OciClient ) ContainsTag (tag string ) (bool , * reporter.KpmEvent ) {
185
204
var exists bool
@@ -191,11 +210,8 @@ func (ociClient *OciClient) ContainsTag(tag string) (bool, *reporter.KpmEvent) {
191
210
192
211
if err != nil {
193
212
// If the repo with tag is not found, return false.
194
- errRes , ok := err .(* errcode.ErrorResponse )
195
- if ok {
196
- if len (errRes .Errors ) == 1 && errRes .Errors [0 ].Code == errcode .ErrorCodeNameUnknown {
197
- return false , nil
198
- }
213
+ if RepoIsNotExist (err ) {
214
+ return false , nil
199
215
}
200
216
// If the user not login, return error.
201
217
return false , reporter .NewErrorEvent (
0 commit comments