No longer enforce version matching between daemon and cli (#4271)
* No longer check version matching between daemon and cli * Add Log Service Handler and report if the daemon is running in background mode
This commit is contained in:
8 files changed
+198
-66
No files matched your search
@@ -0,0 +1,50 @@
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: BUSL-1.1
|
||||
|
||||
package daemon
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/event"
|
||||
)
|
||||
|
||||
// LogRequest is the request body to this handler.
|
||||
type LogRequest struct {
|
||||
// Message is a required field for all requests
|
||||
Message string `json:"message,omitempty"`
|
||||
Op string `json:"op,omitempty"`
|
||||
}
|
||||
|
||||
// newLogHandlerFunc creates a handler that logs a system event using the
|
||||
// daemon's eventer.
|
||||
func newLogHandlerFunc(ctx context.Context) (http.HandlerFunc, error) {
|
||||
const op = "daemon.newLogHandlerFunc"
|
||||
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method != http.MethodPost {
|
||||
writeError(w, "only method POST allowed", http.StatusMethodNotAllowed)
|
||||
}
|
||||
|
||||
var perReq LogRequest
|
||||
data, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
writeError(w, "unable to read request body", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if err := json.Unmarshal(data, &perReq); err != nil {
|
||||
// If, for whatever reason, we can't parse the request body as json
|
||||
// can still log that the request to log was received and print out
|
||||
// the body of the request.
|
||||
event.WriteError(ctx, op, err, event.WithInfo("body", string(data)))
|
||||
writeError(w, "unable to parse request body", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
event.WriteSysEvent(ctx, op, perReq.Message, "requester_op", perReq.Op)
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
}, nil
|
||||
}
|
||||
Reference in new issue
Block a user