Skip to content

Commit

Permalink
Add status to /id response, and include enrollment status (#1637)
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaMahany authored Mar 4, 2024
1 parent 136c75a commit 67a9019
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
34 changes: 23 additions & 11 deletions ee/localserver/request-id.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,25 @@ import (
"github.com/kolide/launcher/pkg/traces"
)

type identifiers struct {
UUID string
InstanceId string
HardwareSerial string
}
type (
identifiers struct {
UUID string
InstanceId string
HardwareSerial string
}

type requestIdsResponse struct {
RequestId string
identifiers
Nonce string
Timestamp time.Time
}
requestIdsResponse struct {
RequestId string
identifiers
Nonce string
Timestamp time.Time
Status status
}

status struct {
EnrollmentStatus string
}
)

const (
idSQL = "select instance_id, osquery_info.uuid, hardware_serial from osquery_info, system_info"
Expand Down Expand Up @@ -66,9 +73,14 @@ func (ls *localServer) requestIdHandlerFunc(w http.ResponseWriter, r *http.Reque
r, span := traces.StartHttpRequestSpan(r, "path", r.URL.Path)
defer span.End()

enrollmentStatus, _ := ls.knapsack.CurrentEnrollmentStatus()

response := requestIdsResponse{
Nonce: ulid.New(),
Timestamp: time.Now(),
Status: status{
EnrollmentStatus: string(enrollmentStatus),
},
}
response.identifiers = ls.identifiers

Expand Down
3 changes: 3 additions & 0 deletions ee/localserver/request-id_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func Test_localServer_requestIdHandler(t *testing.T) {
mockKnapsack := typesMocks.NewKnapsack(t)
mockKnapsack.On("ConfigStore").Return(storageci.NewStore(t, multislogger.NewNopLogger(), storage.ConfigStore.String()))
mockKnapsack.On("KolideServerURL").Return("localhost")
mockKnapsack.On("CurrentEnrollmentStatus").Return(types.Enrolled, nil)

var logBytes bytes.Buffer
slogger := slog.New(slog.NewJSONHandler(&logBytes, &slog.HandlerOptions{
Expand Down Expand Up @@ -53,6 +54,8 @@ func Test_localServer_requestIdHandler(t *testing.T) {
// convert the response to a struct
var response requestIdsResponse
require.NoError(t, json.Unmarshal(rr.Body.Bytes(), &response))

mockKnapsack.AssertExpectations(t)
}

func testServer(t *testing.T, k types.Knapsack) *localServer {
Expand Down

0 comments on commit 67a9019

Please sign in to comment.