feat: add initial migration hook
This commit is contained in:
1 parent
79866a287f
commit
27e9f775be
174 files changed
+4234
-2180
No files matched your search
@@ -22,7 +22,7 @@ type authzProtectedEntityProvider interface {
|
||||
// "where clause" style of argument: if the set of scopes is populated these
|
||||
// are the scopes to limit to (e.g. to put in a where clause). An empty set
|
||||
// of scopes means to look in *all* scopes, not none!
|
||||
FetchAuthzProtectedEntitiesByScope(ctx context.Context, scopeIds []string) (map[string][]boundary.AuthzProtectedEntity, error)
|
||||
FetchAuthzProtectedEntitiesByScope(ctx context.Context, projectIds []string) (map[string][]boundary.AuthzProtectedEntity, error)
|
||||
}
|
||||
|
||||
// ResourceInfo contains information about a particular resource
|
||||
|
||||
+1
-1
@@ -465,7 +465,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) auth.
|
||||
res.Error = handlers.NotFoundError()
|
||||
return res
|
||||
}
|
||||
opts = append(opts, auth.WithScopeId(cs.GetScopeId()))
|
||||
opts = append(opts, auth.WithScopeId(cs.GetProjectId()))
|
||||
default:
|
||||
res.Error = errors.New(ctx, errors.InvalidParameter, op, "unrecognized credential store subtype from id")
|
||||
return res
|
||||
|
||||
+3
-3
@@ -729,7 +729,7 @@ func TestGet(t *testing.T) {
|
||||
Item: &pb.CredentialLibrary{
|
||||
Id: unspecifiedLib.GetPublicId(),
|
||||
CredentialStoreId: unspecifiedLib.GetStoreId(),
|
||||
Scope: &scopepb.ScopeInfo{Id: store.GetScopeId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
|
||||
Scope: &scopepb.ScopeInfo{Id: store.GetProjectId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
|
||||
Type: vault.Subtype.String(),
|
||||
AuthorizedActions: testAuthorizedActions,
|
||||
CreatedTime: unspecifiedLib.CreateTime.GetTimestamp(),
|
||||
@@ -751,7 +751,7 @@ func TestGet(t *testing.T) {
|
||||
Item: &pb.CredentialLibrary{
|
||||
Id: userPassLib.GetPublicId(),
|
||||
CredentialStoreId: userPassLib.GetStoreId(),
|
||||
Scope: &scopepb.ScopeInfo{Id: store.GetScopeId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
|
||||
Scope: &scopepb.ScopeInfo{Id: store.GetProjectId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
|
||||
Type: vault.Subtype.String(),
|
||||
AuthorizedActions: testAuthorizedActions,
|
||||
CreatedTime: userPassLib.CreateTime.GetTimestamp(),
|
||||
@@ -783,7 +783,7 @@ func TestGet(t *testing.T) {
|
||||
Item: &pb.CredentialLibrary{
|
||||
Id: sshPkLib.GetPublicId(),
|
||||
CredentialStoreId: sshPkLib.GetStoreId(),
|
||||
Scope: &scopepb.ScopeInfo{Id: store.GetScopeId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
|
||||
Scope: &scopepb.ScopeInfo{Id: store.GetProjectId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
|
||||
Type: vault.Subtype.String(),
|
||||
AuthorizedActions: testAuthorizedActions,
|
||||
CreatedTime: sshPkLib.CreateTime.GetTimestamp(),
|
||||
|
||||
@@ -502,7 +502,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) auth.
|
||||
res.Error = handlers.NotFoundError()
|
||||
return res
|
||||
}
|
||||
opts = append(opts, auth.WithScopeId(cs.GetScopeId()))
|
||||
opts = append(opts, auth.WithScopeId(cs.GetProjectId()))
|
||||
|
||||
return auth.Verify(ctx, opts...)
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ func TestGet(t *testing.T) {
|
||||
Item: &pb.Credential{
|
||||
Id: upCred.GetPublicId(),
|
||||
CredentialStoreId: upCred.GetStoreId(),
|
||||
Scope: &scopepb.ScopeInfo{Id: store.GetScopeId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
|
||||
Scope: &scopepb.ScopeInfo{Id: store.GetProjectId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
|
||||
Type: credential.UsernamePasswordSubtype.String(),
|
||||
AuthorizedActions: testAuthorizedActions,
|
||||
CreatedTime: upCred.CreateTime.GetTimestamp(),
|
||||
@@ -250,7 +250,7 @@ func TestGet(t *testing.T) {
|
||||
Item: &pb.Credential{
|
||||
Id: upCredPrev.GetPublicId(),
|
||||
CredentialStoreId: upCred.GetStoreId(),
|
||||
Scope: &scopepb.ScopeInfo{Id: store.GetScopeId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
|
||||
Scope: &scopepb.ScopeInfo{Id: store.GetProjectId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
|
||||
Type: credential.UsernamePasswordSubtype.String(),
|
||||
AuthorizedActions: testAuthorizedActions,
|
||||
CreatedTime: upCredPrev.CreateTime.GetTimestamp(),
|
||||
@@ -272,7 +272,7 @@ func TestGet(t *testing.T) {
|
||||
Item: &pb.Credential{
|
||||
Id: spkCred.GetPublicId(),
|
||||
CredentialStoreId: spkCred.GetStoreId(),
|
||||
Scope: &scopepb.ScopeInfo{Id: store.GetScopeId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
|
||||
Scope: &scopepb.ScopeInfo{Id: store.GetProjectId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
|
||||
Type: credential.SshPrivateKeySubtype.String(),
|
||||
AuthorizedActions: testAuthorizedActions,
|
||||
CreatedTime: spkCred.CreateTime.GetTimestamp(),
|
||||
@@ -294,7 +294,7 @@ func TestGet(t *testing.T) {
|
||||
Item: &pb.Credential{
|
||||
Id: spkCredWithPass.GetPublicId(),
|
||||
CredentialStoreId: spkCredWithPass.GetStoreId(),
|
||||
Scope: &scopepb.ScopeInfo{Id: store.GetScopeId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
|
||||
Scope: &scopepb.ScopeInfo{Id: store.GetProjectId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
|
||||
Type: credential.SshPrivateKeySubtype.String(),
|
||||
AuthorizedActions: testAuthorizedActions,
|
||||
CreatedTime: spkCredWithPass.CreateTime.GetTimestamp(),
|
||||
|
||||
@@ -160,7 +160,7 @@ func (s Service) ListCredentialStores(ctx context.Context, req *pbs.ListCredenti
|
||||
}
|
||||
for _, item := range csl {
|
||||
res.Id = item.GetPublicId()
|
||||
res.ScopeId = item.GetScopeId()
|
||||
res.ScopeId = item.GetProjectId()
|
||||
authorizedActions := authResults.FetchActionSetForId(ctx, item.GetPublicId(), IdActions, auth.WithResource(&res)).Strings()
|
||||
if len(authorizedActions) == 0 {
|
||||
continue
|
||||
@@ -170,7 +170,7 @@ func (s Service) ListCredentialStores(ctx context.Context, req *pbs.ListCredenti
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
outputOpts = append(outputOpts, handlers.WithOutputFields(&outputFields))
|
||||
if outputFields.Has(globals.ScopeField) {
|
||||
outputOpts = append(outputOpts, handlers.WithScope(scopeInfoMap[item.GetScopeId()]))
|
||||
outputOpts = append(outputOpts, handlers.WithScope(scopeInfoMap[item.GetProjectId()]))
|
||||
}
|
||||
if outputFields.Has(globals.AuthorizedActionsField) {
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authorizedActions))
|
||||
@@ -586,7 +586,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) auth.
|
||||
res.Error = handlers.NotFoundError()
|
||||
return res
|
||||
}
|
||||
parentId = cs.GetScopeId()
|
||||
parentId = cs.GetProjectId()
|
||||
|
||||
case static.Subtype:
|
||||
var err error
|
||||
@@ -599,7 +599,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) auth.
|
||||
res.Error = handlers.NotFoundError()
|
||||
return res
|
||||
}
|
||||
parentId = cs.GetScopeId()
|
||||
parentId = cs.GetProjectId()
|
||||
}
|
||||
opts = append(opts, auth.WithId(id))
|
||||
}
|
||||
@@ -621,7 +621,7 @@ func toProto(in credential.Store, opt ...handlers.Option) (*pb.CredentialStore,
|
||||
out.Id = in.GetPublicId()
|
||||
}
|
||||
if outputFields.Has(globals.ScopeIdField) {
|
||||
out.ScopeId = in.GetScopeId()
|
||||
out.ScopeId = in.GetProjectId()
|
||||
}
|
||||
if outputFields.Has(globals.TypeField) {
|
||||
out.Type = subtypes.SubtypeFromId(domain, in.GetPublicId()).String()
|
||||
|
||||
+6
-6
@@ -779,8 +779,8 @@ func TestGet(t *testing.T) {
|
||||
res: &pbs.GetCredentialStoreResponse{
|
||||
Item: &pb.CredentialStore{
|
||||
Id: vaultStore.GetPublicId(),
|
||||
ScopeId: vaultStore.GetScopeId(),
|
||||
Scope: &scopepb.ScopeInfo{Id: vaultStore.GetScopeId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
|
||||
ScopeId: vaultStore.GetProjectId(),
|
||||
Scope: &scopepb.ScopeInfo{Id: vaultStore.GetProjectId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
|
||||
Type: vault.Subtype.String(),
|
||||
AuthorizedActions: testAuthorizedActions,
|
||||
AuthorizedCollectionActions: testAuthorizedVaultCollectionActions,
|
||||
@@ -804,8 +804,8 @@ func TestGet(t *testing.T) {
|
||||
res: &pbs.GetCredentialStoreResponse{
|
||||
Item: &pb.CredentialStore{
|
||||
Id: staticStore.GetPublicId(),
|
||||
ScopeId: staticStore.GetScopeId(),
|
||||
Scope: &scopepb.ScopeInfo{Id: staticStore.GetScopeId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
|
||||
ScopeId: staticStore.GetProjectId(),
|
||||
Scope: &scopepb.ScopeInfo{Id: staticStore.GetProjectId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
|
||||
Type: credstatic.Subtype.String(),
|
||||
AuthorizedActions: testAuthorizedActions,
|
||||
AuthorizedCollectionActions: testAuthorizedStaticCollectionActions,
|
||||
@@ -821,8 +821,8 @@ func TestGet(t *testing.T) {
|
||||
res: &pbs.GetCredentialStoreResponse{
|
||||
Item: &pb.CredentialStore{
|
||||
Id: staticStorePrev.GetPublicId(),
|
||||
ScopeId: staticStorePrev.GetScopeId(),
|
||||
Scope: &scopepb.ScopeInfo{Id: staticStorePrev.GetScopeId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
|
||||
ScopeId: staticStorePrev.GetProjectId(),
|
||||
Scope: &scopepb.ScopeInfo{Id: staticStorePrev.GetProjectId(), Type: scope.Project.String(), ParentScopeId: prj.GetParentId()},
|
||||
Type: credstatic.Subtype.String(),
|
||||
AuthorizedActions: testAuthorizedActions,
|
||||
AuthorizedCollectionActions: testAuthorizedStaticCollectionActions,
|
||||
|
||||
@@ -118,7 +118,7 @@ func (s Service) ListHostCatalogs(ctx context.Context, req *pbs.ListHostCatalogs
|
||||
if authResults.Error != nil {
|
||||
// If it's forbidden, and it's a recursive request, and they're
|
||||
// successfully authenticated but just not authorized, keep going as we
|
||||
// may have authorization on downstream scopes. Or, if they've not
|
||||
// may have authorization on downstream projects. Or, if they've not
|
||||
// authenticated, still process in case u_anon has permissions.
|
||||
if (authResults.Error == handlers.ForbiddenError() || authResults.Error == handlers.UnauthenticatedError()) &&
|
||||
req.GetRecursive() &&
|
||||
@@ -156,7 +156,7 @@ func (s Service) ListHostCatalogs(ctx context.Context, req *pbs.ListHostCatalogs
|
||||
}
|
||||
for _, item := range items {
|
||||
res.Id = item.GetPublicId()
|
||||
res.ScopeId = item.GetScopeId()
|
||||
res.ScopeId = item.GetProjectId()
|
||||
authorizedActions := authResults.FetchActionSetForId(ctx, item.GetPublicId(), IdActions, auth.WithResource(&res)).Strings()
|
||||
if len(authorizedActions) == 0 {
|
||||
continue
|
||||
@@ -166,7 +166,7 @@ func (s Service) ListHostCatalogs(ctx context.Context, req *pbs.ListHostCatalogs
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
outputOpts = append(outputOpts, handlers.WithOutputFields(&outputFields))
|
||||
if outputFields.Has(globals.ScopeField) {
|
||||
outputOpts = append(outputOpts, handlers.WithScope(scopeInfoMap[item.GetScopeId()]))
|
||||
outputOpts = append(outputOpts, handlers.WithScope(scopeInfoMap[item.GetProjectId()]))
|
||||
}
|
||||
if outputFields.Has(globals.AuthorizedActionsField) {
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authorizedActions))
|
||||
@@ -436,12 +436,12 @@ func (s Service) getFromRepo(ctx context.Context, id string) (host.Catalog, *plu
|
||||
return cat, plg, nil
|
||||
}
|
||||
|
||||
func (s Service) listFromRepo(ctx context.Context, scopeIds []string) ([]host.Catalog, map[string]*plugins.PluginInfo, error) {
|
||||
func (s Service) listFromRepo(ctx context.Context, projectIds []string) ([]host.Catalog, map[string]*plugins.PluginInfo, error) {
|
||||
repo, err := s.staticRepoFn()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
ul, err := repo.ListCatalogs(ctx, scopeIds)
|
||||
ul, err := repo.ListCatalogs(ctx, projectIds)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -453,7 +453,7 @@ func (s Service) listFromRepo(ctx context.Context, scopeIds []string) ([]host.Ca
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
pl, plgs, err := pluginRepo.ListCatalogs(ctx, scopeIds)
|
||||
pl, plgs, err := pluginRepo.ListCatalogs(ctx, projectIds)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
@@ -664,7 +664,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) auth.
|
||||
res.Error = handlers.NotFoundError()
|
||||
return res
|
||||
}
|
||||
parentId = cat.GetScopeId()
|
||||
parentId = cat.GetProjectId()
|
||||
opts = append(opts, auth.WithId(id))
|
||||
case plugin.Subtype:
|
||||
repo, err := s.pluginHostRepoFn()
|
||||
@@ -681,7 +681,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) auth.
|
||||
res.Error = handlers.NotFoundError()
|
||||
return res
|
||||
}
|
||||
parentId = cat.GetScopeId()
|
||||
parentId = cat.GetProjectId()
|
||||
opts = append(opts, auth.WithId(id))
|
||||
}
|
||||
}
|
||||
@@ -713,7 +713,7 @@ func toProto(ctx context.Context, in host.Catalog, opt ...handlers.Option) (*pb.
|
||||
out.Id = in.GetPublicId()
|
||||
}
|
||||
if outputFields.Has(globals.ScopeIdField) {
|
||||
out.ScopeId = in.GetScopeId()
|
||||
out.ScopeId = in.GetProjectId()
|
||||
}
|
||||
if outputFields.Has(globals.TypeField) {
|
||||
switch in.(type) {
|
||||
@@ -774,7 +774,7 @@ func toProto(ctx context.Context, in host.Catalog, opt ...handlers.Option) (*pb.
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func toStorageStaticCatalog(ctx context.Context, scopeId string, item *pb.HostCatalog) (*static.HostCatalog, error) {
|
||||
func toStorageStaticCatalog(ctx context.Context, projectId string, item *pb.HostCatalog) (*static.HostCatalog, error) {
|
||||
const op = "host_catalog_service.toStorageStaticCatalog"
|
||||
var opts []static.Option
|
||||
if name := item.GetName(); name != nil {
|
||||
@@ -783,14 +783,14 @@ func toStorageStaticCatalog(ctx context.Context, scopeId string, item *pb.HostCa
|
||||
if desc := item.GetDescription(); desc != nil {
|
||||
opts = append(opts, static.WithDescription(desc.GetValue()))
|
||||
}
|
||||
hc, err := static.NewHostCatalog(scopeId, opts...)
|
||||
hc, err := static.NewHostCatalog(projectId, opts...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to build host catalog"))
|
||||
}
|
||||
return hc, nil
|
||||
}
|
||||
|
||||
func toStoragePluginCatalog(ctx context.Context, scopeId, plgId string, item *pb.HostCatalog) (*plugin.HostCatalog, error) {
|
||||
func toStoragePluginCatalog(ctx context.Context, projectId, plgId string, item *pb.HostCatalog) (*plugin.HostCatalog, error) {
|
||||
const op = "host_catalog_service.toStoragePluginCatalog"
|
||||
var opts []plugin.Option
|
||||
if name := item.GetName(); name != nil {
|
||||
@@ -805,7 +805,7 @@ func toStoragePluginCatalog(ctx context.Context, scopeId, plgId string, item *pb
|
||||
if secrets := item.GetSecrets(); secrets != nil {
|
||||
opts = append(opts, plugin.WithSecrets(secrets))
|
||||
}
|
||||
hc, err := plugin.NewHostCatalog(ctx, scopeId, plgId, opts...)
|
||||
hc, err := plugin.NewHostCatalog(ctx, projectId, plgId, opts...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("Unable to build host set for creation"))
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ func TestGet_Static(t *testing.T) {
|
||||
|
||||
pHostCatalog := &pb.HostCatalog{
|
||||
Id: hc.GetPublicId(),
|
||||
ScopeId: hc.GetScopeId(),
|
||||
ScopeId: hc.GetProjectId(),
|
||||
Scope: &scopepb.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: proj.GetParentId()},
|
||||
CreatedTime: hc.CreateTime.GetTimestamp(),
|
||||
UpdatedTime: hc.UpdateTime.GetTimestamp(),
|
||||
@@ -194,7 +194,7 @@ func TestGet_Plugin(t *testing.T) {
|
||||
|
||||
pHostCatalog := &pb.HostCatalog{
|
||||
Id: hc.GetPublicId(),
|
||||
ScopeId: hc.GetScopeId(),
|
||||
ScopeId: hc.GetProjectId(),
|
||||
Scope: &scopepb.ScopeInfo{
|
||||
Id: proj.GetPublicId(),
|
||||
Type: scope.Project.String(),
|
||||
@@ -306,7 +306,7 @@ func TestList(t *testing.T) {
|
||||
for _, hc := range static.TestCatalogs(t, conn, pWithCatalogs.GetPublicId(), 3) {
|
||||
wantSomeCatalogs = append(wantSomeCatalogs, &pb.HostCatalog{
|
||||
Id: hc.GetPublicId(),
|
||||
ScopeId: hc.GetScopeId(),
|
||||
ScopeId: hc.GetProjectId(),
|
||||
CreatedTime: hc.GetCreateTime().GetTimestamp(),
|
||||
UpdatedTime: hc.GetUpdateTime().GetTimestamp(),
|
||||
Scope: &scopepb.ScopeInfo{Id: pWithCatalogs.GetPublicId(), Type: scope.Project.String(), ParentScopeId: oWithCatalogs.GetPublicId()},
|
||||
@@ -324,7 +324,7 @@ func TestList(t *testing.T) {
|
||||
hc := plugin.TestCatalog(t, conn, pWithCatalogs.GetPublicId(), plg.GetPublicId())
|
||||
cat := &pb.HostCatalog{
|
||||
Id: hc.GetPublicId(),
|
||||
ScopeId: hc.GetScopeId(),
|
||||
ScopeId: hc.GetProjectId(),
|
||||
CreatedTime: hc.GetCreateTime().GetTimestamp(),
|
||||
UpdatedTime: hc.GetUpdateTime().GetTimestamp(),
|
||||
Scope: &scopepb.ScopeInfo{Id: pWithCatalogs.GetPublicId(), Type: scope.Project.String(), ParentScopeId: oWithCatalogs.GetPublicId()},
|
||||
@@ -347,7 +347,7 @@ func TestList(t *testing.T) {
|
||||
for _, hc := range static.TestCatalogs(t, conn, pWithOtherCatalogs.GetPublicId(), 3) {
|
||||
wantOtherCatalogs = append(wantOtherCatalogs, &pb.HostCatalog{
|
||||
Id: hc.GetPublicId(),
|
||||
ScopeId: hc.GetScopeId(),
|
||||
ScopeId: hc.GetProjectId(),
|
||||
CreatedTime: hc.GetCreateTime().GetTimestamp(),
|
||||
UpdatedTime: hc.GetUpdateTime().GetTimestamp(),
|
||||
Scope: &scopepb.ScopeInfo{Id: pWithOtherCatalogs.GetPublicId(), Type: scope.Project.String(), ParentScopeId: oWithOtherCatalogs.GetPublicId()},
|
||||
@@ -364,7 +364,7 @@ func TestList(t *testing.T) {
|
||||
hc := plugin.TestCatalog(t, conn, pWithOtherCatalogs.GetPublicId(), diffPlg.GetPublicId())
|
||||
wantOtherCatalogs = append(wantOtherCatalogs, &pb.HostCatalog{
|
||||
Id: hc.GetPublicId(),
|
||||
ScopeId: hc.GetScopeId(),
|
||||
ScopeId: hc.GetProjectId(),
|
||||
CreatedTime: hc.GetCreateTime().GetTimestamp(),
|
||||
UpdatedTime: hc.GetUpdateTime().GetTimestamp(),
|
||||
Scope: &scopepb.ScopeInfo{Id: pWithOtherCatalogs.GetPublicId(), Type: scope.Project.String(), ParentScopeId: oWithOtherCatalogs.GetPublicId()},
|
||||
@@ -1056,7 +1056,7 @@ func TestUpdate_Static(t *testing.T) {
|
||||
res: &pbs.UpdateHostCatalogResponse{
|
||||
Item: &pb.HostCatalog{
|
||||
Id: hc.GetPublicId(),
|
||||
ScopeId: hc.GetScopeId(),
|
||||
ScopeId: hc.GetProjectId(),
|
||||
Scope: &scopepb.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: proj.GetParentId()},
|
||||
Name: &wrappers.StringValue{Value: "new"},
|
||||
Description: &wrappers.StringValue{Value: "desc"},
|
||||
@@ -1082,7 +1082,7 @@ func TestUpdate_Static(t *testing.T) {
|
||||
res: &pbs.UpdateHostCatalogResponse{
|
||||
Item: &pb.HostCatalog{
|
||||
Id: hc.GetPublicId(),
|
||||
ScopeId: hc.GetScopeId(),
|
||||
ScopeId: hc.GetProjectId(),
|
||||
Scope: &scopepb.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: proj.GetParentId()},
|
||||
Name: &wrappers.StringValue{Value: "new"},
|
||||
Description: &wrappers.StringValue{Value: "desc"},
|
||||
@@ -1138,7 +1138,7 @@ func TestUpdate_Static(t *testing.T) {
|
||||
res: &pbs.UpdateHostCatalogResponse{
|
||||
Item: &pb.HostCatalog{
|
||||
Id: hc.GetPublicId(),
|
||||
ScopeId: hc.GetScopeId(),
|
||||
ScopeId: hc.GetProjectId(),
|
||||
Scope: &scopepb.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: proj.GetParentId()},
|
||||
Description: &wrappers.StringValue{Value: "default"},
|
||||
CreatedTime: hc.GetCreateTime().GetTimestamp(),
|
||||
@@ -1161,7 +1161,7 @@ func TestUpdate_Static(t *testing.T) {
|
||||
res: &pbs.UpdateHostCatalogResponse{
|
||||
Item: &pb.HostCatalog{
|
||||
Id: hc.GetPublicId(),
|
||||
ScopeId: hc.GetScopeId(),
|
||||
ScopeId: hc.GetProjectId(),
|
||||
Scope: &scopepb.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: proj.GetParentId()},
|
||||
Name: &wrappers.StringValue{Value: "default"},
|
||||
CreatedTime: hc.GetCreateTime().GetTimestamp(),
|
||||
@@ -1185,7 +1185,7 @@ func TestUpdate_Static(t *testing.T) {
|
||||
res: &pbs.UpdateHostCatalogResponse{
|
||||
Item: &pb.HostCatalog{
|
||||
Id: hc.GetPublicId(),
|
||||
ScopeId: hc.GetScopeId(),
|
||||
ScopeId: hc.GetProjectId(),
|
||||
Scope: &scopepb.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: proj.GetParentId()},
|
||||
Name: &wrappers.StringValue{Value: "updated"},
|
||||
Description: &wrappers.StringValue{Value: "default"},
|
||||
@@ -1210,7 +1210,7 @@ func TestUpdate_Static(t *testing.T) {
|
||||
res: &pbs.UpdateHostCatalogResponse{
|
||||
Item: &pb.HostCatalog{
|
||||
Id: hc.GetPublicId(),
|
||||
ScopeId: hc.GetScopeId(),
|
||||
ScopeId: hc.GetProjectId(),
|
||||
Scope: &scopepb.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: proj.GetParentId()},
|
||||
Name: &wrappers.StringValue{Value: "default"},
|
||||
Description: &wrappers.StringValue{Value: "notignored"},
|
||||
|
||||
@@ -474,7 +474,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (host.Set, []host.H
|
||||
return hs, hl, plg, nil
|
||||
}
|
||||
|
||||
func (s Service) createInRepo(ctx context.Context, scopeId, catalogId string, item *pb.HostSet) (host.Set, *plugins.PluginInfo, error) {
|
||||
func (s Service) createInRepo(ctx context.Context, projectId, catalogId string, item *pb.HostSet) (host.Set, *plugins.PluginInfo, error) {
|
||||
const op = "host_sets.(Service).createInRepo"
|
||||
if item == nil {
|
||||
return nil, nil, errors.New(ctx, errors.InvalidParameter, op, "missing item")
|
||||
@@ -491,7 +491,7 @@ func (s Service) createInRepo(ctx context.Context, scopeId, catalogId string, it
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
out, err := repo.CreateSet(ctx, scopeId, h)
|
||||
out, err := repo.CreateSet(ctx, projectId, h)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to create host set"))
|
||||
}
|
||||
@@ -508,7 +508,7 @@ func (s Service) createInRepo(ctx context.Context, scopeId, catalogId string, it
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
out, hsplg, err := repo.CreateSet(ctx, scopeId, h)
|
||||
out, hsplg, err := repo.CreateSet(ctx, projectId, h)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to create host set"))
|
||||
}
|
||||
@@ -523,7 +523,7 @@ func (s Service) createInRepo(ctx context.Context, scopeId, catalogId string, it
|
||||
return hSet, plg, nil
|
||||
}
|
||||
|
||||
func (s Service) updateStaticInRepo(ctx context.Context, scopeId, catalogId string, req *pbs.UpdateHostSetRequest) (host.Set, []host.Host, error) {
|
||||
func (s Service) updateStaticInRepo(ctx context.Context, projectId, catalogId string, req *pbs.UpdateHostSetRequest) (host.Set, []host.Host, error) {
|
||||
const op = "host_sets.(Service).updateStaticInRepo"
|
||||
item := req.GetItem()
|
||||
h, err := toStorageStaticSet(ctx, catalogId, item)
|
||||
@@ -539,7 +539,7 @@ func (s Service) updateStaticInRepo(ctx context.Context, scopeId, catalogId stri
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
out, m, rowsUpdated, err := repo.UpdateSet(ctx, scopeId, h, item.GetVersion(), dbMask)
|
||||
out, m, rowsUpdated, err := repo.UpdateSet(ctx, projectId, h, item.GetVersion(), dbMask)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to update host set"))
|
||||
}
|
||||
@@ -553,7 +553,7 @@ func (s Service) updateStaticInRepo(ctx context.Context, scopeId, catalogId stri
|
||||
return out, hl, nil
|
||||
}
|
||||
|
||||
func (s Service) updatePluginInRepo(ctx context.Context, scopeId string, req *pbs.UpdateHostSetRequest) (host.Set, []host.Host, *plugins.PluginInfo, error) {
|
||||
func (s Service) updatePluginInRepo(ctx context.Context, projectId string, req *pbs.UpdateHostSetRequest) (host.Set, []host.Host, *plugins.PluginInfo, error) {
|
||||
const op = "host_sets.(Service).updatePluginInRepo"
|
||||
item := req.GetItem()
|
||||
h, err := toStoragePluginSet(ctx, "", item)
|
||||
@@ -569,7 +569,7 @@ func (s Service) updatePluginInRepo(ctx context.Context, scopeId string, req *pb
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
out, hosts, plg, rowsUpdated, err := repo.UpdateSet(ctx, scopeId, h, item.GetVersion(), dbMask)
|
||||
out, hosts, plg, rowsUpdated, err := repo.UpdateSet(ctx, projectId, h, item.GetVersion(), dbMask)
|
||||
if err != nil {
|
||||
return nil, nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to update host set"))
|
||||
}
|
||||
@@ -583,18 +583,18 @@ func (s Service) updatePluginInRepo(ctx context.Context, scopeId string, req *pb
|
||||
return out, hl, toPluginInfo(plg), nil
|
||||
}
|
||||
|
||||
func (s Service) updateInRepo(ctx context.Context, scopeId, catalogId string, req *pbs.UpdateHostSetRequest) (hs host.Set, hosts []host.Host, plg *plugins.PluginInfo, err error) {
|
||||
func (s Service) updateInRepo(ctx context.Context, projectId, catalogId string, req *pbs.UpdateHostSetRequest) (hs host.Set, hosts []host.Host, plg *plugins.PluginInfo, err error) {
|
||||
const op = "host_sets.(Service).updateInRepo"
|
||||
switch subtypes.SubtypeFromId(domain, req.GetId()) {
|
||||
case static.Subtype:
|
||||
hs, hosts, err = s.updateStaticInRepo(ctx, scopeId, catalogId, req)
|
||||
hs, hosts, err = s.updateStaticInRepo(ctx, projectId, catalogId, req)
|
||||
case plugin.Subtype:
|
||||
hs, hosts, plg, err = s.updatePluginInRepo(ctx, scopeId, req)
|
||||
hs, hosts, plg, err = s.updatePluginInRepo(ctx, projectId, req)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (s Service) deleteFromRepo(ctx context.Context, scopeId, id string) (bool, error) {
|
||||
func (s Service) deleteFromRepo(ctx context.Context, projectId, id string) (bool, error) {
|
||||
const op = "host_sets.(Service).deleteFromRepo"
|
||||
rows := 0
|
||||
switch subtypes.SubtypeFromId(domain, id) {
|
||||
@@ -603,7 +603,7 @@ func (s Service) deleteFromRepo(ctx context.Context, scopeId, id string) (bool,
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
rows, err = repo.DeleteSet(ctx, scopeId, id)
|
||||
rows, err = repo.DeleteSet(ctx, projectId, id)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(ctx, err, op, errors.WithMsg("unable to delete host"))
|
||||
}
|
||||
@@ -612,7 +612,7 @@ func (s Service) deleteFromRepo(ctx context.Context, scopeId, id string) (bool,
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
rows, err = repo.DeleteSet(ctx, scopeId, id)
|
||||
rows, err = repo.DeleteSet(ctx, projectId, id)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(ctx, err, op, errors.WithMsg("unable to delete host"))
|
||||
}
|
||||
@@ -654,13 +654,13 @@ func (s Service) listFromRepo(ctx context.Context, catalogId string, opt ...host
|
||||
return sets, plg, nil
|
||||
}
|
||||
|
||||
func (s Service) addInRepo(ctx context.Context, scopeId, setId string, hostIds []string, version uint32) (*static.HostSet, []host.Host, error) {
|
||||
func (s Service) addInRepo(ctx context.Context, projectId, setId string, hostIds []string, version uint32) (*static.HostSet, []host.Host, error) {
|
||||
const op = "host_sets.(Service).addInRepo"
|
||||
repo, err := s.staticRepoFn()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
_, err = repo.AddSetMembers(ctx, scopeId, setId, version, strutil.RemoveDuplicates(hostIds, false))
|
||||
_, err = repo.AddSetMembers(ctx, projectId, setId, version, strutil.RemoveDuplicates(hostIds, false))
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("Unable to add hosts to host set"))
|
||||
}
|
||||
@@ -678,13 +678,13 @@ func (s Service) addInRepo(ctx context.Context, scopeId, setId string, hostIds [
|
||||
return out, hl, nil
|
||||
}
|
||||
|
||||
func (s Service) setInRepo(ctx context.Context, scopeId, setId string, hostIds []string, version uint32) (*static.HostSet, []host.Host, error) {
|
||||
func (s Service) setInRepo(ctx context.Context, projectId, setId string, hostIds []string, version uint32) (*static.HostSet, []host.Host, error) {
|
||||
const op = "host_sets.(Service).setInRepo"
|
||||
repo, err := s.staticRepoFn()
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
_, _, err = repo.SetSetMembers(ctx, scopeId, setId, version, strutil.RemoveDuplicates(hostIds, false))
|
||||
_, _, err = repo.SetSetMembers(ctx, projectId, setId, version, strutil.RemoveDuplicates(hostIds, false))
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("Unable to set hosts in host set"))
|
||||
}
|
||||
@@ -703,13 +703,13 @@ func (s Service) setInRepo(ctx context.Context, scopeId, setId string, hostIds [
|
||||
return out, hl, nil
|
||||
}
|
||||
|
||||
func (s Service) removeInRepo(ctx context.Context, scopeId, setId string, hostIds []string, version uint32) (*static.HostSet, []host.Host, error) {
|
||||
func (s Service) removeInRepo(ctx context.Context, projectId, setId string, hostIds []string, version uint32) (*static.HostSet, []host.Host, error) {
|
||||
const op = "host_sets.(Service).removeInRepo"
|
||||
repo, err := s.staticRepoFn()
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
_, err = repo.DeleteSetMembers(ctx, scopeId, setId, version, strutil.RemoveDuplicates(hostIds, false))
|
||||
_, err = repo.DeleteSetMembers(ctx, projectId, setId, version, strutil.RemoveDuplicates(hostIds, false))
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("Unable to remove hosts from host set"))
|
||||
}
|
||||
@@ -801,7 +801,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
|
||||
}
|
||||
cat = pc
|
||||
}
|
||||
opts = append(opts, auth.WithScopeId(cat.GetScopeId()), auth.WithPin(parentId))
|
||||
opts = append(opts, auth.WithScopeId(cat.GetProjectId()), auth.WithPin(parentId))
|
||||
return cat, auth.Verify(ctx, opts...)
|
||||
}
|
||||
|
||||
|
||||
@@ -497,30 +497,30 @@ func TestDelete_Static(t *testing.T) {
|
||||
require.NoError(t, err, "Couldn't create a new host set service.")
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
scopeId string
|
||||
req *pbs.DeleteHostSetRequest
|
||||
res *pbs.DeleteHostSetResponse
|
||||
err error
|
||||
name string
|
||||
projectId string
|
||||
req *pbs.DeleteHostSetRequest
|
||||
res *pbs.DeleteHostSetResponse
|
||||
err error
|
||||
}{
|
||||
{
|
||||
name: "Delete an Existing Host Set",
|
||||
scopeId: proj.GetPublicId(),
|
||||
name: "Delete an Existing Host Set",
|
||||
projectId: proj.GetPublicId(),
|
||||
req: &pbs.DeleteHostSetRequest{
|
||||
Id: h.GetPublicId(),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Delete bad id Host Set",
|
||||
scopeId: proj.GetPublicId(),
|
||||
name: "Delete bad id Host Set",
|
||||
projectId: proj.GetPublicId(),
|
||||
req: &pbs.DeleteHostSetRequest{
|
||||
Id: static.HostSetPrefix + "_doesntexis",
|
||||
},
|
||||
err: handlers.ApiErrorWithCode(codes.NotFound),
|
||||
},
|
||||
{
|
||||
name: "Bad Host Id formatting",
|
||||
scopeId: proj.GetPublicId(),
|
||||
name: "Bad Host Id formatting",
|
||||
projectId: proj.GetPublicId(),
|
||||
req: &pbs.DeleteHostSetRequest{
|
||||
Id: static.HostSetPrefix + "_bad_format",
|
||||
},
|
||||
@@ -530,7 +530,7 @@ func TestDelete_Static(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
got, gErr := s.DeleteHostSet(auth.DisabledAuthTestContext(iamRepoFn, tc.scopeId), tc.req)
|
||||
got, gErr := s.DeleteHostSet(auth.DisabledAuthTestContext(iamRepoFn, tc.projectId), tc.req)
|
||||
if tc.err != nil {
|
||||
require.Error(gErr)
|
||||
assert.True(errors.Is(gErr, tc.err), "DeleteHostSet(%+v) got error %v, wanted %v", tc.req, gErr, tc.err)
|
||||
@@ -574,30 +574,30 @@ func TestDelete_Plugin(t *testing.T) {
|
||||
require.NoError(t, err, "Couldn't create a new host set service.")
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
scopeId string
|
||||
req *pbs.DeleteHostSetRequest
|
||||
res *pbs.DeleteHostSetResponse
|
||||
err error
|
||||
name string
|
||||
projectId string
|
||||
req *pbs.DeleteHostSetRequest
|
||||
res *pbs.DeleteHostSetResponse
|
||||
err error
|
||||
}{
|
||||
{
|
||||
name: "Delete an Existing Host Set",
|
||||
scopeId: proj.GetPublicId(),
|
||||
name: "Delete an Existing Host Set",
|
||||
projectId: proj.GetPublicId(),
|
||||
req: &pbs.DeleteHostSetRequest{
|
||||
Id: h.GetPublicId(),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Delete bad id Host Set",
|
||||
scopeId: proj.GetPublicId(),
|
||||
name: "Delete bad id Host Set",
|
||||
projectId: proj.GetPublicId(),
|
||||
req: &pbs.DeleteHostSetRequest{
|
||||
Id: plugin.HostSetPrefix + "_doesntexis",
|
||||
},
|
||||
err: handlers.ApiErrorWithCode(codes.NotFound),
|
||||
},
|
||||
{
|
||||
name: "Bad Host Id formatting",
|
||||
scopeId: proj.GetPublicId(),
|
||||
name: "Bad Host Id formatting",
|
||||
projectId: proj.GetPublicId(),
|
||||
req: &pbs.DeleteHostSetRequest{
|
||||
Id: plugin.HostSetPrefix + "_bad_format",
|
||||
},
|
||||
@@ -607,7 +607,7 @@ func TestDelete_Plugin(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
got, gErr := s.DeleteHostSet(auth.DisabledAuthTestContext(iamRepoFn, tc.scopeId), tc.req)
|
||||
got, gErr := s.DeleteHostSet(auth.DisabledAuthTestContext(iamRepoFn, tc.projectId), tc.req)
|
||||
if tc.err != nil {
|
||||
require.Error(gErr)
|
||||
assert.True(errors.Is(gErr, tc.err), "DeleteHostSet(%+v) got error %v, wanted %v", tc.req, gErr, tc.err)
|
||||
|
||||
@@ -325,7 +325,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (host.Host, *plugin
|
||||
return h, plg, nil
|
||||
}
|
||||
|
||||
func (s Service) createInRepo(ctx context.Context, scopeId, catalogId string, item *pb.Host) (*static.Host, error) {
|
||||
func (s Service) createInRepo(ctx context.Context, projectId, catalogId string, item *pb.Host) (*static.Host, error) {
|
||||
const op = "hosts.(Service).createInRepo"
|
||||
ha := item.GetStaticHostAttributes()
|
||||
var opts []static.Option
|
||||
@@ -347,7 +347,7 @@ func (s Service) createInRepo(ctx context.Context, scopeId, catalogId string, it
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
out, err := repo.CreateHost(ctx, scopeId, h)
|
||||
out, err := repo.CreateHost(ctx, projectId, h)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("Unable to create host"))
|
||||
}
|
||||
@@ -357,7 +357,7 @@ func (s Service) createInRepo(ctx context.Context, scopeId, catalogId string, it
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (s Service) updateInRepo(ctx context.Context, scopeId, catalogId, id string, mask []string, item *pb.Host) (*static.Host, error) {
|
||||
func (s Service) updateInRepo(ctx context.Context, projectId, catalogId, id string, mask []string, item *pb.Host) (*static.Host, error) {
|
||||
const op = "hosts.(Service).updateInRepo"
|
||||
ha := item.GetStaticHostAttributes()
|
||||
var opts []static.Option
|
||||
@@ -383,7 +383,7 @@ func (s Service) updateInRepo(ctx context.Context, scopeId, catalogId, id string
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out, rowsUpdated, err := repo.UpdateHost(ctx, scopeId, h, item.GetVersion(), dbMask)
|
||||
out, rowsUpdated, err := repo.UpdateHost(ctx, projectId, h, item.GetVersion(), dbMask)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to update host"))
|
||||
}
|
||||
@@ -393,13 +393,13 @@ func (s Service) updateInRepo(ctx context.Context, scopeId, catalogId, id string
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (s Service) deleteFromRepo(ctx context.Context, scopeId, id string) (bool, error) {
|
||||
func (s Service) deleteFromRepo(ctx context.Context, projectId, id string) (bool, error) {
|
||||
const op = "hosts.(Service).deleteFromRepo"
|
||||
repo, err := s.staticRepoFn()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
rows, err := repo.DeleteHost(ctx, scopeId, id)
|
||||
rows, err := repo.DeleteHost(ctx, projectId, id)
|
||||
if err != nil {
|
||||
return false, errors.Wrap(ctx, err, op, errors.WithMsg("unable to delete host"))
|
||||
}
|
||||
@@ -510,7 +510,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
|
||||
}
|
||||
cat = plcat
|
||||
}
|
||||
opts = append(opts, auth.WithScopeId(cat.GetScopeId()), auth.WithPin(parentId))
|
||||
opts = append(opts, auth.WithScopeId(cat.GetProjectId()), auth.WithPin(parentId))
|
||||
return cat, auth.Verify(ctx, opts...)
|
||||
}
|
||||
|
||||
|
||||
@@ -519,38 +519,38 @@ func TestDelete(t *testing.T) {
|
||||
require.NoError(t, err, "Couldn't create a new host set service.")
|
||||
|
||||
cases := []struct {
|
||||
name string
|
||||
scopeId string
|
||||
req *pbs.DeleteHostRequest
|
||||
res *pbs.DeleteHostResponse
|
||||
err error
|
||||
name string
|
||||
projectId string
|
||||
req *pbs.DeleteHostRequest
|
||||
res *pbs.DeleteHostResponse
|
||||
err error
|
||||
}{
|
||||
{
|
||||
name: "Delete an Existing Host",
|
||||
scopeId: proj.GetPublicId(),
|
||||
name: "Delete an Existing Host",
|
||||
projectId: proj.GetPublicId(),
|
||||
req: &pbs.DeleteHostRequest{
|
||||
Id: h.GetPublicId(),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Delete a plugin Host",
|
||||
scopeId: proj.GetPublicId(),
|
||||
name: "Delete a plugin Host",
|
||||
projectId: proj.GetPublicId(),
|
||||
req: &pbs.DeleteHostRequest{
|
||||
Id: pluginH.GetPublicId(),
|
||||
},
|
||||
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
|
||||
},
|
||||
{
|
||||
name: "Delete bad id Host",
|
||||
scopeId: proj.GetPublicId(),
|
||||
name: "Delete bad id Host",
|
||||
projectId: proj.GetPublicId(),
|
||||
req: &pbs.DeleteHostRequest{
|
||||
Id: static.HostPrefix + "_doesntexis",
|
||||
},
|
||||
err: handlers.ApiErrorWithCode(codes.NotFound),
|
||||
},
|
||||
{
|
||||
name: "Bad Host Id formatting",
|
||||
scopeId: proj.GetPublicId(),
|
||||
name: "Bad Host Id formatting",
|
||||
projectId: proj.GetPublicId(),
|
||||
req: &pbs.DeleteHostRequest{
|
||||
Id: static.HostPrefix + "_bad_format",
|
||||
},
|
||||
@@ -560,7 +560,7 @@ func TestDelete(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
got, gErr := s.DeleteHost(auth.DisabledAuthTestContext(iamRepoFn, tc.scopeId), tc.req)
|
||||
got, gErr := s.DeleteHost(auth.DisabledAuthTestContext(iamRepoFn, tc.projectId), tc.req)
|
||||
if tc.err != nil {
|
||||
require.Error(gErr)
|
||||
assert.True(errors.Is(gErr, tc.err), "DeleteHost(%+v) got error %v, wanted %v", tc.req, gErr, tc.err)
|
||||
|
||||
@@ -89,7 +89,7 @@ func (s Service) GetSession(ctx context.Context, req *pbs.GetSessionRequest) (*p
|
||||
}
|
||||
outputFields = authResults.FetchOutputFields(perms.Resource{
|
||||
Id: ses.GetPublicId(),
|
||||
ScopeId: ses.ScopeId,
|
||||
ScopeId: ses.ProjectId,
|
||||
Type: resource.Session,
|
||||
}, action.Read).SelfOrDefaults(authResults.UserId)
|
||||
} else {
|
||||
@@ -187,10 +187,10 @@ func (s Service) ListSessions(ctx context.Context, req *pbs.ListSessionsRequest)
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
outputOpts = append(outputOpts, handlers.WithOutputFields(&outputFields))
|
||||
if outputFields.Has(globals.ScopeField) {
|
||||
outputOpts = append(outputOpts, handlers.WithScope(scopeResourceInfo.ScopeResourceMap[item.ScopeId].ScopeInfo))
|
||||
outputOpts = append(outputOpts, handlers.WithScope(scopeResourceInfo.ScopeResourceMap[item.ProjectId].ScopeInfo))
|
||||
}
|
||||
if outputFields.Has(globals.AuthorizedActionsField) {
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(scopeResourceInfo.ScopeResourceMap[item.ScopeId].Resources[item.PublicId].AuthorizedActions.Strings()))
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(scopeResourceInfo.ScopeResourceMap[item.ProjectId].Resources[item.PublicId].AuthorizedActions.Strings()))
|
||||
}
|
||||
|
||||
item, err := toProto(ctx, item, outputOpts...)
|
||||
@@ -235,7 +235,7 @@ func (s Service) CancelSession(ctx context.Context, req *pbs.CancelSessionReques
|
||||
}
|
||||
outputFields = authResults.FetchOutputFields(perms.Resource{
|
||||
Id: ses.GetPublicId(),
|
||||
ScopeId: ses.ScopeId,
|
||||
ScopeId: ses.ProjectId,
|
||||
Type: resource.Session,
|
||||
}, action.Cancel).SelfOrDefaults(authResults.UserId)
|
||||
} else {
|
||||
@@ -357,7 +357,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) auth.
|
||||
res.Error = handlers.NotFoundError()
|
||||
return res
|
||||
}
|
||||
parentId = t.ScopeId
|
||||
parentId = t.ProjectId
|
||||
opts = append(opts, auth.WithId(id))
|
||||
default:
|
||||
res.Error = stderrors.New("unsupported action")
|
||||
@@ -379,7 +379,7 @@ func toProto(ctx context.Context, in *session.Session, opt ...handlers.Option) (
|
||||
out.Id = in.GetPublicId()
|
||||
}
|
||||
if outputFields.Has(globals.ScopeIdField) {
|
||||
out.ScopeId = in.ScopeId
|
||||
out.ScopeId = in.ProjectId
|
||||
}
|
||||
if outputFields.Has(globals.TargetIdField) {
|
||||
out.TargetId = in.TargetId
|
||||
|
||||
@@ -67,7 +67,7 @@ func TestGetSession(t *testing.T) {
|
||||
TargetId: tar.GetPublicId(),
|
||||
HostSetId: hs.GetPublicId(),
|
||||
AuthTokenId: at.GetPublicId(),
|
||||
ScopeId: p.GetPublicId(),
|
||||
ProjectId: p.GetPublicId(),
|
||||
Endpoint: "tcp://127.0.0.1:22",
|
||||
})
|
||||
|
||||
@@ -101,7 +101,7 @@ func TestGetSession(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "Get a session",
|
||||
scopeId: sess.ScopeId,
|
||||
scopeId: sess.ProjectId,
|
||||
req: &pbs.GetSessionRequest{Id: sess.GetPublicId()},
|
||||
res: &pbs.GetSessionResponse{Item: wireSess},
|
||||
},
|
||||
@@ -185,7 +185,7 @@ func TestList_Self(t *testing.T) {
|
||||
TargetId: tar.GetPublicId(),
|
||||
HostSetId: hs.GetPublicId(),
|
||||
AuthTokenId: at.GetPublicId(),
|
||||
ScopeId: pWithSessions.GetPublicId(),
|
||||
ProjectId: pWithSessions.GetPublicId(),
|
||||
Endpoint: "tcp://127.0.0.1:22",
|
||||
})
|
||||
|
||||
@@ -279,7 +279,7 @@ func TestList(t *testing.T) {
|
||||
TargetId: tar.GetPublicId(),
|
||||
HostSetId: hs.GetPublicId(),
|
||||
AuthTokenId: at.GetPublicId(),
|
||||
ScopeId: pWithSessions.GetPublicId(),
|
||||
ProjectId: pWithSessions.GetPublicId(),
|
||||
Endpoint: "tcp://127.0.0.1:22",
|
||||
})
|
||||
|
||||
@@ -318,7 +318,7 @@ func TestList(t *testing.T) {
|
||||
TargetId: tarOther.GetPublicId(),
|
||||
HostSetId: hsOther.GetPublicId(),
|
||||
AuthTokenId: atOther.GetPublicId(),
|
||||
ScopeId: pWithOtherSessions.GetPublicId(),
|
||||
ProjectId: pWithOtherSessions.GetPublicId(),
|
||||
Endpoint: "tcp://127.0.0.1:22",
|
||||
})
|
||||
|
||||
@@ -356,7 +356,7 @@ func TestList(t *testing.T) {
|
||||
TargetId: tar.GetPublicId(),
|
||||
HostSetId: hs.GetPublicId(),
|
||||
AuthTokenId: at.GetPublicId(),
|
||||
ScopeId: pWithSessions.GetPublicId(),
|
||||
ProjectId: pWithSessions.GetPublicId(),
|
||||
Endpoint: "tcp://127.0.0.1:22",
|
||||
})
|
||||
|
||||
@@ -541,7 +541,7 @@ func TestCancel(t *testing.T) {
|
||||
TargetId: tar.GetPublicId(),
|
||||
HostSetId: hs.GetPublicId(),
|
||||
AuthTokenId: at.GetPublicId(),
|
||||
ScopeId: p.GetPublicId(),
|
||||
ProjectId: p.GetPublicId(),
|
||||
Endpoint: "tcp://127.0.0.1:22",
|
||||
})
|
||||
|
||||
@@ -575,13 +575,13 @@ func TestCancel(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "Cancel a session",
|
||||
scopeId: sess.ScopeId,
|
||||
scopeId: sess.ProjectId,
|
||||
req: &pbs.CancelSessionRequest{Id: sess.GetPublicId()},
|
||||
res: &pbs.CancelSessionResponse{Item: wireSess},
|
||||
},
|
||||
{
|
||||
name: "Already canceled",
|
||||
scopeId: sess.ScopeId,
|
||||
scopeId: sess.ProjectId,
|
||||
req: &pbs.CancelSessionRequest{Id: sess.GetPublicId()},
|
||||
res: &pbs.CancelSessionResponse{Item: wireSess},
|
||||
},
|
||||
|
||||
@@ -231,10 +231,10 @@ func (s Service) ListTargets(ctx context.Context, req *pbs.ListTargetsRequest) (
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
outputOpts = append(outputOpts, handlers.WithOutputFields(&outputFields))
|
||||
if outputFields.Has(globals.ScopeField) {
|
||||
outputOpts = append(outputOpts, handlers.WithScope(scopeResourceInfo.ScopeResourceMap[item.GetScopeId()].ScopeInfo))
|
||||
outputOpts = append(outputOpts, handlers.WithScope(scopeResourceInfo.ScopeResourceMap[item.GetProjectId()].ScopeInfo))
|
||||
}
|
||||
if outputFields.Has(globals.AuthorizedActionsField) {
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(scopeResourceInfo.ScopeResourceMap[item.GetScopeId()].Resources[item.GetPublicId()].AuthorizedActions.Strings()))
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(scopeResourceInfo.ScopeResourceMap[item.GetProjectId()].Resources[item.GetPublicId()].AuthorizedActions.Strings()))
|
||||
}
|
||||
|
||||
item, err := toProto(ctx, item, nil, nil, outputOpts...)
|
||||
@@ -753,8 +753,8 @@ func (s Service) AuthorizeSession(ctx context.Context, req *pbs.AuthorizeSession
|
||||
}
|
||||
authResults := s.authResult(ctx, req.GetId(), action.AuthorizeSession,
|
||||
target.WithName(req.GetName()),
|
||||
target.WithScopeId(req.GetScopeId()),
|
||||
target.WithScopeName(req.GetScopeName()),
|
||||
target.WithProjectId(req.GetScopeId()),
|
||||
target.WithProjectName(req.GetScopeName()),
|
||||
)
|
||||
if authResults.Error != nil {
|
||||
return nil, authResults.Error
|
||||
@@ -958,7 +958,7 @@ func (s Service) AuthorizeSession(ctx context.Context, req *pbs.AuthorizeSession
|
||||
TargetId: t.GetPublicId(),
|
||||
HostSetId: chosenEndpoint.SetId,
|
||||
AuthTokenId: authResults.AuthTokenId,
|
||||
ScopeId: authResults.Scope.Id,
|
||||
ProjectId: authResults.Scope.Id,
|
||||
Endpoint: endpointUrl.String(),
|
||||
ExpirationTime: ×tamp.Timestamp{Timestamp: expTime},
|
||||
ConnectionLimit: t.GetSessionConnectionLimit(),
|
||||
@@ -1001,7 +1001,7 @@ func (s Service) AuthorizeSession(ctx context.Context, req *pbs.AuthorizeSession
|
||||
|
||||
// Remove duplicate requests
|
||||
staticIds = strutil.RemoveDuplicates(staticIds, false)
|
||||
creds, err := credRepo.Retrieve(ctx, t.GetScopeId(), staticIds)
|
||||
creds, err := credRepo.Retrieve(ctx, t.GetProjectId(), staticIds)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
@@ -1058,7 +1058,7 @@ func (s Service) AuthorizeSession(ctx context.Context, req *pbs.AuthorizeSession
|
||||
|
||||
if len(workerCreds) > 0 {
|
||||
// store credentials in repo, worker will request creds when a connection is established
|
||||
err = sessionRepo.AddSessionCredentials(ctx, sess.ScopeId, sess.PublicId, workerCreds)
|
||||
err = sessionRepo.AddSessionCredentials(ctx, sess.ProjectId, sess.PublicId, workerCreds)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
@@ -1433,7 +1433,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type, looku
|
||||
return res
|
||||
}
|
||||
id = t.GetPublicId()
|
||||
parentId = t.GetScopeId()
|
||||
parentId = t.GetProjectId()
|
||||
opts = append(opts, auth.WithId(id))
|
||||
}
|
||||
opts = append(opts, auth.WithScopeId(parentId))
|
||||
@@ -1455,7 +1455,7 @@ func toProto(ctx context.Context, in target.Target, hostSources []target.HostSou
|
||||
out.Id = in.GetPublicId()
|
||||
}
|
||||
if outputFields.Has(globals.ScopeIdField) {
|
||||
out.ScopeId = in.GetScopeId()
|
||||
out.ScopeId = in.GetProjectId()
|
||||
}
|
||||
if outputFields.Has(globals.TypeField) {
|
||||
out.Type = in.GetType().String()
|
||||
|
||||
@@ -666,7 +666,7 @@ func TestUpdate(t *testing.T) {
|
||||
res: &pbs.UpdateTargetResponse{
|
||||
Item: &pb.Target{
|
||||
Id: tar.GetPublicId(),
|
||||
ScopeId: tar.GetScopeId(),
|
||||
ScopeId: tar.GetProjectId(),
|
||||
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
|
||||
Name: wrapperspb.String("name"),
|
||||
Description: wrapperspb.String("desc"),
|
||||
@@ -702,7 +702,7 @@ func TestUpdate(t *testing.T) {
|
||||
res: &pbs.UpdateTargetResponse{
|
||||
Item: &pb.Target{
|
||||
Id: tar.GetPublicId(),
|
||||
ScopeId: tar.GetScopeId(),
|
||||
ScopeId: tar.GetProjectId(),
|
||||
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
|
||||
Name: wrapperspb.String("name"),
|
||||
Description: wrapperspb.String("desc"),
|
||||
@@ -802,7 +802,7 @@ func TestUpdate(t *testing.T) {
|
||||
res: &pbs.UpdateTargetResponse{
|
||||
Item: &pb.Target{
|
||||
Id: tar.GetPublicId(),
|
||||
ScopeId: tar.GetScopeId(),
|
||||
ScopeId: tar.GetProjectId(),
|
||||
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
|
||||
Name: wrapperspb.String("default"),
|
||||
CreatedTime: tar.GetCreateTime().GetTimestamp(),
|
||||
@@ -836,7 +836,7 @@ func TestUpdate(t *testing.T) {
|
||||
res: &pbs.UpdateTargetResponse{
|
||||
Item: &pb.Target{
|
||||
Id: tar.GetPublicId(),
|
||||
ScopeId: tar.GetScopeId(),
|
||||
ScopeId: tar.GetProjectId(),
|
||||
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
|
||||
Name: wrapperspb.String("updated"),
|
||||
Description: wrapperspb.String("default"),
|
||||
@@ -871,7 +871,7 @@ func TestUpdate(t *testing.T) {
|
||||
res: &pbs.UpdateTargetResponse{
|
||||
Item: &pb.Target{
|
||||
Id: tar.GetPublicId(),
|
||||
ScopeId: tar.GetScopeId(),
|
||||
ScopeId: tar.GetProjectId(),
|
||||
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
|
||||
Name: wrapperspb.String("default"),
|
||||
Description: wrapperspb.String("notignored"),
|
||||
@@ -2448,7 +2448,7 @@ func TestAuthorizeSession(t *testing.T) {
|
||||
shsWithPort := static.TestSets(t, conn, hcWithPort.GetPublicId(), 1)[0]
|
||||
_ = static.TestSetMembers(t, conn, shsWithPort.GetPublicId(), []*static.Host{hWithPort})
|
||||
hWithPort.Address = fmt.Sprintf("%s:54321", hWithPort.GetAddress())
|
||||
hWithPort, _, err = staticRepo.UpdateHost(ctx, hcWithPort.GetScopeId(), hWithPort, hWithPort.GetVersion(), []string{"address"})
|
||||
hWithPort, _, err = staticRepo.UpdateHost(ctx, hcWithPort.GetProjectId(), hWithPort, hWithPort.GetVersion(), []string{"address"})
|
||||
require.NoError(t, err)
|
||||
|
||||
phc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId())
|
||||
@@ -3289,7 +3289,7 @@ func TestAuthorizeSession_Errors(t *testing.T) {
|
||||
h.Address = fmt.Sprintf("%s:54321", h.GetAddress())
|
||||
repo, err := staticHostRepoFn()
|
||||
require.NoError(t, err)
|
||||
h, _, err = repo.UpdateHost(ctx, hc.GetScopeId(), h, h.GetVersion(), []string{"address"})
|
||||
h, _, err = repo.UpdateHost(ctx, hc.GetProjectId(), h, h.GetVersion(), []string{"address"})
|
||||
require.NoError(t, err)
|
||||
return apiTar.GetItem().GetVersion()
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user