diff --git a/cmd/registry/serve.go b/cmd/registry/serve.go index f0c24f9..ccbd734 100644 --- a/cmd/registry/serve.go +++ b/cmd/registry/serve.go @@ -421,7 +421,7 @@ func initializeUI(config *configuration.Configuration, oauthApp *oauth.App, refr &uihandlers.HomeHandler{ DB: database, Templates: templates, - RegistryURL: baseURL, + RegistryURL: uihandlers.TrimRegistryURL(baseURL), }, )).Methods("GET") @@ -429,7 +429,7 @@ func initializeUI(config *configuration.Configuration, oauthApp *oauth.App, refr &uihandlers.RecentPushesHandler{ DB: database, Templates: templates, - RegistryURL: baseURL, + RegistryURL: uihandlers.TrimRegistryURL(baseURL), }, )).Methods("GET") @@ -440,13 +440,13 @@ func initializeUI(config *configuration.Configuration, oauthApp *oauth.App, refr authRouter.Handle("/images", &uihandlers.ImagesHandler{ DB: database, Templates: templates, - RegistryURL: baseURL, + RegistryURL: uihandlers.TrimRegistryURL(baseURL), }).Methods("GET") authRouter.Handle("/settings", &uihandlers.SettingsHandler{ Templates: templates, Refresher: refresher, - RegistryURL: baseURL, + RegistryURL: uihandlers.TrimRegistryURL(baseURL), }).Methods("GET") authRouter.Handle("/api/profile/default-hold", &uihandlers.UpdateDefaultHoldHandler{ diff --git a/pkg/appview/appview.go b/pkg/appview/appview.go index 2f89f25..5c310a4 100644 --- a/pkg/appview/appview.go +++ b/pkg/appview/appview.go @@ -71,7 +71,7 @@ func Templates() (*template.Template, error) { return string([]rune(s)[0]) }, - "trimPrefix": func(s, prefix string) string { + "trimPrefix": func(prefix, s string) string { if len(s) >= len(prefix) && s[:len(prefix)] == prefix { return s[len(prefix):] } diff --git a/pkg/appview/handlers/settings.go b/pkg/appview/handlers/settings.go index 836e19c..6929843 100644 --- a/pkg/appview/handlers/settings.go +++ b/pkg/appview/handlers/settings.go @@ -59,12 +59,10 @@ func (h *SettingsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { PDSEndpoint string DefaultHold string } - SessionExpiry time.Time Query string RegistryURL string }{ User: user, - SessionExpiry: time.Now().Add(24 * time.Hour), // TODO: Get from actual session Query: r.URL.Query().Get("q"), RegistryURL: h.RegistryURL, } diff --git a/pkg/appview/handlers/util.go b/pkg/appview/handlers/util.go new file mode 100644 index 0000000..ca1555d --- /dev/null +++ b/pkg/appview/handlers/util.go @@ -0,0 +1,11 @@ +package handlers + +import "strings" + +// TrimRegistryURL removes http:// or https:// prefix from a URL +// for use in Docker commands where only the host:port is needed +func TrimRegistryURL(url string) string { + url = strings.TrimPrefix(url, "https://") + url = strings.TrimPrefix(url, "http://") + return url +} diff --git a/pkg/appview/templates/pages/settings.html b/pkg/appview/templates/pages/settings.html index cbaae7a..8e79a8d 100644 --- a/pkg/appview/templates/pages/settings.html +++ b/pkg/appview/templates/pages/settings.html @@ -73,19 +73,19 @@
  • Configure Docker to use the helper. Add to ~/.docker/config.json:
    {
       "credHelpers": {
    -    "{{ .RegistryURL | trimPrefix "http://" | trimPrefix "https://" }}": "atcr"
    +    "{{ .RegistryURL }}": "atcr"
       }
     }
  • Run any Docker command: -
    docker pull {{ .RegistryURL | trimPrefix "http://" | trimPrefix "https://" }}/{{ .Profile.Handle }}/myimage
    +
    docker pull {{ .RegistryURL }}/{{ .Profile.Handle }}/myimage
  • Browser will open for authorization - click Approve
  • Done! Device is automatically authorized
  • - Fallback: Use app-password with docker login {{ .RegistryURL | trimPrefix "http://" | trimPrefix "https://" }} for quick start (no device tracking) + Fallback: Use app-password with docker login {{ .RegistryURL }} for quick start (no device tracking)
    @@ -108,22 +108,6 @@ - - -
    -

    OAuth Session

    -
    - - {{ .Profile.Handle }} -
    -
    - - -
    - Re-authenticate -