-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[scd] minimal implementation for the dss report handler
- Loading branch information
Showing
4 changed files
with
58 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package scd | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"github.com/google/uuid" | ||
restapi "github.com/interuss/dss/pkg/api/scdv1" | ||
"github.com/interuss/dss/pkg/logging" | ||
"github.com/interuss/stacktrace" | ||
"go.uber.org/zap" | ||
) | ||
|
||
// JsonLoggingDssReportHandler a DssReportHandler that simply logs the received report as JSON. | ||
type JsonLoggingDssReportHandler struct { | ||
ReportLogger *zap.Logger | ||
} | ||
|
||
// HandleDssReport logs the received report as a JSON string to a logger. | ||
func (h JsonLoggingDssReportHandler) HandleDssReport(ctx context.Context, req *restapi.MakeDssReportRequest) (*restapi.ErrorReport, error) { | ||
reportId, err := uuid.NewRandom() | ||
if err != nil { | ||
return nil, stacktrace.Propagate(err, "Failed to generate report ID") | ||
} | ||
reportIdStr := reportId.String() | ||
req.Body.ReportId = &reportIdStr | ||
// Serialize the report to a JSON string: | ||
jsonReport, err := json.Marshal(req.Body) | ||
if err != nil { | ||
logging.WithValuesFromContext(ctx, logging.Logger).Error("Failed to serialize DSS Report", zap.Error(err)) | ||
return nil, stacktrace.Propagate(err, "Failed to serialize DSS Report") | ||
} | ||
h.ReportLogger.Info("Received DSS Report", zap.String("report", string(jsonReport))) | ||
return req.Body, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters