Skip to content

Commit

Permalink
add http hanlder for store registry auth
Browse files Browse the repository at this point in the history
Signed-off-by: Changwei Ge <[email protected]>
  • Loading branch information
changweige committed Mar 6, 2023
1 parent aea3720 commit 2b80793
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions pkg/system/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"`
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2b80793

Please sign in to comment.