mirror of
https://github.com/redhat-developer/odo.git
synced 2025-10-19 03:06:19 +03:00
* fix to prioritize newly added registry Signed-off-by: anandrkskd <anandrkskd@gmail.com> * update RegistryList func to reverse the list and return []Registry Signed-off-by: anandrkskd <anandrkskd@gmail.com> * update the usage of RegistryList Signed-off-by: anandrkskd <anandrkskd@gmail.com> * update unit test and mock Signed-off-by: anandrkskd <anandrkskd@gmail.com> * fix: lint error and check for empty registry list Signed-off-by: anandrkskd <anandrkskd@gmail.com> * add documentation Signed-off-by: anandrkskd <anandrkskd@gmail.com> Signed-off-by: anandrkskd <anandrkskd@gmail.com>
38 lines
813 B
Go
38 lines
813 B
Go
package registry
|
|
|
|
import (
|
|
"fmt"
|
|
url2 "net/url"
|
|
"strings"
|
|
|
|
"github.com/redhat-developer/odo/pkg/preference"
|
|
)
|
|
|
|
// IsSecure checks if the registry is secure
|
|
func IsSecure(prefClient preference.Client, registryName string) bool {
|
|
isSecure := false
|
|
if prefClient.RegistryList() != nil {
|
|
for _, registry := range prefClient.RegistryList() {
|
|
if registry.Name == registryName && registry.Secure {
|
|
isSecure = true
|
|
break
|
|
}
|
|
}
|
|
}
|
|
|
|
return isSecure
|
|
}
|
|
|
|
func IsGithubBasedRegistry(url string) (bool, error) {
|
|
pu, err := url2.Parse(url)
|
|
if err != nil {
|
|
return false, fmt.Errorf("unable to parse registry url %w", err)
|
|
}
|
|
for _, d := range []string{"github.com", "raw.githubusercontent.com"} {
|
|
if pu.Host == d || strings.HasSuffix(pu.Host, "."+d) {
|
|
return true, nil
|
|
}
|
|
}
|
|
return false, nil
|
|
}
|