diff --git a/pkg/system/system.go b/pkg/system/system.go index 03cdd219cd..65ee020a49 100644 --- a/pkg/system/system.go +++ b/pkg/system/system.go @@ -39,6 +39,7 @@ const ( // it's very helpful to check daemon's record in database. endpointDaemonRecords string = "/api/v1/daemons/records" endpointDaemonsUpgrade string = "/api/v1/daemons/upgrade" + endpointRemoteAuth string = "/api/v1/remote/auth" ) const defaultErrorCode string = "Unknown" @@ -65,6 +66,12 @@ type upgradeRequest struct { Policy string `json:"policy"` } +type ImagePullCreds struct { + Host string `json:"host"` + User string `json:"user"` + Secret string `json:"secret"` +} + type errorMessage struct { Code string `json:"code"` Message string `json:"message"` @@ -152,6 +159,7 @@ func (sc *Controller) registerRouter() { sc.router.HandleFunc(endpointDaemons, sc.describeDaemons()).Methods(http.MethodGet) sc.router.HandleFunc(endpointDaemonsUpgrade, sc.upgradeDaemons()).Methods(http.MethodPut) sc.router.HandleFunc(endpointDaemonRecords, sc.getDaemonRecords()).Methods(http.MethodGet) + sc.router.HandleFunc(endpointRemoteAuth, sc.storeRemoteAuth()).Methods(http.MethodPut) } func (sc *Controller) describeDaemons() func(w http.ResponseWriter, r *http.Request) { @@ -210,6 +218,30 @@ func (sc *Controller) getDaemonRecords() func(w http.ResponseWriter, r *http.Req } } +func (sc *Controller) storeRemoteAuth() func(w http.ResponseWriter, r *http.Request) { + return func(w http.ResponseWriter, r *http.Request) { + var err error + var statusCode int + var creds ImagePullCreds + + defer func() { + if err != nil { + m := newErrorMessage(err.Error()) + http.Error(w, m.encode(), statusCode) + } + }() + + err = json.NewDecoder(r.Body).Decode(&creds) + if err != nil { + log.L.Errorf("request %v, decode error %s", r, err) + statusCode = http.StatusBadRequest + return + } + + log.L.Infof("Stored registry credential %+v", creds) + } +} + // PUT /api/v1/nydusd/upgrade // body: {"nydusd_path": "/path/to/new/nydusd", "version": "v2.2.1", "policy": "rolling"} // Possible policy: rolling, immediate