Skip to content

Commit 2b80793

Browse files
author
Changwei Ge
committed
add http hanlder for store registry auth
Signed-off-by: Changwei Ge <[email protected]>
1 parent aea3720 commit 2b80793

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

pkg/system/system.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const (
3939
// it's very helpful to check daemon's record in database.
4040
endpointDaemonRecords string = "/api/v1/daemons/records"
4141
endpointDaemonsUpgrade string = "/api/v1/daemons/upgrade"
42+
endpointRemoteAuth string = "/api/v1/remote/auth"
4243
)
4344

4445
const defaultErrorCode string = "Unknown"
@@ -65,6 +66,12 @@ type upgradeRequest struct {
6566
Policy string `json:"policy"`
6667
}
6768

69+
type ImagePullCreds struct {
70+
Host string `json:"host"`
71+
User string `json:"user"`
72+
Secret string `json:"secret"`
73+
}
74+
6875
type errorMessage struct {
6976
Code string `json:"code"`
7077
Message string `json:"message"`
@@ -152,6 +159,7 @@ func (sc *Controller) registerRouter() {
152159
sc.router.HandleFunc(endpointDaemons, sc.describeDaemons()).Methods(http.MethodGet)
153160
sc.router.HandleFunc(endpointDaemonsUpgrade, sc.upgradeDaemons()).Methods(http.MethodPut)
154161
sc.router.HandleFunc(endpointDaemonRecords, sc.getDaemonRecords()).Methods(http.MethodGet)
162+
sc.router.HandleFunc(endpointRemoteAuth, sc.storeRemoteAuth()).Methods(http.MethodPut)
155163
}
156164

157165
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
210218
}
211219
}
212220

221+
func (sc *Controller) storeRemoteAuth() func(w http.ResponseWriter, r *http.Request) {
222+
return func(w http.ResponseWriter, r *http.Request) {
223+
var err error
224+
var statusCode int
225+
var creds ImagePullCreds
226+
227+
defer func() {
228+
if err != nil {
229+
m := newErrorMessage(err.Error())
230+
http.Error(w, m.encode(), statusCode)
231+
}
232+
}()
233+
234+
err = json.NewDecoder(r.Body).Decode(&creds)
235+
if err != nil {
236+
log.L.Errorf("request %v, decode error %s", r, err)
237+
statusCode = http.StatusBadRequest
238+
return
239+
}
240+
241+
log.L.Infof("Stored registry credential %+v", creds)
242+
}
243+
}
244+
213245
// PUT /api/v1/nydusd/upgrade
214246
// body: {"nydusd_path": "/path/to/new/nydusd", "version": "v2.2.1", "policy": "rolling"}
215247
// Possible policy: rolling, immediate

0 commit comments

Comments
 (0)