Skip to content

Commit

Permalink
chore(): improved interceptor
Browse files Browse the repository at this point in the history
  • Loading branch information
debuggerpk committed Dec 7, 2024
1 parent 1ba069a commit 45d56e0
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 19 deletions.
5 changes: 5 additions & 0 deletions internal/core/repos/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"go.breu.io/quantm/internal/core/repos/activities"
"go.breu.io/quantm/internal/core/repos/defs"
"go.breu.io/quantm/internal/core/repos/fns"
"go.breu.io/quantm/internal/core/repos/nomad"
"go.breu.io/quantm/internal/core/repos/states"
"go.breu.io/quantm/internal/core/repos/workflows"
)
Expand Down Expand Up @@ -38,6 +39,10 @@ var (
RepoWorkflowOptions = defs.RepoWorkflowOptions
)

var (
NomadHandler = nomad.NewRepoServiceHandler
)

const (
SignalPush = defs.SignalPush
SignalRef = defs.SignalRef
Expand Down
6 changes: 3 additions & 3 deletions internal/core/repos/nomad/repos.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package reposnmd
package nomad

import (
"context"
Expand All @@ -8,7 +8,7 @@ import (
"google.golang.org/protobuf/types/known/emptypb"

"go.breu.io/quantm/internal/auth"
reposcast "go.breu.io/quantm/internal/core/repos/cast"
"go.breu.io/quantm/internal/core/repos/cast"
"go.breu.io/quantm/internal/db"
"go.breu.io/quantm/internal/erratic"
corev1 "go.breu.io/quantm/internal/proto/ctrlplane/core/v1"
Expand All @@ -31,7 +31,7 @@ func (s *RepoService) ListRepos(
return nil, erratic.NewDatabaseError(erratic.CoreModule).Wrap(err)
}

protos := reposcast.RepoExtendedListToProto(rows)
protos := cast.RepoExtendedListToProto(rows)

return connect.NewResponse(&corev1.ListReposResponse{Repos: protos}), nil
}
Expand Down
3 changes: 3 additions & 0 deletions internal/hooks/github/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package github
import (
"go.breu.io/quantm/internal/hooks/github/activities"
"go.breu.io/quantm/internal/hooks/github/config"
"go.breu.io/quantm/internal/hooks/github/nomad"
"go.breu.io/quantm/internal/hooks/github/web"
"go.breu.io/quantm/internal/hooks/github/workflows"
)
Expand Down Expand Up @@ -30,4 +31,6 @@ var (
PushWorkflow = workflows.Push
PullRequestWorkflow = workflows.PullRequest
SyncReposWorkflow = workflows.SyncRepos

NomadHandler = nomad.NewGithubServiceHandler
)
3 changes: 3 additions & 0 deletions internal/hooks/slack/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package slack
import (
"go.breu.io/quantm/internal/hooks/slack/activities"
"go.breu.io/quantm/internal/hooks/slack/config"
"go.breu.io/quantm/internal/hooks/slack/nomad"
)

type (
Expand All @@ -14,4 +15,6 @@ type (
var (
WithConfig = config.WithConfig
Configure = config.Instance

NomadHandler = nomad.NewSlackServiceHandler
)
12 changes: 12 additions & 0 deletions internal/nomad/intercepts/recover.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package intercepts

import (
"context"
"net/http"

"connectrpc.com/connect"
)

func Recover(ctx context.Context, spec connect.Spec, header http.Header, req any) error {
return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func RequestLogger() connect.UnaryInterceptorFunc {
fields = append(fields, "internal_error", qerr.Unwrap().Error())
}

slog.Error(procedure, fields...)
slog.Warn(procedure, fields...)

err = qerr.ToConnectError()
} else {
Expand Down
16 changes: 8 additions & 8 deletions internal/nomad/server/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"connectrpc.com/connect"

"go.breu.io/quantm/internal/auth"
reposnmd "go.breu.io/quantm/internal/core/repos/nomad"
githubnmd "go.breu.io/quantm/internal/hooks/github/nomad"
slacknmd "go.breu.io/quantm/internal/hooks/slack/nomad"
"go.breu.io/quantm/internal/observe"
"go.breu.io/quantm/internal/core/repos"
"go.breu.io/quantm/internal/hooks/github"
"go.breu.io/quantm/internal/hooks/slack"
"go.breu.io/quantm/internal/nomad/intercepts"
)

// DefaultServer creates a new Nomad server instance with the provided options.
Expand All @@ -19,7 +19,7 @@ func DefaultServer(opts ...Option) *Server {
// -- config/interceptors --

interceptors := []connect.Interceptor{
observe.NomadRequestLogger(),
intercepts.RequestLogger(),
}

// -- config/handlers --
Expand All @@ -38,13 +38,13 @@ func DefaultServer(opts ...Option) *Server {
options = append(options, connect.WithInterceptors(auth.NomadInterceptor()))

// -- core/repos --
srv.add(reposnmd.NewRepoServiceHandler(options...))
srv.add(repos.NomadHandler(options...))

Check failure on line 41 in internal/nomad/server/default.go

View workflow job for this annotation

GitHub Actions / golangci-lint

not enough arguments in call to srv.add

// -- hooks/github --
srv.add(githubnmd.NewGithubServiceHandler(options...))
srv.add(github.NomadHandler(options...))

Check failure on line 44 in internal/nomad/server/default.go

View workflow job for this annotation

GitHub Actions / golangci-lint

not enough arguments in call to srv.add

// -- hooks/slack --
srv.add(slacknmd.NewSlackServiceHandler(options...))
srv.add(slack.NomadHandler(options...))

return srv
}
7 changes: 0 additions & 7 deletions internal/observe/alias.go

This file was deleted.

0 comments on commit 45d56e0

Please sign in to comment.