Rename package servers to server (#2222)

This commit is contained in:
Todd authored and GitHub committed 2022-06-20 18:20:17 -07:00
1 parent fb0e5ea1ce
commit 19b549c44a
79 files changed
+608 -604

No files matched your search

+3 -3
View File
@@ -20,7 +20,7 @@ import (
"github.com/hashicorp/boundary/internal/observability/event"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/requests"
"github.com/hashicorp/boundary/internal/servers"
"github.com/hashicorp/boundary/internal/server"
"github.com/hashicorp/boundary/internal/types/action"
"github.com/hashicorp/boundary/internal/types/resource"
"github.com/hashicorp/boundary/internal/types/scope"
@@ -418,11 +418,11 @@ func (v *verifier) decryptToken(ctx context.Context) {
}
repo, err := v.serversRepoFn()
if err != nil {
event.WriteError(ctx, op, err, event.WithInfoMsg("decrypt recovery token: error fetching servers repo"))
event.WriteError(ctx, op, err, event.WithInfoMsg("decrypt recovery token: error fetching server repo"))
v.requestInfo.TokenFormat = uint32(AuthTokenTypeUnknown)
return
}
if err := repo.AddNonce(v.ctx, info.Nonce, servers.NoncePurposeRecovery); err != nil {
if err := repo.AddNonce(v.ctx, info.Nonce, server.NoncePurposeRecovery); err != nil {
event.WriteError(ctx, op, err, event.WithInfoMsg("decrypt recovery token: error adding nonce to database (possible replay attack)"))
v.requestInfo.TokenFormat = uint32(AuthTokenTypeUnknown)
return
+5 -5
View File
@@ -16,7 +16,7 @@ import (
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/observability/event"
"github.com/hashicorp/boundary/internal/servers"
"github.com/hashicorp/boundary/internal/server"
"github.com/hashicorp/boundary/internal/tests/api"
"github.com/hashicorp/eventlogger/filters/encrypt"
"github.com/hashicorp/go-hclog"
@@ -38,8 +38,8 @@ func TestAuthTokenAuthenticator(t *testing.T) {
iamRepoFn := func() (*iam.Repository, error) {
return iamRepo, nil
}
serversRepoFn := func() (*servers.Repository, error) {
return servers.NewRepository(rw, rw, kms)
serversRepoFn := func() (*server.Repository, error) {
return server.NewRepository(rw, rw, kms)
}
o, _ := iam.TestScopes(t, iamRepo)
@@ -161,8 +161,8 @@ func TestVerify_AuditEvent(t *testing.T) {
iamRepoFn := func() (*iam.Repository, error) {
return iamRepo, nil
}
serversRepoFn := func() (*servers.Repository, error) {
return servers.NewRepository(rw, rw, testKms)
serversRepoFn := func() (*server.Repository, error) {
return server.NewRepository(rw, rw, testKms)
}
o, _ := iam.TestScopes(t, iamRepo)
+3 -3
View File
@@ -9,7 +9,7 @@ import (
"github.com/hashicorp/boundary/internal/host/static"
"github.com/hashicorp/boundary/internal/iam"
hostplugin "github.com/hashicorp/boundary/internal/plugin/host"
"github.com/hashicorp/boundary/internal/servers"
"github.com/hashicorp/boundary/internal/server"
"github.com/hashicorp/boundary/internal/session"
"github.com/hashicorp/boundary/internal/target"
)
@@ -21,12 +21,12 @@ type (
IamRepoFactory func() (*iam.Repository, error)
OidcAuthRepoFactory = oidc.OidcRepoFactory
PasswordAuthRepoFactory func() (*password.Repository, error)
ServersRepoFactory func() (*servers.Repository, error)
ServersRepoFactory func() (*server.Repository, error)
StaticRepoFactory func() (*static.Repository, error)
PluginHostRepoFactory func() (*pluginhost.Repository, error)
HostPluginRepoFactory func() (*hostplugin.Repository, error)
SessionRepoFactory func() (*session.Repository, error)
ConnectionRepoFactory func() (*session.ConnectionRepository, error)
TargetRepoFactory func() (*target.Repository, error)
WorkerAuthRepoStorageFactory func() (*servers.WorkerAuthRepositoryStorage, error)
WorkerAuthRepoStorageFactory func() (*server.WorkerAuthRepositoryStorage, error)
)
@@ -14,7 +14,7 @@ import (
authpb "github.com/hashicorp/boundary/internal/gen/controller/auth"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/servers"
"github.com/hashicorp/boundary/internal/server"
"github.com/hashicorp/boundary/internal/session"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/stretchr/testify/require"
@@ -38,8 +38,8 @@ func TestListingScopeIds(t *testing.T) {
authTokenRepoFn := func() (*authtoken.Repository, error) {
return authtoken.NewRepository(rw, rw, kms)
}
serversRepoFn := func() (*servers.Repository, error) {
return servers.NewRepository(rw, rw, kms)
serversRepoFn := func() (*server.Repository, error) {
return server.NewRepository(rw, rw, kms)
}
s, err := groups.NewService(iamRepoFn)
require.NoError(t, err)
+8 -8
View File
@@ -27,8 +27,8 @@ import (
hostplugin "github.com/hashicorp/boundary/internal/plugin/host"
"github.com/hashicorp/boundary/internal/scheduler"
"github.com/hashicorp/boundary/internal/scheduler/job"
"github.com/hashicorp/boundary/internal/servers"
serversjob "github.com/hashicorp/boundary/internal/servers/job"
"github.com/hashicorp/boundary/internal/server"
serversjob "github.com/hashicorp/boundary/internal/server/job"
"github.com/hashicorp/boundary/internal/session"
"github.com/hashicorp/boundary/internal/target"
"github.com/hashicorp/boundary/internal/types/scope"
@@ -283,8 +283,8 @@ func New(ctx context.Context, conf *Config) (*Controller, error) {
c.StaticCredentialRepoFn = func() (*credstatic.Repository, error) {
return credstatic.NewRepository(ctx, dbase, dbase, c.kms)
}
c.ServersRepoFn = func() (*servers.Repository, error) {
return servers.NewRepository(dbase, dbase, c.kms)
c.ServersRepoFn = func() (*server.Repository, error) {
return server.NewRepository(dbase, dbase, c.kms)
}
c.OidcRepoFn = func() (*oidc.Repository, error) {
return oidc.NewRepository(ctx, dbase, dbase, c.kms)
@@ -301,17 +301,17 @@ func New(ctx context.Context, conf *Config) (*Controller, error) {
c.ConnectionRepoFn = func() (*session.ConnectionRepository, error) {
return session.NewConnectionRepository(ctx, dbase, dbase, c.kms)
}
c.WorkerAuthRepoStorageFn = func() (*servers.WorkerAuthRepositoryStorage, error) {
return servers.NewRepositoryStorage(ctx, dbase, dbase, c.kms)
c.WorkerAuthRepoStorageFn = func() (*server.WorkerAuthRepositoryStorage, error) {
return server.NewRepositoryStorage(ctx, dbase, dbase, c.kms)
}
// Check that credentials are available at startup, to avoid some harmless
// but nasty-looking errors
serversRepo, err := servers.NewRepositoryStorage(ctx, dbase, dbase, c.kms)
serversRepo, err := server.NewRepositoryStorage(ctx, dbase, dbase, c.kms)
if err != nil {
return nil, fmt.Errorf("unable to instantiate worker auth repository: %w", err)
}
err = servers.RotateRoots(ctx, serversRepo)
err = server.RotateRoots(ctx, serversRepo)
if err != nil {
return nil, fmt.Errorf("unable to ensure worker auth roots exist: %w", err)
}
@@ -28,7 +28,7 @@ import (
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/requests"
"github.com/hashicorp/boundary/internal/servers"
"github.com/hashicorp/boundary/internal/server"
"github.com/hashicorp/boundary/internal/types/scope"
pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/authmethods"
scopepb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/scopes"
@@ -151,8 +151,8 @@ func TestList_FilterNonPublic(t *testing.T) {
atRepoFn := func() (*authtoken.Repository, error) {
return authtoken.NewRepository(rw, rw, kmsCache)
}
serversRepoFn := func() (*servers.Repository, error) {
return servers.NewRepository(rw, rw, kmsCache)
serversRepoFn := func() (*server.Repository, error) {
return server.NewRepository(rw, rw, kmsCache)
}
iamRepo := iam.TestRepo(t, conn, wrapper)
@@ -18,7 +18,7 @@ import (
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/requests"
"github.com/hashicorp/boundary/internal/servers"
"github.com/hashicorp/boundary/internal/server"
"github.com/hashicorp/boundary/internal/types/scope"
pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/authtokens"
"github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/scopes"
@@ -43,8 +43,8 @@ func TestGetSelf(t *testing.T) {
tokenRepoFn := func() (*authtoken.Repository, error) {
return authtoken.NewRepository(rw, rw, kms)
}
serversRepoFn := func() (*servers.Repository, error) {
return servers.NewRepository(rw, rw, kms)
serversRepoFn := func() (*server.Repository, error) {
return server.NewRepository(rw, rw, kms)
}
a, err := authtokens.NewService(tokenRepoFn, iamRepoFn)
@@ -202,8 +202,8 @@ func TestList_Self(t *testing.T) {
tokenRepoFn := func() (*authtoken.Repository, error) {
return authtoken.NewRepository(rw, rw, kms)
}
serversRepoFn := func() (*servers.Repository, error) {
return servers.NewRepository(rw, rw, kms)
serversRepoFn := func() (*server.Repository, error) {
return server.NewRepository(rw, rw, kms)
}
// This will result in the scope having default permissions, which now
@@ -426,8 +426,8 @@ func TestDeleteSelf(t *testing.T) {
tokenRepoFn := func() (*authtoken.Repository, error) {
return authtoken.NewRepository(rw, rw, kms)
}
serversRepoFn := func() (*servers.Repository, error) {
return servers.NewRepository(rw, rw, kms)
serversRepoFn := func() (*server.Repository, error) {
return server.NewRepository(rw, rw, kms)
}
a, err := authtokens.NewService(tokenRepoFn, iamRepoFn)
@@ -14,7 +14,7 @@ import (
authpb "github.com/hashicorp/boundary/internal/gen/controller/auth"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/servers"
"github.com/hashicorp/boundary/internal/server"
"github.com/hashicorp/boundary/internal/session"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/hashicorp/boundary/testing/dbtest"
@@ -93,7 +93,7 @@ func BenchmarkSessionList(b *testing.B) {
pwRepo, err := password.NewRepository(rw, rw, kmsThing)
require.NoError(b, err)
serversRepo, err := servers.NewRepository(rw, rw, kmsThing)
serversRepo, err := server.NewRepository(rw, rw, kmsThing)
require.NoError(b, err)
iamRepoFn := func() (*iam.Repository, error) {
@@ -105,7 +105,7 @@ func BenchmarkSessionList(b *testing.B) {
authTokenRepoFn := func() (*authtoken.Repository, error) {
return authTokenRepo, nil
}
serversRepoFn := func() (*servers.Repository, error) {
serversRepoFn := func() (*server.Repository, error) {
return serversRepo, nil
}
@@ -19,7 +19,7 @@ import (
"github.com/hashicorp/boundary/internal/host/static"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/servers"
"github.com/hashicorp/boundary/internal/server"
"github.com/hashicorp/boundary/internal/session"
"github.com/hashicorp/boundary/internal/target"
"github.com/hashicorp/boundary/internal/target/tcp"
@@ -162,8 +162,8 @@ func TestList_Self(t *testing.T) {
tokenRepoFn := func() (*authtoken.Repository, error) {
return authtoken.NewRepository(rw, rw, kms)
}
serversRepoFn := func() (*servers.Repository, error) {
return servers.NewRepository(rw, rw, kms)
serversRepoFn := func() (*server.Repository, error) {
return server.NewRepository(rw, rw, kms)
}
o, pWithSessions := iam.TestScopes(t, iamRepo)
@@ -27,7 +27,7 @@ import (
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/requests"
"github.com/hashicorp/boundary/internal/servers"
"github.com/hashicorp/boundary/internal/server"
"github.com/hashicorp/boundary/internal/session"
"github.com/hashicorp/boundary/internal/target"
"github.com/hashicorp/boundary/internal/types/action"
@@ -115,7 +115,7 @@ func NewService(
return Service{}, errors.New(ctx, errors.InvalidParameter, op, "missing iam repository")
}
if serversRepoFn == nil {
return Service{}, errors.New(ctx, errors.InvalidParameter, op, "missing servers repository")
return Service{}, errors.New(ctx, errors.InvalidParameter, op, "missing server repository")
}
if sessionRepoFn == nil {
return Service{}, errors.New(ctx, errors.InvalidParameter, op, "missing session repository")
@@ -1918,7 +1918,7 @@ func validateAuthorizeSessionRequest(req *pbs.AuthorizeSessionRequest) error {
}
// workerList is a helper type to make the selection of workers clearer and more declarative.
type workerList []*servers.Worker
type workerList []*server.Worker
// addresses converts the slice of workers to a slice of their addresses
func (w workerList) addresses() []string {
@@ -1941,7 +1941,7 @@ func (w workerList) workerInfos() []*pb.WorkerInfo {
// filtered returns a new workerList where all elements contained in it are the
// ones which from the original workerList that pass the evaluator's evaluation.
func (w workerList) filtered(eval *bexpr.Evaluator) (workerList, error) {
var ret []*servers.Worker
var ret []*server.Worker
for _, worker := range w {
filterInput := map[string]interface{}{
"name": worker.GetName(),
@@ -5,7 +5,7 @@ import (
"testing"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/servers"
"github.com/hashicorp/boundary/internal/server"
"github.com/hashicorp/boundary/internal/types/scope"
pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/targets"
"github.com/hashicorp/go-bexpr"
@@ -24,9 +24,9 @@ func TestWorkerList_Addresses(t *testing.T) {
var tested workerList
for _, a := range addresses {
workerInfos = append(workerInfos, &pb.WorkerInfo{Address: a})
tested = append(tested, servers.NewWorker(scope.Global.String(),
servers.WithName(a),
servers.WithAddress(a)))
tested = append(tested, server.NewWorker(scope.Global.String(),
server.WithName(a),
server.WithAddress(a)))
}
assert.Equal(t, addresses, tested.addresses())
assert.Equal(t, workerInfos, tested.workerInfos())
@@ -35,20 +35,20 @@ func TestWorkerList_Addresses(t *testing.T) {
func TestWorkerList_Filter(t *testing.T) {
conn, _ := db.TestSetup(t, "postgres")
wrapper := db.TestWrapper(t)
var workers []*servers.Worker
var workers []*server.Worker
for i := 0; i < 5; i++ {
switch {
case i%2 == 0:
workers = append(workers, servers.TestKmsWorker(t, conn, wrapper,
servers.WithName(fmt.Sprintf("test_worker_%d", i)),
servers.WithWorkerTags(&servers.Tag{
workers = append(workers, server.TestKmsWorker(t, conn, wrapper,
server.WithName(fmt.Sprintf("test_worker_%d", i)),
server.WithWorkerTags(&server.Tag{
Key: fmt.Sprintf("key%d", i),
Value: fmt.Sprintf("value%d", i),
})))
default:
workers = append(workers, servers.TestPkiWorker(t, conn, wrapper,
servers.WithName(fmt.Sprintf("test_worker_%d", i)),
servers.WithWorkerTags(&servers.Tag{
workers = append(workers, server.TestPkiWorker(t, conn, wrapper,
server.WithName(fmt.Sprintf("test_worker_%d", i)),
server.WithWorkerTags(&server.Tag{
Key: "key",
Value: "configvalue",
})))
@@ -33,8 +33,8 @@ import (
"github.com/hashicorp/boundary/internal/plugin/host"
"github.com/hashicorp/boundary/internal/requests"
"github.com/hashicorp/boundary/internal/scheduler"
"github.com/hashicorp/boundary/internal/servers"
spb "github.com/hashicorp/boundary/internal/servers"
"github.com/hashicorp/boundary/internal/server"
spb "github.com/hashicorp/boundary/internal/server"
"github.com/hashicorp/boundary/internal/session"
"github.com/hashicorp/boundary/internal/target"
"github.com/hashicorp/boundary/internal/target/tcp"
@@ -85,8 +85,8 @@ func testService(t *testing.T, ctx context.Context, conn *db.DB, kms *kms.Kms, w
iamRepoFn := func() (*iam.Repository, error) {
return iam.TestRepo(t, conn, wrapper), nil
}
serversRepoFn := func() (*servers.Repository, error) {
return servers.NewRepository(rw, rw, kms)
serversRepoFn := func() (*server.Repository, error) {
return server.NewRepository(rw, rw, kms)
}
sessionRepoFn := func() (*session.Repository, error) {
return session.NewRepository(rw, rw, kms)
@@ -2365,8 +2365,8 @@ func TestAuthorizeSession(t *testing.T) {
iamRepoFn := func() (*iam.Repository, error) {
return iamRepo, nil
}
serversRepoFn := func() (*servers.Repository, error) {
return servers.NewRepository(rw, rw, kms)
serversRepoFn := func() (*server.Repository, error) {
return server.NewRepository(rw, rw, kms)
}
sessionRepoFn := func() (*session.Repository, error) {
return session.NewRepository(rw, rw, kms)
@@ -2529,7 +2529,7 @@ func TestAuthorizeSession(t *testing.T) {
require.NoError(t, err)
// Tell our DB that there is a worker ready to serve the data
servers.TestKmsWorker(t, conn, wrapper)
server.TestKmsWorker(t, conn, wrapper)
asRes1, err := s.AuthorizeSession(ctx, &pbs.AuthorizeSessionRequest{
Id: tar.GetPublicId(),
@@ -2625,8 +2625,8 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
iamRepoFn := func() (*iam.Repository, error) {
return iamRepo, nil
}
serversRepoFn := func() (*servers.Repository, error) {
return servers.NewRepository(rw, rw, kms)
serversRepoFn := func() (*server.Repository, error) {
return server.NewRepository(rw, rw, kms)
}
sessionRepoFn := func() (*session.Repository, error) {
return session.NewRepository(rw, rw, kms)
@@ -2874,7 +2874,7 @@ func TestAuthorizeSessionTypedCredentials(t *testing.T) {
require.NoError(t, err)
// Tell our DB that there is a worker ready to serve the data
servers.TestKmsWorker(t, conn, wrapper)
server.TestKmsWorker(t, conn, wrapper)
asRes, err := s.AuthorizeSession(ctx, &pbs.AuthorizeSessionRequest{
Id: tar.GetPublicId(),
@@ -2931,8 +2931,8 @@ func TestAuthorizeSession_Errors(t *testing.T) {
iamRepoFn := func() (*iam.Repository, error) {
return iamRepo, nil
}
serversRepoFn := func() (*servers.Repository, error) {
return servers.NewRepository(rw, rw, kms)
serversRepoFn := func() (*server.Repository, error) {
return server.NewRepository(rw, rw, kms)
}
sessionRepoFn := func() (*session.Repository, error) {
return session.NewRepository(rw, rw, kms)
@@ -3164,8 +3164,8 @@ func TestAddTargetCredentialLibraryPerms(t *testing.T) {
iamRepoFn := func() (*iam.Repository, error) {
return iam.TestRepo(t, conn, wrapper), nil
}
serversRepoFn := func() (*servers.Repository, error) {
return servers.NewRepository(rw, rw, kms)
serversRepoFn := func() (*server.Repository, error) {
return server.NewRepository(rw, rw, kms)
}
iamRepo := iam.TestRepo(t, conn, wrapper)
@@ -3250,8 +3250,8 @@ func TestSetTargetCredentialLibraryPerms(t *testing.T) {
iamRepoFn := func() (*iam.Repository, error) {
return iam.TestRepo(t, conn, wrapper), nil
}
serversRepoFn := func() (*servers.Repository, error) {
return servers.NewRepository(rw, rw, kms)
serversRepoFn := func() (*server.Repository, error) {
return server.NewRepository(rw, rw, kms)
}
iamRepo := iam.TestRepo(t, conn, wrapper)
@@ -3336,8 +3336,8 @@ func TestRemoveTargetCredentialLibraryPerms(t *testing.T) {
iamRepoFn := func() (*iam.Repository, error) {
return iam.TestRepo(t, conn, wrapper), nil
}
serversRepoFn := func() (*servers.Repository, error) {
return servers.NewRepository(rw, rw, kms)
serversRepoFn := func() (*server.Repository, error) {
return server.NewRepository(rw, rw, kms)
}
iamRepo := iam.TestRepo(t, conn, wrapper)
@@ -14,8 +14,8 @@ import (
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/requests"
"github.com/hashicorp/boundary/internal/servers"
"github.com/hashicorp/boundary/internal/servers/store"
"github.com/hashicorp/boundary/internal/server"
"github.com/hashicorp/boundary/internal/server/store"
"github.com/hashicorp/boundary/internal/types/action"
"github.com/hashicorp/boundary/internal/types/resource"
"github.com/hashicorp/boundary/internal/types/scope"
@@ -73,7 +73,7 @@ type Service struct {
func NewService(ctx context.Context, repo common.ServersRepoFactory, iamRepoFn common.IamRepoFactory) (Service, error) {
const op = "workers.NewService"
if repo == nil {
return Service{}, errors.New(ctx, errors.InvalidParameter, op, "missing servers repository")
return Service{}, errors.New(ctx, errors.InvalidParameter, op, "missing server repository")
}
if iamRepoFn == nil {
return Service{}, errors.New(ctx, errors.InvalidParameter, op, "missing iam repository")
@@ -297,19 +297,19 @@ func (s Service) UpdateWorker(ctx context.Context, req *pbs.UpdateWorkerRequest)
return &pbs.UpdateWorkerResponse{Item: item}, nil
}
func (s Service) listFromRepo(ctx context.Context, scopeIds []string) ([]*servers.Worker, error) {
func (s Service) listFromRepo(ctx context.Context, scopeIds []string) ([]*server.Worker, error) {
repo, err := s.repoFn()
if err != nil {
return nil, err
}
wl, err := repo.ListWorkers(ctx, scopeIds, servers.WithLiveness(-1))
wl, err := repo.ListWorkers(ctx, scopeIds, server.WithLiveness(-1))
if err != nil {
return nil, err
}
return wl, nil
}
func (s Service) getFromRepo(ctx context.Context, id string) (*servers.Worker, error) {
func (s Service) getFromRepo(ctx context.Context, id string) (*server.Worker, error) {
repo, err := s.repoFn()
if err != nil {
return nil, err
@@ -327,18 +327,18 @@ func (s Service) getFromRepo(ctx context.Context, id string) (*servers.Worker, e
return w, nil
}
func (s Service) createInRepo(ctx context.Context, worker *pb.Worker, creds *types.FetchNodeCredentialsRequest) (*servers.Worker, error) {
func (s Service) createInRepo(ctx context.Context, worker *pb.Worker, creds *types.FetchNodeCredentialsRequest) (*server.Worker, error) {
const op = "workers.(Service).createInRepo"
repo, err := s.repoFn()
if err != nil {
return nil, err
}
newWorker := servers.NewWorker(
newWorker := server.NewWorker(
worker.GetScopeId(),
servers.WithName(worker.GetName().GetValue()),
servers.WithDescription(worker.GetDescription().GetValue()),
server.WithName(worker.GetName().GetValue()),
server.WithDescription(worker.GetDescription().GetValue()),
)
retWorker, err := repo.CreateWorker(ctx, newWorker, servers.WithFetchNodeCredentialsRequest(creds))
retWorker, err := repo.CreateWorker(ctx, newWorker, server.WithFetchNodeCredentialsRequest(creds))
if err != nil {
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to create worker"))
}
@@ -361,16 +361,16 @@ func (s Service) deleteFromRepo(ctx context.Context, id string) (bool, error) {
return rows > 0, nil
}
func (s Service) updateInRepo(ctx context.Context, scopeId, id string, mask []string, item *pb.Worker) (*servers.Worker, error) {
func (s Service) updateInRepo(ctx context.Context, scopeId, id string, mask []string, item *pb.Worker) (*server.Worker, error) {
const op = "workers.(Service).updateInRepo"
var opts []servers.Option
var opts []server.Option
if desc := item.GetDescription(); desc != nil {
opts = append(opts, servers.WithDescription(desc.GetValue()))
opts = append(opts, server.WithDescription(desc.GetValue()))
}
if name := item.GetName(); name != nil {
opts = append(opts, servers.WithName(name.GetValue()))
opts = append(opts, server.WithName(name.GetValue()))
}
w := servers.NewWorker(scopeId, opts...)
w := server.NewWorker(scopeId, opts...)
w.PublicId = id
dbMask := maskManager.Translate(mask)
if len(dbMask) == 0 {
@@ -420,7 +420,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) auth.
return auth.Verify(ctx, opts...)
}
func toProto(ctx context.Context, in *servers.Worker, opt ...handlers.Option) (*pb.Worker, error) {
func toProto(ctx context.Context, in *server.Worker, opt ...handlers.Option) (*pb.Worker, error) {
const op = "workers.toProto"
opts := handlers.GetOpts(opt...)
if opts.WithOutputFields == nil {
@@ -522,7 +522,7 @@ func tagsToMapProto(in map[string][]string) (map[string]*structpb.ListValue, err
// * All required parameters are set
// * There are no conflicting parameters provided
func validateGetRequest(req *pbs.GetWorkerRequest) error {
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, servers.WorkerPrefix)
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, server.WorkerPrefix)
}
func validateListRequest(req *pbs.ListWorkersRequest) error {
@@ -540,7 +540,7 @@ func validateListRequest(req *pbs.ListWorkersRequest) error {
}
func validateDeleteRequest(req *pbs.DeleteWorkerRequest) error {
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, servers.WorkerPrefix)
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, server.WorkerPrefix)
}
func validateUpdateRequest(req *pbs.UpdateWorkerRequest) error {
@@ -567,7 +567,7 @@ func validateUpdateRequest(req *pbs.UpdateWorkerRequest) error {
badFields[globals.DescriptionField] = "Contains non-printable characters."
}
return badFields
}, servers.WorkerPrefix)
}, server.WorkerPrefix)
}
func validateCreateRequest(req *pbs.CreateWorkerLedRequest) error {
@@ -15,7 +15,7 @@ import (
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/servers"
"github.com/hashicorp/boundary/internal/server"
"github.com/hashicorp/boundary/internal/types/action"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/scopes"
@@ -59,17 +59,17 @@ func TestGet(t *testing.T) {
}
rw := db.New(conn)
kms := kms.TestKms(t, conn, wrap)
repo, err := servers.NewRepository(rw, rw, kms)
repo, err := server.NewRepository(rw, rw, kms)
require.NoError(t, err)
repoFn := func() (*servers.Repository, error) {
repoFn := func() (*server.Repository, error) {
return repo, nil
}
kmsWorker := servers.TestKmsWorker(t, conn, wrap,
servers.WithName("test kms worker names"),
servers.WithDescription("test kms worker description"),
servers.WithAddress("test kms worker address"),
servers.WithWorkerTags(&servers.Tag{Key: "key", Value: "val"}))
kmsWorker := server.TestKmsWorker(t, conn, wrap,
server.WithName("test kms worker names"),
server.WithDescription("test kms worker description"),
server.WithAddress("test kms worker address"),
server.WithWorkerTags(&server.Tag{Key: "key", Value: "val"}))
kmsAuthzActions := make([]string, len(testAuthorizedActions))
copy(kmsAuthzActions, testAuthorizedActions)
@@ -97,21 +97,21 @@ func TestGet(t *testing.T) {
}
var pkiWorkerKeyId string
pkiWorker := servers.TestPkiWorker(t, conn, wrap,
servers.WithName("test pki worker names"),
servers.WithDescription("test pki worker description"),
servers.WithTestPkiWorkerAuthorizedKeyId(&pkiWorkerKeyId))
pkiWorker := server.TestPkiWorker(t, conn, wrap,
server.WithName("test pki worker names"),
server.WithDescription("test pki worker description"),
server.WithTestPkiWorkerAuthorizedKeyId(&pkiWorkerKeyId))
// Add config tags to the created worker
pkiWorker, err = repo.UpsertWorkerStatus(context.Background(),
servers.NewWorker(pkiWorker.GetScopeId(),
servers.WithAddress("test kms worker address"),
servers.WithWorkerTags(&servers.Tag{
server.NewWorker(pkiWorker.GetScopeId(),
server.WithAddress("test kms worker address"),
server.WithWorkerTags(&server.Tag{
Key: "config",
Value: "test",
})),
servers.WithUpdateTags(true),
servers.WithPublicId(pkiWorker.GetPublicId()),
servers.WithKeyId(pkiWorkerKeyId))
server.WithUpdateTags(true),
server.WithPublicId(pkiWorker.GetPublicId()),
server.WithKeyId(pkiWorkerKeyId))
require.NoError(t, err)
wantPkiWorker := &pb.Worker{
@@ -157,7 +157,7 @@ func TestGet(t *testing.T) {
},
{
name: "Get a non-existent Worker",
req: &pbs.GetWorkerRequest{Id: servers.WorkerPrefix + "_DoesntExis"},
req: &pbs.GetWorkerRequest{Id: server.WorkerPrefix + "_DoesntExis"},
res: nil,
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -169,7 +169,7 @@ func TestGet(t *testing.T) {
},
{
name: "Space in id",
req: &pbs.GetWorkerRequest{Id: servers.WorkerPrefix + "_1 23456789"},
req: &pbs.GetWorkerRequest{Id: server.WorkerPrefix + "_1 23456789"},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
@@ -200,13 +200,13 @@ func TestList(t *testing.T) {
}
rw := db.New(conn)
kms := kms.TestKms(t, conn, wrap)
repoFn := func() (*servers.Repository, error) {
return servers.NewRepository(rw, rw, kms)
repoFn := func() (*server.Repository, error) {
return server.NewRepository(rw, rw, kms)
}
var wantKmsWorkers []*pb.Worker
for i := 0; i < 10; i++ {
w := servers.TestKmsWorker(t, conn, wrap, servers.WithName(fmt.Sprintf("kms-worker%d", i)))
w := server.TestKmsWorker(t, conn, wrap, server.WithName(fmt.Sprintf("kms-worker%d", i)))
kmsAuthzActions := make([]string, len(testAuthorizedActions))
copy(kmsAuthzActions, testAuthorizedActions)
wantKmsWorkers = append(wantKmsWorkers, &pb.Worker{
@@ -227,7 +227,7 @@ func TestList(t *testing.T) {
var wantPkiWorkers []*pb.Worker
for i := 0; i < 10; i++ {
w := servers.TestPkiWorker(t, conn, wrap, servers.WithName(fmt.Sprintf("pki-worker%d", i)))
w := server.TestPkiWorker(t, conn, wrap, server.WithName(fmt.Sprintf("pki-worker%d", i)))
wantPkiWorkers = append(wantPkiWorkers, &pb.Worker{
Id: w.GetPublicId(),
ScopeId: w.GetScopeId(),
@@ -332,15 +332,15 @@ func TestDelete(t *testing.T) {
}
rw := db.New(conn)
kms := kms.TestKms(t, conn, wrap)
repoFn := func() (*servers.Repository, error) {
return servers.NewRepository(rw, rw, kms)
repoFn := func() (*server.Repository, error) {
return server.NewRepository(rw, rw, kms)
}
ctx := context.Background()
s, err := NewService(ctx, repoFn, iamRepoFn)
require.NoError(t, err, "Error when getting new worker service.")
w := servers.TestKmsWorker(t, conn, wrap)
w := server.TestKmsWorker(t, conn, wrap)
cases := []struct {
name string
@@ -360,7 +360,7 @@ func TestDelete(t *testing.T) {
name: "Delete bad worker id",
scopeId: w.GetScopeId(),
req: &pbs.DeleteWorkerRequest{
Id: servers.WorkerPrefix + "_doesntexis",
Id: server.WorkerPrefix + "_doesntexis",
},
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -398,15 +398,15 @@ func TestUpdate(t *testing.T) {
iamRepoFn := func() (*iam.Repository, error) {
return iamRepo, nil
}
repo, err := servers.NewRepository(rw, rw, kms)
repo, err := server.NewRepository(rw, rw, kms)
require.NoError(t, err)
repoFn := func() (*servers.Repository, error) {
repoFn := func() (*server.Repository, error) {
return repo, nil
}
wkr := servers.TestPkiWorker(t, conn, wrapper,
servers.WithName("default"),
servers.WithDescription("default"))
wkr := server.TestPkiWorker(t, conn, wrapper,
server.WithName("default"),
server.WithDescription("default"))
version := wkr.GetVersion()
@@ -630,7 +630,7 @@ func TestUpdate(t *testing.T) {
{
name: "Update a Non Existing Worker",
req: &pbs.UpdateWorkerRequest{
Id: servers.WorkerPrefix + "_DoesntExis",
Id: server.WorkerPrefix + "_DoesntExis",
UpdateMask: &field_mask.FieldMask{
Paths: []string{"description"},
},
@@ -809,15 +809,15 @@ func TestUpdate_KMS(t *testing.T) {
iamRepoFn := func() (*iam.Repository, error) {
return iamRepo, nil
}
repo, err := servers.NewRepository(rw, rw, kms)
repo, err := server.NewRepository(rw, rw, kms)
require.NoError(t, err)
repoFn := func() (*servers.Repository, error) {
repoFn := func() (*server.Repository, error) {
return repo, nil
}
wkr := servers.TestKmsWorker(t, conn, wrapper,
servers.WithName("default"),
servers.WithDescription("default"))
wkr := server.TestKmsWorker(t, conn, wrapper,
server.WithName("default"),
server.WithDescription("default"))
toMerge := &pbs.UpdateWorkerRequest{
Id: wkr.GetPublicId(),
@@ -891,9 +891,9 @@ func TestUpdate_BadVersion(t *testing.T) {
_, proj := iam.TestScopes(t, iamRepo)
rw := db.New(conn)
repo, err := servers.NewRepository(rw, rw, kms)
repo, err := server.NewRepository(rw, rw, kms)
require.NoError(t, err, "Couldn't create new worker repo.")
repoFn := func() (*servers.Repository, error) {
repoFn := func() (*server.Repository, error) {
return repo, nil
}
ctx := context.Background()
@@ -901,7 +901,7 @@ func TestUpdate_BadVersion(t *testing.T) {
workerService, err := NewService(ctx, repoFn, iamRepoFn)
require.NoError(t, err, "Failed to create a new host set service.")
wkr := servers.TestPkiWorker(t, conn, wrapper)
wkr := server.TestPkiWorker(t, conn, wrapper)
upTar, err := workerService.UpdateWorker(auth.DisabledAuthTestContext(iamRepoFn, proj.GetPublicId()), &pbs.UpdateWorkerRequest{
Id: wkr.GetPublicId(),
@@ -926,8 +926,8 @@ func TestCreateWorkerLed(t *testing.T) {
}
rw := db.New(conn)
testKms := kms.TestKms(t, conn, testRootWrapper)
repoFn := func() (*servers.Repository, error) {
return servers.NewRepository(rw, rw, testKms)
repoFn := func() (*server.Repository, error) {
return server.NewRepository(rw, rw, testKms)
}
testCtx := context.Background()
@@ -935,7 +935,7 @@ func TestCreateWorkerLed(t *testing.T) {
require.NoError(t, err, "Error when getting new worker service.")
// Get an initial set of authorized node credentials
rootStorage, err := servers.NewRepositoryStorage(testCtx, rw, rw, testKms)
rootStorage, err := server.NewRepositoryStorage(testCtx, rw, rw, testKms)
require.NoError(t, err)
_, err = rotation.RotateRootCertificates(testCtx, rootStorage)
require.NoError(t, err)
@@ -1180,8 +1180,8 @@ func TestCreateWorkerLed(t *testing.T) {
{
name: "create-error",
service: func() Service {
repoFn := func() (*servers.Repository, error) {
return servers.NewRepository(rw, &db.Db{}, testKms)
repoFn := func() (*server.Repository, error) {
return server.NewRepository(rw, &db.Db{}, testKms)
}
testSrv, err := NewService(testCtx, repoFn, iamRepoFn)
require.NoError(t, err, "Error when getting new worker service.")
@@ -1207,13 +1207,13 @@ func TestCreateWorkerLed(t *testing.T) {
// CreateWorker(...) and test the createInRepo(...) failure
// path if the repoFn returns and err.
cnt := 0
repoFn := func() (*servers.Repository, error) {
repoFn := func() (*server.Repository, error) {
cnt = cnt + 1
switch {
case cnt > 1:
return nil, errors.New(testCtx, errors.Internal, "bad-repo-function", "error creating repo")
default:
return servers.NewRepository(rw, rw, testKms)
return server.NewRepository(rw, rw, testKms)
}
}
testSrv, err := NewService(testCtx, repoFn, iamRepoFn)
+1 -1
View File
@@ -60,7 +60,7 @@ func requestCtxInterceptor(
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing auth token repo function")
}
if serversRepoFn == nil {
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing servers repo function")
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing server repo function")
}
if kms == nil {
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing kms")
@@ -22,7 +22,7 @@ import (
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/observability/event"
"github.com/hashicorp/boundary/internal/servers"
"github.com/hashicorp/boundary/internal/server"
"github.com/hashicorp/go-hclog"
"github.com/mr-tron/base58"
"github.com/stretchr/testify/assert"
@@ -45,8 +45,8 @@ func Test_requestCtxInterceptor(t *testing.T) {
atRepoFn := func() (*authtoken.Repository, error) {
return authtoken.NewRepository(rw, rw, kmsCache)
}
serversRepoFn := func() (*servers.Repository, error) {
return servers.NewRepository(rw, rw, kmsCache)
serversRepoFn := func() (*server.Repository, error) {
return server.NewRepository(rw, rw, kmsCache)
}
validGatewayTicket := "valid-ticket"
@@ -143,7 +143,7 @@ func Test_requestCtxInterceptor(t *testing.T) {
eventer: testEventer,
wantFactoryErr: true,
wantFactoryErrMatch: errors.T(errors.InvalidParameter),
wantFactoryErrContains: "missing servers repo function",
wantFactoryErrContains: "missing server repo function",
},
{
name: "missing-kms",
+2 -2
View File
@@ -26,7 +26,7 @@ import (
"github.com/hashicorp/boundary/internal/intglobals"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/observability/event"
"github.com/hashicorp/boundary/internal/servers"
"github.com/hashicorp/boundary/internal/server"
"github.com/hashicorp/boundary/internal/session"
"github.com/hashicorp/go-hclog"
wrapping "github.com/hashicorp/go-kms-wrapping/v2"
@@ -112,7 +112,7 @@ func (tc *TestController) AuthTokenRepo() *authtoken.Repository {
return repo
}
func (tc *TestController) ServersRepo() *servers.Repository {
func (tc *TestController) ServersRepo() *server.Repository {
repo, err := tc.c.ServersRepoFn()
if err != nil {
tc.t.Fatal(err)
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"math/rand"
"time"
"github.com/hashicorp/boundary/internal/servers/store"
"github.com/hashicorp/boundary/internal/server/store"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/observability/event"
@@ -12,7 +12,7 @@ import (
"strings"
"github.com/hashicorp/boundary/internal/cmd/base"
"github.com/hashicorp/boundary/internal/servers"
"github.com/hashicorp/boundary/internal/server"
wrapping "github.com/hashicorp/go-kms-wrapping/v2"
"google.golang.org/protobuf/proto"
)
@@ -99,9 +99,9 @@ func (c Controller) v1WorkerAuthConfig(protos []string) (*tls.Config, *base.Work
// Check for replays
serversRepo, err := c.ServersRepoFn()
if err != nil {
return nil, nil, fmt.Errorf("unable to fetch servers repo: %w", err)
return nil, nil, fmt.Errorf("unable to fetch server repo: %w", err)
}
if err := serversRepo.AddNonce(c.baseContext, info.ConnectionNonce, servers.NoncePurposeWorkerAuth); err != nil {
if err := serversRepo.AddNonce(c.baseContext, info.ConnectionNonce, server.NoncePurposeWorkerAuth); err != nil {
return nil, nil, fmt.Errorf("unable to add connection nonce to database: %w", err)
}