Conversation
There was a problem hiding this comment.
I've yet to crystalise on how to handle this bit. So it's missing from the PR for now
pkg/web/rest.go
Outdated
| authenticator := &AuthenticateServer{a} | ||
| authenticatePath, authenticateHandler := authenticatev1connect.NewAuthenticateServiceHandler(authenticator, connect.WithInterceptors(validate.NewInterceptor())) | ||
| // Recovery routes are the _only_ routes loaded in recovery mode. | ||
| recoveryRoutes := map[string]http.HandlerFunc{ | ||
| "POST /authenticate": a.authenticate, | ||
| authenticatePath: authenticateHandler, |
There was a problem hiding this comment.
Instead of having handler functions being defined on the api struct, the *Server structs accept the api context (as a) to use in their handler functions.
| type AuthenticateRequestBody struct { | ||
| Password string `json:"password"` | ||
| type AuthenticateServer struct { | ||
| a api |
There was a problem hiding this comment.
We take in the api struct as context for the AuthenticateServer struct so the Authenticate function can use it when handling requests
| body, err := io.ReadAll(r.Body) | ||
| if err != nil { | ||
| sendErrorResponse(w, http.StatusBadRequest, "Error reading request body") | ||
| return | ||
| } | ||
| defer r.Body.Close() | ||
|
|
||
| var requestBody AuthenticateRequestBody | ||
| if err := json.Unmarshal(body, &requestBody); err != nil { | ||
| http.Error(w, "Error parsing payload", http.StatusBadRequest) | ||
| return | ||
| } |
There was a problem hiding this comment.
All of the boilerplate is no longer needed since protobuf impl is handling this for us so we can focus on the fun parts of the implementation
6f50407 to
8633785
Compare
|
@DivineGod - This still needs to be expanded to allow the new auth endpoint to be used when un-authed |
a816142 to
755a1b3
Compare
755a1b3 to
6795a02
Compare
Signed-off-by: Ando “Thor” Nando <divinegod@gmail.com>
|
Follow up to this would be slowly moving over each endpoint as we have spare time to do so |
|
I've split out the URL updates into #186 to clean this up a bit |
Signed-off-by: Ben <elusiveshiba@gmail.com>
This is a wip spike to see how well the connectrpc connect-go stuff would slot in to dogeboxd.
I think it's possible to make it work without too much trouble.
There's some work to create a protobuf schema for each of the rest api endpoints, but as this initial work shows it should be possible to do this work incrementally.
Important read is the getting started guide here: https://connectrpc.com/docs/go/getting-started
Frontend: Dogebox-WG/dpanel#190
References: Dogebox-WG/dpanel#187