From bcb43a79476ecae5d9c2798830dc3728f6c94512 Mon Sep 17 00:00:00 2001 From: Tamal Saha Date: Sun, 29 Oct 2023 05:08:36 -0700 Subject: [PATCH] Add ImageRegistrySpec helpers Signed-off-by: Tamal Saha --- apis/shared/helpers.go | 63 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/apis/shared/helpers.go b/apis/shared/helpers.go index 41d35a841..884e0f5af 100644 --- a/apis/shared/helpers.go +++ b/apis/shared/helpers.go @@ -91,3 +91,66 @@ func (r ResourceLocator) GraphQuery(oid kmapi.OID) (string, map[string]interface } return "", nil, fmt.Errorf("unknown query type %+v, oid %s", r, oid) } + +func (r ImageRegistrySpec) DockerHubProxy() string { + addr := r.Proxies.DockerHub + if addr == "" { + addr = r.RegistryFQDN + } + addr = strings.TrimSpace(addr) + addr = strings.TrimSuffix(addr, "/") + return addr +} + +func (r ImageRegistrySpec) DockerLibraryProxy() string { + addr := r.Proxies.DockerLibrary + if addr == "" { + addr = r.Proxies.DockerHub + } + if addr == "" { + addr = r.RegistryFQDN + } + addr = strings.TrimSpace(addr) + addr = strings.TrimSuffix(addr, "/") + return addr +} + +func (r ImageRegistrySpec) GHCRProxy() string { + addr := r.Proxies.GHCR + if addr == "" { + addr = r.RegistryFQDN + } + addr = strings.TrimSpace(addr) + addr = strings.TrimSuffix(addr, "/") + return addr +} + +func (r ImageRegistrySpec) QuayProxy() string { + addr := r.Proxies.Quay + if addr == "" { + addr = r.RegistryFQDN + } + addr = strings.TrimSpace(addr) + addr = strings.TrimSuffix(addr, "/") + return addr +} + +func (r ImageRegistrySpec) KubernetesRegistryProxy() string { + addr := r.Proxies.Kubernetes + if addr == "" { + addr = r.RegistryFQDN + } + addr = strings.TrimSpace(addr) + addr = strings.TrimSuffix(addr, "/") + return addr +} + +func (r ImageRegistrySpec) AppsCodeRegistryProxy() string { + addr := r.Proxies.AppsCode + if addr == "" { + addr = r.RegistryFQDN + } + addr = strings.TrimSpace(addr) + addr = strings.TrimSuffix(addr, "/") + return addr +}