Remove unneeded hclog dependencies as we move forward with events (#1433)
This commit is contained in:
43 files changed
+147
-421
No files matched your search
@@ -22,7 +22,6 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/types/resource"
|
||||
"github.com/hashicorp/boundary/internal/types/scope"
|
||||
"github.com/hashicorp/boundary/sdk/recovery"
|
||||
"github.com/hashicorp/go-hclog"
|
||||
wrapping "github.com/hashicorp/go-kms-wrapping"
|
||||
"github.com/mr-tron/base58"
|
||||
"google.golang.org/protobuf/proto"
|
||||
@@ -105,7 +104,6 @@ type VerifyResults struct {
|
||||
}
|
||||
|
||||
type verifier struct {
|
||||
logger hclog.Logger
|
||||
iamRepoFn common.IamRepoFactory
|
||||
authTokenRepoFn common.AuthTokenRepoFactory
|
||||
serversRepoFn common.ServersRepoFactory
|
||||
@@ -122,14 +120,12 @@ type verifier struct {
|
||||
// HTTP handler and should exist for every request that reaches the service
|
||||
// handlers.
|
||||
func NewVerifierContext(ctx context.Context,
|
||||
logger hclog.Logger,
|
||||
iamRepoFn common.IamRepoFactory,
|
||||
authTokenRepoFn common.AuthTokenRepoFactory,
|
||||
serversRepoFn common.ServersRepoFactory,
|
||||
kms *kms.Kms,
|
||||
requestInfo RequestInfo) context.Context {
|
||||
return context.WithValue(ctx, verifierKey, &verifier{
|
||||
logger: logger,
|
||||
iamRepoFn: iamRepoFn,
|
||||
authTokenRepoFn: authTokenRepoFn,
|
||||
serversRepoFn: serversRepoFn,
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/kms"
|
||||
"github.com/hashicorp/boundary/internal/servers"
|
||||
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
|
||||
"github.com/hashicorp/go-hclog"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -21,7 +20,6 @@ import (
|
||||
func TestAuthTokenAuthenticator(t *testing.T) {
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
logger := hclog.New(nil)
|
||||
wrapper := db.TestWrapper(t)
|
||||
kms := kms.TestKms(t, conn, wrapper)
|
||||
tokenRepo, err := authtoken.NewRepository(rw, rw, kms)
|
||||
@@ -119,7 +117,7 @@ func TestAuthTokenAuthenticator(t *testing.T) {
|
||||
if tc.userId == "" {
|
||||
return
|
||||
}
|
||||
ctx := NewVerifierContext(context.Background(), logger, iamRepoFn, tokenRepoFn, serversRepoFn, kms, requestInfo)
|
||||
ctx := NewVerifierContext(context.Background(), iamRepoFn, tokenRepoFn, serversRepoFn, kms, requestInfo)
|
||||
|
||||
v, ok := ctx.Value(verifierKey).(*verifier)
|
||||
require.True(t, ok)
|
||||
|
||||
@@ -22,5 +22,5 @@ func DisabledAuthTestContext(iamRepoFn common.IamRepoFactory, scopeId string, op
|
||||
reqInfo.userIdOverride = "u_auth"
|
||||
}
|
||||
requestContext := context.WithValue(context.Background(), requests.ContextRequestInformationKey, &requests.RequestContext{})
|
||||
return NewVerifierContext(requestContext, nil, iamRepoFn, nil, nil, opts.withKms, reqInfo)
|
||||
return NewVerifierContext(requestContext, iamRepoFn, nil, nil, opts.withKms, reqInfo)
|
||||
}
|
||||
@@ -225,7 +225,6 @@ func TestListingScopeIds(t *testing.T) {
|
||||
o, p := iam.TestScopes(t, iamRepo)
|
||||
at := authtoken.TestAuthToken(t, conn, kms, o.GetPublicId())
|
||||
ctx := auth.NewVerifierContext(context.Background(),
|
||||
nil,
|
||||
iamRepoFn,
|
||||
authTokenRepoFn,
|
||||
serversRepoFn,
|
||||
|
||||
@@ -105,7 +105,7 @@ func New(ctx context.Context, conf *Config) (*Controller, error) {
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating kms repository: %w", err)
|
||||
}
|
||||
c.kms, err = kms.NewKms(kmsRepo, kms.WithLogger(c.logger.Named("kms")))
|
||||
c.kms, err = kms.NewKms(kmsRepo)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating kms cache: %w", err)
|
||||
}
|
||||
@@ -121,7 +121,7 @@ func New(ctx context.Context, conf *Config) (*Controller, error) {
|
||||
}
|
||||
// TODO: the RunJobsLimit is temporary until a better fix gets in. This
|
||||
// currently caps the scheduler at running 10 jobs per interval.
|
||||
c.scheduler, err = scheduler.New(c.conf.RawConfig.Controller.Name, jobRepoFn, c.logger, scheduler.WithRunJobsLimit(10))
|
||||
c.scheduler, err = scheduler.New(c.conf.RawConfig.Controller.Name, jobRepoFn, scheduler.WithRunJobsLimit(10))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating new scheduler: %w", err)
|
||||
}
|
||||
@@ -203,7 +203,7 @@ func (c *Controller) Start() error {
|
||||
|
||||
func (c *Controller) registerJobs() error {
|
||||
rw := db.New(c.conf.Database)
|
||||
if err := vault.RegisterJobs(c.baseContext, c.scheduler, rw, rw, c.kms, c.logger); err != nil {
|
||||
if err := vault.RegisterJobs(c.baseContext, c.scheduler, rw, rw, c.kms); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ func (c *Controller) registerJobs() error {
|
||||
// registerSessionCleanupJob is a helper method to abstract
|
||||
// registering the session cleanup job specifically.
|
||||
func (c *Controller) registerSessionCleanupJob() error {
|
||||
sessionCleanupJob, err := newSessionCleanupJob(c.logger, c.SessionRepoFn, int(c.conf.StatusGracePeriodDuration.Seconds()))
|
||||
sessionCleanupJob, err := newSessionCleanupJob(c.SessionRepoFn, int(c.conf.StatusGracePeriodDuration.Seconds()))
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating session cleanup job: %w", err)
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ func handleGrpcGateway(c *Controller, props HandlerProperties) (http.Handler, er
|
||||
runtime.WithMarshalerOption(runtime.MIMEWildcard, &runtime.HTTPBodyMarshaler{
|
||||
Marshaler: handlers.JSONMarshaler(),
|
||||
}),
|
||||
runtime.WithErrorHandler(handlers.ErrorHandler(c.logger)),
|
||||
runtime.WithErrorHandler(handlers.ErrorHandler()),
|
||||
runtime.WithForwardResponseOption(handlers.OutgoingInterceptor),
|
||||
)
|
||||
hcs, err := host_catalogs.NewService(c.StaticHostRepoFn, c.IamRepoFn)
|
||||
@@ -113,7 +113,7 @@ func handleGrpcGateway(c *Controller, props HandlerProperties) (http.Handler, er
|
||||
if err := services.RegisterAccountServiceHandlerServer(ctx, mux, accts); err != nil {
|
||||
return nil, fmt.Errorf("failed to register account service handler: %w", err)
|
||||
}
|
||||
authMethods, err := authmethods.NewService(c.kms, c.PasswordAuthRepoFn, c.OidcRepoFn, c.IamRepoFn, c.AuthTokenRepoFn, handlers.WithLogger(c.logger.Named("authmethod_service")))
|
||||
authMethods, err := authmethods.NewService(c.kms, c.PasswordAuthRepoFn, c.OidcRepoFn, c.IamRepoFn, c.AuthTokenRepoFn)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create auth method handler service: %w", err)
|
||||
}
|
||||
@@ -243,7 +243,7 @@ func wrapHandlerWithCommonFuncs(h http.Handler, c *Controller, props HandlerProp
|
||||
}
|
||||
|
||||
requestInfo.PublicId, requestInfo.EncryptedToken, requestInfo.TokenFormat = auth.GetTokenFromRequest(ctx, c.kms, r)
|
||||
ctx = auth.NewVerifierContext(ctx, c.logger, c.IamRepoFn, c.AuthTokenRepoFn, c.ServersRepoFn, c.kms, requestInfo)
|
||||
ctx = auth.NewVerifierContext(ctx, c.IamRepoFn, c.AuthTokenRepoFn, c.ServersRepoFn, c.kms, requestInfo)
|
||||
|
||||
// Add general request information to the context. The information from
|
||||
// the auth verifier context is pretty specifically curated to
|
||||
|
||||
@@ -6,10 +6,9 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/observability/event"
|
||||
"github.com/hashicorp/go-hclog"
|
||||
)
|
||||
|
||||
func devPassthroughHandler(logger hclog.Logger, passthroughDir string) http.Handler {
|
||||
func devPassthroughHandler(passthroughDir string) http.Handler {
|
||||
const op = "controller.devPassthroughHandler"
|
||||
ctx := context.TODO()
|
||||
// Panic may not be ideal but this is never a production call and it'll
|
||||
@@ -28,7 +27,7 @@ func devPassthroughHandler(logger hclog.Logger, passthroughDir string) http.Hand
|
||||
|
||||
var handleUi = func(c *Controller) http.Handler {
|
||||
if c.conf.RawConfig.PassthroughDirectory != "" {
|
||||
return devPassthroughHandler(c.logger, c.conf.RawConfig.PassthroughDirectory)
|
||||
return devPassthroughHandler(c.conf.RawConfig.PassthroughDirectory)
|
||||
}
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
|
||||
@@ -16,7 +16,7 @@ func init() {
|
||||
func handleUiWithAssets(c *Controller) http.Handler {
|
||||
var nextHandler http.Handler
|
||||
if c.conf.RawConfig.PassthroughDirectory != "" {
|
||||
nextHandler = devPassthroughHandler(c.logger, c.conf.RawConfig.PassthroughDirectory)
|
||||
nextHandler = devPassthroughHandler(c.conf.RawConfig.PassthroughDirectory)
|
||||
} else {
|
||||
nextHandler = ui.Handler()
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/types/resource"
|
||||
"github.com/hashicorp/boundary/internal/types/scope"
|
||||
"github.com/hashicorp/boundary/internal/types/subtypes"
|
||||
"github.com/hashicorp/go-hclog"
|
||||
"github.com/hashicorp/go-secure-stdlib/strutil"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/protobuf/types/known/structpb"
|
||||
@@ -74,8 +73,6 @@ type Service struct {
|
||||
oidcRepoFn common.OidcAuthRepoFactory
|
||||
iamRepoFn common.IamRepoFactory
|
||||
atRepoFn common.AuthTokenRepoFactory
|
||||
|
||||
oidcLogger hclog.Logger
|
||||
}
|
||||
|
||||
// NewService returns a auth method service which handles auth method related requests to boundary.
|
||||
@@ -97,10 +94,7 @@ func NewService(kms *kms.Kms, pwRepoFn common.PasswordAuthRepoFactory, oidcRepoF
|
||||
return Service{}, fmt.Errorf("nil auth token repository provided")
|
||||
}
|
||||
s := Service{kms: kms, pwRepoFn: pwRepoFn, oidcRepoFn: oidcRepoFn, iamRepoFn: iamRepoFn, atRepoFn: atRepoFn}
|
||||
opts := handlers.GetOpts(opt...)
|
||||
if opts.WithLogger != nil {
|
||||
s.oidcLogger = opts.WithLogger.Named("oidc")
|
||||
}
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -203,7 +203,6 @@ func TestList_FilterNonPublic(t *testing.T) {
|
||||
reqCtx: func() context.Context {
|
||||
at := authtoken.TestAuthToken(t, conn, kmsCache, o.GetPublicId())
|
||||
return auth.NewVerifierContext(requests.NewRequestContext(context.Background()),
|
||||
nil,
|
||||
iamRepoFn,
|
||||
atRepoFn,
|
||||
serversRepoFn,
|
||||
|
||||
@@ -21,7 +21,6 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
|
||||
"github.com/hashicorp/boundary/internal/servers/controller/handlers/authtokens"
|
||||
"github.com/hashicorp/boundary/internal/types/scope"
|
||||
"github.com/hashicorp/go-hclog"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/protobuf/testing/protocmp"
|
||||
|
||||
@@ -35,7 +34,6 @@ func TestGetSelf(t *testing.T) {
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
wrap := db.TestWrapper(t)
|
||||
logger := hclog.New(nil)
|
||||
kms := kms.TestKms(t, conn, wrap)
|
||||
|
||||
iamRepoFn := func() (*iam.Repository, error) {
|
||||
@@ -97,7 +95,7 @@ func TestGetSelf(t *testing.T) {
|
||||
Token: tc.token.GetToken(),
|
||||
}
|
||||
|
||||
ctx := auth.NewVerifierContext(context.Background(), logger, iamRepoFn, tokenRepoFn, serversRepoFn, kms, requestInfo)
|
||||
ctx := auth.NewVerifierContext(context.Background(), iamRepoFn, tokenRepoFn, serversRepoFn, kms, requestInfo)
|
||||
ctx = context.WithValue(ctx, requests.ContextRequestInformationKey, &requests.RequestContext{})
|
||||
got, err := a.GetAuthToken(ctx, &pbs.GetAuthTokenRequest{Id: tc.readId})
|
||||
if tc.err != nil {
|
||||
@@ -193,7 +191,6 @@ func TestList_Self(t *testing.T) {
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
wrap := db.TestWrapper(t)
|
||||
logger := hclog.New(nil)
|
||||
kms := kms.TestKms(t, conn, wrap)
|
||||
|
||||
iamRepo := iam.TestRepo(t, conn, wrap)
|
||||
@@ -247,7 +244,7 @@ func TestList_Self(t *testing.T) {
|
||||
Token: tc.requester.GetToken(),
|
||||
}
|
||||
|
||||
ctx := auth.NewVerifierContext(context.Background(), logger, iamRepoFn, tokenRepoFn, serversRepoFn, kms, requestInfo)
|
||||
ctx := auth.NewVerifierContext(context.Background(), iamRepoFn, tokenRepoFn, serversRepoFn, kms, requestInfo)
|
||||
got, err := a.ListAuthTokens(ctx, &pbs.ListAuthTokensRequest{ScopeId: o.GetPublicId()})
|
||||
require.NoError(err)
|
||||
require.Len(got.Items, 1)
|
||||
@@ -418,7 +415,6 @@ func TestDeleteSelf(t *testing.T) {
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
rw := db.New(conn)
|
||||
wrap := db.TestWrapper(t)
|
||||
logger := hclog.New(nil)
|
||||
kms := kms.TestKms(t, conn, wrap)
|
||||
|
||||
iamRepo := iam.TestRepo(t, conn, wrap)
|
||||
@@ -494,7 +490,7 @@ func TestDeleteSelf(t *testing.T) {
|
||||
Token: tc.token.GetToken(),
|
||||
}
|
||||
|
||||
ctx := auth.NewVerifierContext(context.Background(), logger, iamRepoFn, tokenRepoFn, serversRepoFn, kms, requestInfo)
|
||||
ctx := auth.NewVerifierContext(context.Background(), iamRepoFn, tokenRepoFn, serversRepoFn, kms, requestInfo)
|
||||
got, err := a.DeleteAuthToken(ctx, &pbs.DeleteAuthTokenRequest{Id: tc.deleteId})
|
||||
if tc.err != nil {
|
||||
require.EqualError(err, tc.err.Error())
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/errors"
|
||||
pb "github.com/hashicorp/boundary/internal/gen/controller/api"
|
||||
"github.com/hashicorp/boundary/internal/observability/event"
|
||||
"github.com/hashicorp/go-hclog"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
@@ -185,7 +184,7 @@ func backendErrorToApiError(inErr error) *apiError {
|
||||
}
|
||||
}
|
||||
|
||||
func ErrorHandler(logger hclog.Logger) runtime.ErrorHandlerFunc {
|
||||
func ErrorHandler() runtime.ErrorHandlerFunc {
|
||||
const op = "handlers.ErrorHandler"
|
||||
const errorFallback = `{"error": "failed to marshal error message"}`
|
||||
return func(ctx context.Context, _ *runtime.ServeMux, mar runtime.Marshaler, w http.ResponseWriter, r *http.Request, inErr error) {
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
|
||||
"github.com/hashicorp/boundary/internal/errors"
|
||||
pb "github.com/hashicorp/boundary/internal/gen/controller/api"
|
||||
"github.com/hashicorp/go-hclog"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/grpc/codes"
|
||||
@@ -28,7 +27,7 @@ func TestApiErrorHandler(t *testing.T) {
|
||||
mux := runtime.NewServeMux()
|
||||
inMarsh, outMarsh := runtime.MarshalerForRequest(mux, req)
|
||||
|
||||
tested := ErrorHandler(hclog.L())
|
||||
tested := ErrorHandler()
|
||||
|
||||
testCases := []struct {
|
||||
name string
|
||||
|
||||
@@ -4,7 +4,6 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/perms"
|
||||
"github.com/hashicorp/go-hclog"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -29,15 +28,6 @@ func Test_GetOpts(t *testing.T) {
|
||||
testOpts.withDiscardUnknownFields = false
|
||||
assert.Equal(opts, testOpts)
|
||||
})
|
||||
t.Run("WithLogger", func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
opts := GetOpts()
|
||||
assert.Nil(opts.WithLogger)
|
||||
|
||||
opts = GetOpts(WithLogger(hclog.New(nil)))
|
||||
assert.NotNil(opts.WithLogger)
|
||||
})
|
||||
t.Run("WithUserIsAnonymous", func(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package handlers
|
||||
import (
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api/resources/scopes"
|
||||
"github.com/hashicorp/boundary/internal/perms"
|
||||
"github.com/hashicorp/go-hclog"
|
||||
"google.golang.org/protobuf/types/known/structpb"
|
||||
)
|
||||
|
||||
@@ -24,7 +23,6 @@ type Option func(*options)
|
||||
// options = how options are represented
|
||||
type options struct {
|
||||
withDiscardUnknownFields bool
|
||||
WithLogger hclog.Logger
|
||||
WithUserIsAnonymous bool
|
||||
WithOutputFields *perms.OutputFieldsMap
|
||||
WithScope *scopes.ScopeInfo
|
||||
@@ -47,13 +45,6 @@ func WithDiscardUnknownFields(discard bool) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// WithLogger provides an option include a logger
|
||||
func WithLogger(logger hclog.Logger) Option {
|
||||
return func(o *options) {
|
||||
o.WithLogger = logger
|
||||
}
|
||||
}
|
||||
|
||||
// DEPRECATED: Superceded by WithOutputFields. Will be removed once all handlers
|
||||
// have been migrated to that.
|
||||
func WithUserIsAnonymous(anonListing bool) Option {
|
||||
|
||||
@@ -24,7 +24,6 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/session"
|
||||
"github.com/hashicorp/boundary/internal/target"
|
||||
"github.com/hashicorp/boundary/internal/types/scope"
|
||||
"github.com/hashicorp/go-hclog"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/grpc/codes"
|
||||
@@ -148,7 +147,6 @@ func TestList_Self(t *testing.T) {
|
||||
conn, _ := db.TestSetup(t, "postgres")
|
||||
wrap := db.TestWrapper(t)
|
||||
kms := kms.TestKms(t, conn, wrap)
|
||||
logger := hclog.New(nil)
|
||||
iamRepo := iam.TestRepo(t, conn, wrap)
|
||||
|
||||
rw := db.New(conn)
|
||||
@@ -220,7 +218,7 @@ func TestList_Self(t *testing.T) {
|
||||
Token: tc.requester.GetToken(),
|
||||
}
|
||||
|
||||
ctx := auth.NewVerifierContext(context.Background(), logger, iamRepoFn, tokenRepoFn, serversRepoFn, kms, requestInfo)
|
||||
ctx := auth.NewVerifierContext(context.Background(), iamRepoFn, tokenRepoFn, serversRepoFn, kms, requestInfo)
|
||||
got, err := s.ListSessions(ctx, &pbs.ListSessionsRequest{ScopeId: pWithSessions.GetPublicId()})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, tc.count, len(got.GetItems()), got.GetItems())
|
||||
|
||||
@@ -36,7 +36,6 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/session"
|
||||
"github.com/hashicorp/boundary/internal/target"
|
||||
"github.com/hashicorp/boundary/internal/types/scope"
|
||||
"github.com/hashicorp/go-hclog"
|
||||
wrapping "github.com/hashicorp/go-kms-wrapping"
|
||||
"github.com/jinzhu/gorm"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -2497,7 +2496,6 @@ func TestAuthorizeSession(t *testing.T) {
|
||||
org, proj := iam.TestScopes(t, iamRepo)
|
||||
at := authtoken.TestAuthToken(t, conn, kms, org.GetPublicId())
|
||||
ctx := auth.NewVerifierContext(requests.NewRequestContext(context.Background()),
|
||||
nil,
|
||||
iamRepoFn,
|
||||
atRepoFn,
|
||||
serversRepoFn,
|
||||
@@ -2556,7 +2554,7 @@ func TestAuthorizeSession(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Tell our DB that there is a worker ready to serve the data
|
||||
workerService := workers.NewWorkerServiceServer(hclog.Default(), serversRepoFn, sessionRepoFn, &sync.Map{}, kms)
|
||||
workerService := workers.NewWorkerServiceServer(serversRepoFn, sessionRepoFn, &sync.Map{}, kms)
|
||||
_, err = workerService.Status(ctx, &spbs.StatusRequest{
|
||||
Worker: &spb.Server{
|
||||
PrivateId: "testworker",
|
||||
@@ -2665,7 +2663,6 @@ func TestAuthorizeSession_Errors(t *testing.T) {
|
||||
// Authorized user gets full permissions
|
||||
at := authtoken.TestAuthToken(t, conn, kms, org.GetPublicId())
|
||||
ctx := auth.NewVerifierContext(requests.NewRequestContext(context.Background()),
|
||||
nil,
|
||||
iamRepoFn,
|
||||
atRepoFn,
|
||||
serversRepoFn,
|
||||
@@ -2685,7 +2682,7 @@ func TestAuthorizeSession_Errors(t *testing.T) {
|
||||
store := vault.TestCredentialStore(t, conn, wrapper, proj.GetPublicId(), v.Addr, tok, sec.Auth.Accessor)
|
||||
|
||||
workerExists := func(tar *target.TcpTarget) (version uint32) {
|
||||
workerService := workers.NewWorkerServiceServer(hclog.Default(), serversRepoFn, sessionRepoFn, &sync.Map{}, kms)
|
||||
workerService := workers.NewWorkerServiceServer(serversRepoFn, sessionRepoFn, &sync.Map{}, kms)
|
||||
_, err := workerService.Status(context.Background(), &spbs.StatusRequest{
|
||||
Worker: &spb.Server{
|
||||
PrivateId: "testworker",
|
||||
|
||||
@@ -17,7 +17,6 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/session"
|
||||
"github.com/hashicorp/boundary/internal/types/resource"
|
||||
"github.com/hashicorp/go-bexpr"
|
||||
"github.com/hashicorp/go-hclog"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
@@ -26,7 +25,6 @@ type workerServiceServer struct {
|
||||
pbs.UnimplementedServerCoordinationServiceServer
|
||||
pbs.UnimplementedSessionServiceServer
|
||||
|
||||
logger hclog.Logger
|
||||
serversRepoFn common.ServersRepoFactory
|
||||
sessionRepoFn common.SessionRepoFactory
|
||||
updateTimes *sync.Map
|
||||
@@ -34,13 +32,11 @@ type workerServiceServer struct {
|
||||
}
|
||||
|
||||
func NewWorkerServiceServer(
|
||||
logger hclog.Logger,
|
||||
serversRepoFn common.ServersRepoFactory,
|
||||
sessionRepoFn common.SessionRepoFactory,
|
||||
updateTimes *sync.Map,
|
||||
kms *kms.Kms) *workerServiceServer {
|
||||
return &workerServiceServer{
|
||||
logger: logger,
|
||||
serversRepoFn: serversRepoFn,
|
||||
sessionRepoFn: sessionRepoFn,
|
||||
updateTimes: updateTimes,
|
||||
|
||||
@@ -119,7 +119,7 @@ func (c *Controller) startListeners() error {
|
||||
grpc.MaxRecvMsgSize(math.MaxInt32),
|
||||
grpc.MaxSendMsgSize(math.MaxInt32),
|
||||
)
|
||||
workerService := workers.NewWorkerServiceServer(c.logger.Named("worker-handler"), c.ServersRepoFn, c.SessionRepoFn, c.workerStatusUpdateTimes, c.kms)
|
||||
workerService := workers.NewWorkerServiceServer(c.ServersRepoFn, c.SessionRepoFn, c.workerStatusUpdateTimes, c.kms)
|
||||
pbs.RegisterServerCoordinationServiceServer(workerServer, workerService)
|
||||
pbs.RegisterSessionServiceServer(workerServer, workerService)
|
||||
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/scheduler"
|
||||
"github.com/hashicorp/boundary/internal/servers/controller/common"
|
||||
"github.com/hashicorp/boundary/internal/session"
|
||||
"github.com/hashicorp/go-hclog"
|
||||
)
|
||||
|
||||
// sessionCleanupJob defines a periodic job that monitors workers for
|
||||
@@ -24,7 +23,6 @@ import (
|
||||
// the controller will win out and order that the connections be
|
||||
// closed on the worker.
|
||||
type sessionCleanupJob struct {
|
||||
logger hclog.Logger
|
||||
sessionRepoFn common.SessionRepoFactory
|
||||
|
||||
// The amount of time to give disconnected workers before marking
|
||||
@@ -37,14 +35,11 @@ type sessionCleanupJob struct {
|
||||
|
||||
// newSessionCleanupJob instantiates the session cleanup job.
|
||||
func newSessionCleanupJob(
|
||||
logger hclog.Logger,
|
||||
sessionRepoFn common.SessionRepoFactory,
|
||||
gracePeriod int,
|
||||
) (*sessionCleanupJob, error) {
|
||||
const op = "controller.newNewSessionCleanupJob"
|
||||
switch {
|
||||
case logger == nil:
|
||||
return nil, errors.NewDeprecated(errors.InvalidParameter, op, "missing logger")
|
||||
case sessionRepoFn == nil:
|
||||
return nil, errors.NewDeprecated(errors.InvalidParameter, op, "missing sessionRepoFn")
|
||||
case gracePeriod < session.DeadWorkerConnCloseMinGrace:
|
||||
@@ -53,7 +48,6 @@ func newSessionCleanupJob(
|
||||
}
|
||||
|
||||
return &sessionCleanupJob{
|
||||
logger: logger,
|
||||
sessionRepoFn: sessionRepoFn,
|
||||
gracePeriod: gracePeriod,
|
||||
}, nil
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/scheduler"
|
||||
"github.com/hashicorp/boundary/internal/servers"
|
||||
"github.com/hashicorp/boundary/internal/session"
|
||||
"github.com/hashicorp/go-hclog"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -96,7 +95,6 @@ func TestSessionCleanupJob(t *testing.T) {
|
||||
|
||||
// Create the job.
|
||||
job, err := newSessionCleanupJob(
|
||||
hclog.New(&hclog.LoggerOptions{Level: hclog.Trace}),
|
||||
func() (*session.Repository, error) { return sessionRepo, nil },
|
||||
session.DeadWorkerConnCloseMinGrace,
|
||||
)
|
||||
@@ -145,16 +143,7 @@ func TestSessionCleanupJobNewJobErr(t *testing.T) {
|
||||
const op = "controller.newNewSessionCleanupJob"
|
||||
require := require.New(t)
|
||||
|
||||
job, err := newSessionCleanupJob(nil, nil, 0)
|
||||
require.Equal(err, errors.E(
|
||||
ctx,
|
||||
errors.WithCode(errors.InvalidParameter),
|
||||
errors.WithOp(op),
|
||||
errors.WithMsg("missing logger"),
|
||||
))
|
||||
require.Nil(job)
|
||||
|
||||
job, err = newSessionCleanupJob(hclog.New(nil), nil, 0)
|
||||
job, err := newSessionCleanupJob(nil, 0)
|
||||
require.Equal(err, errors.E(
|
||||
ctx,
|
||||
errors.WithCode(errors.InvalidParameter),
|
||||
@@ -163,7 +152,7 @@ func TestSessionCleanupJobNewJobErr(t *testing.T) {
|
||||
))
|
||||
require.Nil(job)
|
||||
|
||||
job, err = newSessionCleanupJob(hclog.New(nil), func() (*session.Repository, error) { return nil, nil }, 0)
|
||||
job, err = newSessionCleanupJob(func() (*session.Repository, error) { return nil, nil }, 0)
|
||||
require.Equal(err, errors.E(
|
||||
ctx,
|
||||
errors.WithCode(errors.InvalidParameter),
|
||||
|
||||
Reference in new issue
Block a user