Skip to content

Commit c85f949

Browse files
authored
Use proxy registry custom domain not replicated app domain in LicenseDockerCfg template function (#2994)
1 parent d1810c0 commit c85f949

File tree

2 files changed

+15
-48
lines changed

2 files changed

+15
-48
lines changed

api/pkg/template/license.go

Lines changed: 5 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ import (
44
"encoding/base64"
55
"encoding/json"
66
"fmt"
7-
"net/url"
87

98
"github.com/replicatedhq/embedded-cluster/api/internal/utils"
109
"github.com/replicatedhq/embedded-cluster/pkg/netutils"
1110
"github.com/replicatedhq/embedded-cluster/pkg/release"
12-
kotsv1beta1 "github.com/replicatedhq/kotskinds/apis/kots/v1beta1"
1311
)
1412

1513
func (e *Engine) licenseFieldValue(name string) string {
@@ -80,7 +78,7 @@ func (e *Engine) licenseDockerCfg() (string, error) {
8078
auth := fmt.Sprintf("%s:%s", e.license.Spec.LicenseID, e.license.Spec.LicenseID)
8179
encodedAuth := base64.StdEncoding.EncodeToString([]byte(auth))
8280

83-
registryProxyInfo := getRegistryProxyInfo(e.license, e.releaseData)
81+
registryProxyInfo := getRegistryProxyInfo(e.releaseData)
8482

8583
dockercfg := map[string]any{
8684
"auths": map[string]any{
@@ -104,41 +102,12 @@ func (e *Engine) licenseDockerCfg() (string, error) {
104102
type registryProxyInfo struct {
105103
Registry string
106104
Proxy string
107-
Upstream string
108105
}
109106

110-
func getRegistryProxyInfo(license *kotsv1beta1.License, releaseData *release.ReleaseData) *registryProxyInfo {
111-
registryProxyInfo := getRegistryProxyInfoFromLicense(license)
112-
107+
func getRegistryProxyInfo(releaseData *release.ReleaseData) *registryProxyInfo {
113108
ecDomains := utils.GetDomains(releaseData)
114-
registryProxyInfo.Proxy = ecDomains.ReplicatedAppDomain
115-
registryProxyInfo.Registry = ecDomains.ReplicatedRegistryDomain
116-
return registryProxyInfo
117-
}
118-
119-
func getRegistryProxyInfoFromLicense(license *kotsv1beta1.License) *registryProxyInfo {
120-
defaultInfo := &registryProxyInfo{
121-
Upstream: "registry.replicated.com",
122-
Registry: "registry.replicated.com",
123-
Proxy: "proxy.replicated.com",
124-
}
125-
126-
if license == nil {
127-
return defaultInfo
128-
}
129-
130-
u, err := url.Parse(license.Spec.Endpoint)
131-
if err != nil {
132-
return defaultInfo
133-
}
134-
135-
if u.Hostname() == "staging.replicated.app" {
136-
return &registryProxyInfo{
137-
Upstream: "registry.staging.replicated.com",
138-
Registry: "registry.staging.replicated.com",
139-
Proxy: "proxy.staging.replicated.com",
140-
}
109+
return &registryProxyInfo{
110+
Proxy: ecDomains.ProxyRegistryDomain,
111+
Registry: ecDomains.ReplicatedRegistryDomain,
141112
}
142-
143-
return defaultInfo
144113
}

api/pkg/template/license_test.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ func TestEngine_LicenseDockerCfg(t *testing.T) {
214214
DefaultDomains: release.Domains{
215215
ReplicatedAppDomain: "my-app.example.com",
216216
ReplicatedRegistryDomain: "registry.my-app.example.com",
217+
ProxyRegistryDomain: "proxy.my-app.example.com",
217218
},
218219
},
219220
}
@@ -239,7 +240,7 @@ func TestEngine_LicenseDockerCfg(t *testing.T) {
239240
require.True(t, ok, "auths should be a map")
240241

241242
// Check that both proxy and registry domains are present
242-
proxyAuth, ok := auths["my-app.example.com"].(map[string]interface{})
243+
proxyAuth, ok := auths["proxy.my-app.example.com"].(map[string]interface{})
243244
require.True(t, ok, "proxy auth should exist")
244245
require.Contains(t, proxyAuth, "auth")
245246

@@ -322,12 +323,8 @@ func TestEngine_LicenseDockerCfgStagingEndpoint(t *testing.T) {
322323
auths, ok := dockercfg["auths"].(map[string]interface{})
323324
require.True(t, ok, "auths should be a map")
324325

325-
// With staging endpoint, should use staging domains:
326-
// - Proxy: ReplicatedAppDomain (default: "replicated.app") - not affected by staging
327-
// - Registry: ReplicatedRegistryDomain (default: "registry.replicated.com") - not affected by staging
328-
// Note: The staging endpoint only affects the getRegistryProxyInfoFromLicense function,
329-
// but when there's no release data, utils.GetDomains returns default domains
330-
proxyAuth, ok := auths["replicated.app"].(map[string]interface{})
326+
// The (staging) endpoint in license should not affect the domains being used
327+
proxyAuth, ok := auths["proxy.replicated.com"].(map[string]interface{})
331328
require.True(t, ok, "staging proxy auth should exist")
332329
require.Contains(t, proxyAuth, "auth")
333330

@@ -364,6 +361,7 @@ func TestEngine_LicenseDockerCfgStagingEndpointWithReleaseData(t *testing.T) {
364361
DefaultDomains: release.Domains{
365362
ReplicatedAppDomain: "staging-app.example.com",
366363
ReplicatedRegistryDomain: "staging-registry.example.com",
364+
ProxyRegistryDomain: "staging-proxy.example.com",
367365
},
368366
},
369367
}
@@ -388,15 +386,15 @@ func TestEngine_LicenseDockerCfgStagingEndpointWithReleaseData(t *testing.T) {
388386
auths, ok := dockercfg["auths"].(map[string]interface{})
389387
require.True(t, ok, "auths should be a map")
390388

391-
// With staging endpoint and release data, should use release data domains:
392-
// - Proxy: ReplicatedAppDomain from release data
389+
// Domains should come from release data and not be affected by the staging endpoint in license:
390+
// - Proxy: ProxyRegistryDomain from release data
393391
// - Registry: ReplicatedRegistryDomain from release data
394-
proxyAuth, ok := auths["staging-app.example.com"].(map[string]interface{})
395-
require.True(t, ok, "staging proxy auth should exist")
392+
proxyAuth, ok := auths["staging-proxy.example.com"].(map[string]interface{})
393+
require.True(t, ok, "custom staging proxy auth should exist")
396394
require.Contains(t, proxyAuth, "auth")
397395

398396
registryAuth, ok := auths["staging-registry.example.com"].(map[string]interface{})
399-
require.True(t, ok, "staging registry auth should exist")
397+
require.True(t, ok, "custom staging registry auth should exist")
400398
require.Contains(t, registryAuth, "auth")
401399

402400
// Verify the auth value is base64 encoded license:license

0 commit comments

Comments
 (0)