Compare commits

..

No commits in common. "8f1897da97c3db0f16b5745514f8a8375515e883" and "99f67a7e790f81c9c0fcfbf923718e7dcb434cc6" have entirely different histories.

2 changed files with 8 additions and 22 deletions

View file

@ -14,10 +14,6 @@ import (
const EnrollRoute = "/enroll"
type newClientPayload struct {
ID string `json:"ID"`
}
type EnrollController struct {
clientService *services.ClientHandlerService
l *logrus.Logger
@ -30,39 +26,30 @@ func NewEnrollController(l *logrus.Logger, service *services.ClientHandlerServic
}
}
func (ec *EnrollController) enrollMachine(w http.ResponseWriter, r *http.Request) (int, []byte, error) {
func (ec *EnrollController) enrollMachine(w http.ResponseWriter, r *http.Request) (int, error) {
if r.Method != http.MethodPost {
return http.StatusMethodNotAllowed, nil, nil
return http.StatusMethodNotAllowed, nil
}
dat, err := io.ReadAll(r.Body)
if err != nil {
return http.StatusInternalServerError, nil, fmt.Errorf("failed to read body: %w", err)
return http.StatusInternalServerError, fmt.Errorf("failed to read body: %w", err)
}
var client bootoption.Client
if err := json.Unmarshal(dat, &client); err != nil {
return http.StatusInternalServerError, nil, fmt.Errorf("failed to parse body: %w", err)
}
cltID, err := ec.clientService.AddClient(&client)
if err != nil {
return http.StatusInternalServerError, nil, fmt.Errorf("failed to create client %w", err)
}
payload, err := json.Marshal(newClientPayload{ID: cltID.String()})
if err != nil {
return http.StatusInternalServerError, nil, fmt.Errorf("failed to serialize payload: %w", err)
return http.StatusInternalServerError, fmt.Errorf("failed to parse body: %w", err)
}
ec.clientService.AddClient(&client)
ec.l.Infof("Added client")
return http.StatusOK, payload, nil
return http.StatusAccepted, nil
}
func (ec *EnrollController) ServeHTTP(w http.ResponseWriter, r *http.Request) {
returncode, content, err := ec.enrollMachine(w, r)
returncode, err := ec.enrollMachine(w, r)
if err != nil {
ec.l.Errorf("Error handling client enrollement: %s", err.Error())
}
helpers.HandleResponse(w, r, returncode, content, ec.l)
helpers.HandleResponse(w, r, returncode, nil, ec.l)
}

View file

@ -120,7 +120,6 @@ func (l *UDPListener) listen() (*udpMessage, error) {
return nil, fmt.Errorf("UDP packet too big (%d/%d)", n, bufferLength)
}
l.log.Debugf("Parsing UDP message %q", bytes.Trim(buffer, "\x00"))
parsedMsg, err := bootprotocol.MessageFromBytes(bytes.Trim(buffer, "\x00"))
if err != nil {
return nil, fmt.Errorf("failed to parse message: %w", err)