Skip to content

Commit

Permalink
Add logs to get instance and local vendored audit package
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlHembrough committed Jul 6, 2018
1 parent bded7d6 commit af5ab54
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
9 changes: 9 additions & 0 deletions instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,25 +116,32 @@ func (s *Store) Get(w http.ResponseWriter, r *http.Request) {
data := log.Data{"instance_id": id}
ap := common.Params{"instance_id": id}

data["req_path"] = r.URL.Path
log.InfoCtx(ctx, "instance get: handler called, auditing attempt", data)

if err := s.Auditor.Record(ctx, GetInstanceAction, audit.Attempted, ap); err != nil {
handleInstanceErr(ctx, err, w, nil)
return
}

log.InfoCtx(ctx, "instance get: getting instance", data)

b, err := func() ([]byte, error) {
instance, err := s.GetInstance(id)
if err != nil {
log.ErrorCtx(ctx, errors.WithMessage(err, "get instance: failed to retrieve instance"), data)
return nil, err
}

log.InfoCtx(ctx, "instance get: checking instance state", data)
// Early return if instance state is invalid
if err = models.CheckState("instance", instance.State); err != nil {
data["state"] = instance.State
log.ErrorCtx(ctx, errors.WithMessage(err, "get instance: instance has an invalid state"), data)
return nil, err
}

log.InfoCtx(ctx, "instance get: marshalling instance json", data)
b, err := json.Marshal(instance)
if err != nil {
log.ErrorCtx(ctx, errors.WithMessage(err, "get instance: failed to marshal instance to json"), data)
Expand All @@ -143,6 +150,8 @@ func (s *Store) Get(w http.ResponseWriter, r *http.Request) {

return b, nil
}()

log.InfoCtx(ctx, "instance get: auditing outcome", data)
if err != nil {
if auditErr := s.Auditor.Record(ctx, GetInstanceAction, audit.Unsuccessful, ap); auditErr != nil {
err = auditErr
Expand Down
15 changes: 14 additions & 1 deletion vendor/github.com/ONSdigital/go-ns/audit/audit.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit af5ab54

Please sign in to comment.