Remove Prefix Id and Plugin Name fields (#1563)
* Remove Prefix Id and Plugin Name fields. Creating catalogs now require either the plugin id or the name of the plugin resource (but not both). Host Catalogs and Host Sets API resources now have a read only plugin field populated with plugin info. Host Catalogs have a plugin id field as a top level field.
This commit is contained in:
51 files changed
+1314
-1052
No files matched your search
@@ -3,7 +3,6 @@ package host_catalogs
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/boundary/globals"
|
||||
"github.com/hashicorp/boundary/internal/errors"
|
||||
@@ -13,6 +12,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/host/static"
|
||||
"github.com/hashicorp/boundary/internal/host/static/store"
|
||||
"github.com/hashicorp/boundary/internal/perms"
|
||||
hostplugin "github.com/hashicorp/boundary/internal/plugin/host"
|
||||
"github.com/hashicorp/boundary/internal/requests"
|
||||
"github.com/hashicorp/boundary/internal/servers/controller/auth"
|
||||
"github.com/hashicorp/boundary/internal/servers/controller/common"
|
||||
@@ -24,6 +24,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/types/resource"
|
||||
"github.com/hashicorp/boundary/internal/types/scope"
|
||||
pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/hostcatalogs"
|
||||
"github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/plugins"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/types/known/structpb"
|
||||
@@ -120,7 +121,7 @@ func (s Service) ListHostCatalogs(ctx context.Context, req *pbs.ListHostCatalogs
|
||||
return &pbs.ListHostCatalogsResponse{}, nil
|
||||
}
|
||||
|
||||
ul, err := s.listFromRepo(ctx, scopeIds)
|
||||
ul, pluginInfoMap, err := s.listFromRepo(ctx, scopeIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -160,6 +161,12 @@ func (s Service) ListHostCatalogs(ctx context.Context, req *pbs.ListHostCatalogs
|
||||
}
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedCollectionActions(collectionActions))
|
||||
}
|
||||
switch hc := item.(type) {
|
||||
case *plugin.HostCatalog:
|
||||
if plgInfo, ok := pluginInfoMap[hc.GetPluginId()]; ok {
|
||||
outputOpts = append(outputOpts, handlers.WithPlugin(plgInfo))
|
||||
}
|
||||
}
|
||||
|
||||
item, err := toProto(ctx, item, outputOpts...)
|
||||
if err != nil {
|
||||
@@ -184,7 +191,7 @@ func (s Service) GetHostCatalog(ctx context.Context, req *pbs.GetHostCatalogRequ
|
||||
if authResults.Error != nil {
|
||||
return nil, authResults.Error
|
||||
}
|
||||
hc, err := s.getFromRepo(ctx, req.GetId())
|
||||
hc, plg, err := s.getFromRepo(ctx, req.GetId())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -209,6 +216,9 @@ func (s Service) GetHostCatalog(ctx context.Context, req *pbs.GetHostCatalogRequ
|
||||
}
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedCollectionActions(collectionActions))
|
||||
}
|
||||
if plg != nil {
|
||||
outputOpts = append(outputOpts, handlers.WithPlugin(plg))
|
||||
}
|
||||
|
||||
item, err := toProto(ctx, hc, outputOpts...)
|
||||
if err != nil {
|
||||
@@ -229,7 +239,7 @@ func (s Service) CreateHostCatalog(ctx context.Context, req *pbs.CreateHostCatal
|
||||
if authResults.Error != nil {
|
||||
return nil, authResults.Error
|
||||
}
|
||||
hc, err := s.createInRepo(ctx, authResults.Scope.GetId(), req.GetItem())
|
||||
hc, plg, err := s.createInRepo(ctx, authResults.Scope.GetId(), req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -239,7 +249,7 @@ func (s Service) CreateHostCatalog(ctx context.Context, req *pbs.CreateHostCatal
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
outputOpts := make([]handlers.Option, 0, 4)
|
||||
outputOpts = append(outputOpts, handlers.WithOutputFields(&outputFields))
|
||||
if outputFields.Has(globals.ScopeField) {
|
||||
outputOpts = append(outputOpts, handlers.WithScope(authResults.Scope))
|
||||
@@ -254,6 +264,9 @@ func (s Service) CreateHostCatalog(ctx context.Context, req *pbs.CreateHostCatal
|
||||
}
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedCollectionActions(collectionActions))
|
||||
}
|
||||
if plg != nil {
|
||||
outputOpts = append(outputOpts, handlers.WithPlugin(plg))
|
||||
}
|
||||
|
||||
item, err := toProto(ctx, hc, outputOpts...)
|
||||
if err != nil {
|
||||
@@ -327,47 +340,49 @@ func (s Service) DeleteHostCatalog(ctx context.Context, req *pbs.DeleteHostCatal
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s Service) getFromRepo(ctx context.Context, id string) (host.Catalog, error) {
|
||||
func (s Service) getFromRepo(ctx context.Context, id string) (host.Catalog, *plugins.PluginInfo, error) {
|
||||
var plg *plugins.PluginInfo
|
||||
var cat host.Catalog
|
||||
switch host.SubtypeFromId(id) {
|
||||
case static.Subtype:
|
||||
repo, err := s.staticRepoFn()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
hc, err := repo.LookupCatalog(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
if hc == nil {
|
||||
return nil, handlers.NotFoundErrorf("Host Catalog %q doesn't exist.", id)
|
||||
return nil, nil, handlers.NotFoundErrorf("Host Catalog %q doesn't exist.", id)
|
||||
}
|
||||
cat = hc
|
||||
case plugin.Subtype:
|
||||
repo, err := s.pluginHostRepoFn()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
hc, err := repo.LookupCatalog(ctx, id)
|
||||
hc, hcplg, err := repo.LookupCatalog(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
if hc == nil {
|
||||
return nil, handlers.NotFoundErrorf("Host Catalog %q doesn't exist.", id)
|
||||
return nil, nil, handlers.NotFoundErrorf("Host Catalog %q doesn't exist.", id)
|
||||
}
|
||||
cat = hc
|
||||
plg = toPluginInfo(hcplg)
|
||||
}
|
||||
return cat, nil
|
||||
return cat, plg, nil
|
||||
}
|
||||
|
||||
func (s Service) listFromRepo(ctx context.Context, scopeIds []string) ([]host.Catalog, error) {
|
||||
func (s Service) listFromRepo(ctx context.Context, scopeIds []string) ([]host.Catalog, map[string]*plugins.PluginInfo, error) {
|
||||
repo, err := s.staticRepoFn()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
ul, err := repo.ListCatalogs(ctx, scopeIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
var res []host.Catalog
|
||||
for _, c := range ul {
|
||||
@@ -375,16 +390,21 @@ func (s Service) listFromRepo(ctx context.Context, scopeIds []string) ([]host.Ca
|
||||
}
|
||||
pluginRepo, err := s.pluginHostRepoFn()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
pl, err := pluginRepo.ListCatalogs(ctx, scopeIds)
|
||||
pl, plgs, err := pluginRepo.ListCatalogs(ctx, scopeIds)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
for _, c := range pl {
|
||||
res = append(res, c)
|
||||
}
|
||||
return res, nil
|
||||
pluginsMap := make(map[string]*plugins.PluginInfo, len(plgs))
|
||||
for _, plg := range plgs {
|
||||
pluginsMap[plg.GetPublicId()] = toPluginInfo(plg)
|
||||
}
|
||||
|
||||
return res, pluginsMap, nil
|
||||
}
|
||||
|
||||
func (s Service) createStaticInRepo(ctx context.Context, projId string, item *pb.HostCatalog) (*static.HostCatalog, error) {
|
||||
@@ -407,42 +427,48 @@ func (s Service) createStaticInRepo(ctx context.Context, projId string, item *pb
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (s Service) createPluginInRepo(ctx context.Context, projId string, item *pb.HostCatalog) (*plugin.HostCatalog, error) {
|
||||
func (s Service) createPluginInRepo(ctx context.Context, projId string, req *pbs.CreateHostCatalogRequest) (*plugin.HostCatalog, *plugins.PluginInfo, error) {
|
||||
const op = "host_catalogs.(Service).createInRepo"
|
||||
plgRepo, err := s.pluginRepoFn()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
item := req.GetItem()
|
||||
pluginId := item.GetPluginId()
|
||||
if pluginId == "" {
|
||||
plgRepo, err := s.pluginRepoFn()
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
plg, err := plgRepo.LookupPluginByName(ctx, req.GetPluginName())
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
pluginId = plg.GetPublicId()
|
||||
}
|
||||
plg, err := plgRepo.LookupPluginByPluginName(ctx, item.GetType())
|
||||
h, err := toStoragePluginCatalog(ctx, projId, pluginId, item)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
h, err := toStoragePluginCatalog(ctx, projId, plg.GetPublicId(), item)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to build catalog for creation"))
|
||||
return nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to build catalog for creation"))
|
||||
}
|
||||
repo, err := s.pluginHostRepoFn()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
return nil, nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
out, err := repo.CreateCatalog(ctx, h)
|
||||
out, plg, err := repo.CreateCatalog(ctx, h)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to create host catalog"))
|
||||
return nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to create host catalog"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create host catalog but no error returned from repository.")
|
||||
return nil, nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create host catalog but no error returned from repository.")
|
||||
}
|
||||
return out, nil
|
||||
return out, toPluginInfo(plg), nil
|
||||
}
|
||||
|
||||
func (s Service) createInRepo(ctx context.Context, projId string, item *pb.HostCatalog) (hc host.Catalog, err error) {
|
||||
switch host.SubtypeFromType(item.GetType()) {
|
||||
func (s Service) createInRepo(ctx context.Context, projId string, req *pbs.CreateHostCatalogRequest) (hc host.Catalog, info *plugins.PluginInfo, err error) {
|
||||
var plg *plugins.PluginInfo
|
||||
switch host.SubtypeFromType(req.GetItem().GetType()) {
|
||||
case static.Subtype:
|
||||
hc, err = s.createStaticInRepo(ctx, projId, item)
|
||||
hc, err = s.createStaticInRepo(ctx, projId, req.GetItem())
|
||||
default:
|
||||
hc, err = s.createPluginInRepo(ctx, projId, item)
|
||||
hc, plg, err = s.createPluginInRepo(ctx, projId, req)
|
||||
}
|
||||
return hc, err
|
||||
return hc, plg, err
|
||||
}
|
||||
|
||||
func (s Service) updateInRepo(ctx context.Context, projId, id string, mask []string, item *pb.HostCatalog) (*static.HostCatalog, error) {
|
||||
@@ -531,7 +557,7 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) auth.
|
||||
res.Error = err
|
||||
return res
|
||||
}
|
||||
cat, err := repo.LookupCatalog(ctx, id)
|
||||
cat, _, err := repo.LookupCatalog(ctx, id)
|
||||
if err != nil {
|
||||
res.Error = err
|
||||
return res
|
||||
@@ -548,6 +574,17 @@ func (s Service) authResult(ctx context.Context, id string, a action.Type) auth.
|
||||
return auth.Verify(ctx, opts...)
|
||||
}
|
||||
|
||||
func toPluginInfo(plg *hostplugin.Plugin) *plugins.PluginInfo {
|
||||
if plg == nil {
|
||||
return nil
|
||||
}
|
||||
return &plugins.PluginInfo{
|
||||
Id: plg.GetPublicId(),
|
||||
Name: plg.GetName(),
|
||||
Description: plg.GetDescription(),
|
||||
}
|
||||
}
|
||||
|
||||
func toProto(ctx context.Context, in host.Catalog, opt ...handlers.Option) (*pb.HostCatalog, error) {
|
||||
const op = "host_catalog_service.toProto"
|
||||
opts := handlers.GetOpts(opt...)
|
||||
@@ -563,17 +600,18 @@ func toProto(ctx context.Context, in host.Catalog, opt ...handlers.Option) (*pb.
|
||||
if outputFields.Has(globals.ScopeIdField) {
|
||||
out.ScopeId = in.GetScopeId()
|
||||
}
|
||||
if outputFields.Has(globals.PluginIdField) {
|
||||
switch hc := in.(type) {
|
||||
case *plugin.HostCatalog:
|
||||
out.PluginId = hc.GetPluginId()
|
||||
}
|
||||
}
|
||||
if outputFields.Has(globals.TypeField) {
|
||||
switch host.SubtypeFromId(in.GetPublicId()) {
|
||||
case static.Subtype:
|
||||
switch in.(type) {
|
||||
case *static.HostCatalog:
|
||||
out.Type = static.Subtype.String()
|
||||
default:
|
||||
// TODO: When id prefix and plugin name can diverge, update this logic.
|
||||
out.Type = "plugin"
|
||||
idParts := strings.Split(in.GetPublicId(), "_")
|
||||
if len(idParts) > 2 {
|
||||
out.Type = idParts[1]
|
||||
}
|
||||
case *plugin.HostCatalog:
|
||||
out.Type = plugin.Subtype.String()
|
||||
}
|
||||
}
|
||||
if outputFields.Has(globals.DescriptionField) && in.GetDescription() != "" {
|
||||
@@ -594,6 +632,9 @@ func toProto(ctx context.Context, in host.Catalog, opt ...handlers.Option) (*pb.
|
||||
if outputFields.Has(globals.ScopeField) {
|
||||
out.Scope = opts.WithScope
|
||||
}
|
||||
if outputFields.Has(globals.PluginField) {
|
||||
out.Plugin = opts.WithPlugin
|
||||
}
|
||||
if outputFields.Has(globals.AuthorizedActionsField) {
|
||||
out.AuthorizedActions = opts.WithAuthorizedActions
|
||||
}
|
||||
@@ -662,13 +703,7 @@ func toStoragePluginCatalog(ctx context.Context, scopeId, plgId string, item *pb
|
||||
// * The type asserted by the ID and/or field is known
|
||||
// * If relevant, the type derived from the id prefix matches what is claimed by the type field
|
||||
func validateGetRequest(req *pbs.GetHostCatalogRequest) error {
|
||||
pluginPrefix := plugin.HostCatalogPrefix
|
||||
idParts := strings.Split(req.GetId(), "_")
|
||||
if len(idParts) > 2 && idParts[0] == plugin.HostCatalogPrefix {
|
||||
pluginPrefix = strings.Join(idParts[:2], "_")
|
||||
}
|
||||
|
||||
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, static.HostCatalogPrefix, pluginPrefix)
|
||||
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, static.HostCatalogPrefix, plugin.HostCatalogPrefix)
|
||||
}
|
||||
|
||||
func validateCreateRequest(req *pbs.CreateHostCatalogRequest) error {
|
||||
@@ -677,8 +712,20 @@ func validateCreateRequest(req *pbs.CreateHostCatalogRequest) error {
|
||||
if !handlers.ValidId(handlers.Id(req.GetItem().GetScopeId()), scope.Project.Prefix()) {
|
||||
badFields[globals.ScopeIdField] = "This field must be a valid project scope id."
|
||||
}
|
||||
if req.GetItem().GetType() == "" {
|
||||
badFields[globals.TypeField] = "This field is required."
|
||||
switch host.SubtypeFromType(req.GetItem().GetType()) {
|
||||
case static.Subtype:
|
||||
case plugin.Subtype:
|
||||
if req.GetItem().GetPlugin() != nil {
|
||||
badFields[globals.PluginField] = fmt.Sprintf("This is a read only field.")
|
||||
}
|
||||
if req.GetItem().GetPluginId() == "" && req.GetPluginName() == "" {
|
||||
badFields[globals.PluginIdField] = fmt.Sprintf("This is a required field.")
|
||||
}
|
||||
if req.GetItem().GetPluginId() != "" && req.GetPluginName() != "" {
|
||||
badFields[globals.PluginIdField] = fmt.Sprintf("Can't set the plugin name field along with this field.")
|
||||
}
|
||||
default:
|
||||
badFields[globals.TypeField] = fmt.Sprintf("This is a required field and must be either %q or %q.", static.Subtype.String(), plugin.Subtype.String())
|
||||
}
|
||||
return badFields
|
||||
})
|
||||
@@ -690,7 +737,7 @@ func validateUpdateRequest(req *pbs.UpdateHostCatalogRequest) error {
|
||||
switch host.SubtypeFromId(req.GetId()) {
|
||||
case static.Subtype:
|
||||
if req.GetItem().GetType() != "" && host.SubtypeFromType(req.GetItem().GetType()) != static.Subtype {
|
||||
badFields["type"] = "Cannot modify resource type."
|
||||
badFields[globals.TypeField] = "Cannot modify resource type."
|
||||
}
|
||||
}
|
||||
return badFields
|
||||
@@ -698,23 +745,17 @@ func validateUpdateRequest(req *pbs.UpdateHostCatalogRequest) error {
|
||||
}
|
||||
|
||||
func validateDeleteRequest(req *pbs.DeleteHostCatalogRequest) error {
|
||||
pluginPrefix := plugin.HostCatalogPrefix
|
||||
idParts := strings.Split(req.GetId(), "_")
|
||||
if len(idParts) > 2 && idParts[0] == plugin.HostCatalogPrefix {
|
||||
pluginPrefix = strings.Join(idParts[:2], "_")
|
||||
}
|
||||
|
||||
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, static.HostCatalogPrefix, pluginPrefix)
|
||||
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, static.HostCatalogPrefix, plugin.HostCatalogPrefix)
|
||||
}
|
||||
|
||||
func validateListRequest(req *pbs.ListHostCatalogsRequest) error {
|
||||
badFields := map[string]string{}
|
||||
if !handlers.ValidId(handlers.Id(req.GetScopeId()), scope.Project.Prefix()) &&
|
||||
!req.GetRecursive() {
|
||||
badFields["scope_id"] = "This field must be a valid project scope ID or the list operation must be recursive."
|
||||
badFields[globals.ScopeIdField] = "This field must be a valid project scope ID or the list operation must be recursive."
|
||||
}
|
||||
if _, err := handlers.NewFilter(req.GetFilter()); err != nil {
|
||||
badFields["filter"] = fmt.Sprintf("This field could not be parsed. %v", err)
|
||||
badFields[globals.FilterField] = fmt.Sprintf("This field could not be parsed. %v", err)
|
||||
}
|
||||
if len(badFields) > 0 {
|
||||
return handlers.InvalidArgumentErrorf("Improperly formatted identifier.", badFields)
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/servers/controller/handlers/host_catalogs"
|
||||
"github.com/hashicorp/boundary/internal/types/scope"
|
||||
pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/hostcatalogs"
|
||||
"github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/plugins"
|
||||
scopepb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/scopes"
|
||||
plgpb "github.com/hashicorp/boundary/sdk/pbs/plugin"
|
||||
"google.golang.org/genproto/protobuf/field_mask"
|
||||
@@ -161,7 +162,7 @@ func TestGet_Plugin(t *testing.T) {
|
||||
return iam.TestRepo(t, conn, wrapper), nil
|
||||
}
|
||||
name := "test"
|
||||
plg := host.TestPlugin(t, conn, name, name)
|
||||
plg := host.TestPlugin(t, conn, name)
|
||||
hc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId())
|
||||
|
||||
toMerge := &pbs.GetHostCatalogRequest{
|
||||
@@ -169,12 +170,22 @@ func TestGet_Plugin(t *testing.T) {
|
||||
}
|
||||
|
||||
pHostCatalog := &pb.HostCatalog{
|
||||
Id: hc.GetPublicId(),
|
||||
ScopeId: hc.GetScopeId(),
|
||||
Scope: &scopepb.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: proj.GetParentId()},
|
||||
Id: hc.GetPublicId(),
|
||||
ScopeId: hc.GetScopeId(),
|
||||
Scope: &scopepb.ScopeInfo{
|
||||
Id: proj.GetPublicId(),
|
||||
Type: scope.Project.String(),
|
||||
ParentScopeId: proj.GetParentId(),
|
||||
},
|
||||
PluginId: plg.GetPublicId(),
|
||||
Plugin: &plugins.PluginInfo{
|
||||
Id: plg.GetPublicId(),
|
||||
Name: plg.GetName(),
|
||||
Description: plg.GetDescription(),
|
||||
},
|
||||
CreatedTime: hc.CreateTime.GetTimestamp(),
|
||||
UpdatedTime: hc.UpdateTime.GetTimestamp(),
|
||||
Type: name,
|
||||
Type: plugin.Subtype.String(),
|
||||
AuthorizedActions: testAuthorizedActions,
|
||||
AuthorizedCollectionActions: authorizedCollectionActions,
|
||||
}
|
||||
@@ -272,17 +283,23 @@ func TestList(t *testing.T) {
|
||||
|
||||
var testPluginCatalogs []*pb.HostCatalog
|
||||
name := "test"
|
||||
plg := host.TestPlugin(t, conn, name, name)
|
||||
plg := host.TestPlugin(t, conn, name)
|
||||
for i := 0; i < 3; i++ {
|
||||
hc := plugin.TestCatalog(t, conn, pWithCatalogs.GetPublicId(), plg.GetPublicId())
|
||||
cat := &pb.HostCatalog{
|
||||
Id: hc.GetPublicId(),
|
||||
ScopeId: hc.GetScopeId(),
|
||||
CreatedTime: hc.GetCreateTime().GetTimestamp(),
|
||||
UpdatedTime: hc.GetUpdateTime().GetTimestamp(),
|
||||
Scope: &scopepb.ScopeInfo{Id: pWithCatalogs.GetPublicId(), Type: scope.Project.String(), ParentScopeId: oWithCatalogs.GetPublicId()},
|
||||
Id: hc.GetPublicId(),
|
||||
ScopeId: hc.GetScopeId(),
|
||||
CreatedTime: hc.GetCreateTime().GetTimestamp(),
|
||||
UpdatedTime: hc.GetUpdateTime().GetTimestamp(),
|
||||
Scope: &scopepb.ScopeInfo{Id: pWithCatalogs.GetPublicId(), Type: scope.Project.String(), ParentScopeId: oWithCatalogs.GetPublicId()},
|
||||
PluginId: plg.GetPublicId(),
|
||||
Plugin: &plugins.PluginInfo{
|
||||
Id: plg.GetPublicId(),
|
||||
Name: plg.GetName(),
|
||||
Description: plg.GetDescription(),
|
||||
},
|
||||
Version: 1,
|
||||
Type: name,
|
||||
Type: plugin.Subtype.String(),
|
||||
AuthorizedActions: testAuthorizedActions,
|
||||
AuthorizedCollectionActions: authorizedCollectionActions,
|
||||
}
|
||||
@@ -306,17 +323,23 @@ func TestList(t *testing.T) {
|
||||
}
|
||||
|
||||
name = "different"
|
||||
plg = host.TestPlugin(t, conn, name, name)
|
||||
diffPlg := host.TestPlugin(t, conn, name)
|
||||
for i := 0; i < 3; i++ {
|
||||
hc := plugin.TestCatalog(t, conn, pWithOtherCatalogs.GetPublicId(), plg.GetPublicId())
|
||||
hc := plugin.TestCatalog(t, conn, pWithOtherCatalogs.GetPublicId(), diffPlg.GetPublicId())
|
||||
wantOtherCatalogs = append(wantOtherCatalogs, &pb.HostCatalog{
|
||||
Id: hc.GetPublicId(),
|
||||
ScopeId: hc.GetScopeId(),
|
||||
CreatedTime: hc.GetCreateTime().GetTimestamp(),
|
||||
UpdatedTime: hc.GetUpdateTime().GetTimestamp(),
|
||||
Scope: &scopepb.ScopeInfo{Id: pWithOtherCatalogs.GetPublicId(), Type: scope.Project.String(), ParentScopeId: oWithOtherCatalogs.GetPublicId()},
|
||||
Id: hc.GetPublicId(),
|
||||
ScopeId: hc.GetScopeId(),
|
||||
CreatedTime: hc.GetCreateTime().GetTimestamp(),
|
||||
UpdatedTime: hc.GetUpdateTime().GetTimestamp(),
|
||||
Scope: &scopepb.ScopeInfo{Id: pWithOtherCatalogs.GetPublicId(), Type: scope.Project.String(), ParentScopeId: oWithOtherCatalogs.GetPublicId()},
|
||||
PluginId: diffPlg.GetPublicId(),
|
||||
Plugin: &plugins.PluginInfo{
|
||||
Id: diffPlg.GetPublicId(),
|
||||
Name: diffPlg.GetName(),
|
||||
Description: diffPlg.GetDescription(),
|
||||
},
|
||||
Version: 1,
|
||||
Type: name,
|
||||
Type: plugin.Subtype.String(),
|
||||
AuthorizedActions: testAuthorizedActions,
|
||||
AuthorizedCollectionActions: authorizedCollectionActions,
|
||||
})
|
||||
@@ -369,10 +392,10 @@ func TestList(t *testing.T) {
|
||||
res: &pbs.ListHostCatalogsResponse{Items: wantSomeCatalogs},
|
||||
},
|
||||
{
|
||||
name: "Filter To Catalog Test Type",
|
||||
name: "Filter To Catalog Using Test Plugin",
|
||||
req: &pbs.ListHostCatalogsRequest{
|
||||
ScopeId: scope.Global.String(), Recursive: true,
|
||||
Filter: `"/item/type"=="test"`,
|
||||
Filter: `"/item/plugin/name"=="test"`,
|
||||
},
|
||||
res: &pbs.ListHostCatalogsResponse{Items: testPluginCatalogs},
|
||||
},
|
||||
@@ -684,7 +707,7 @@ func TestCreate_Plugin(t *testing.T) {
|
||||
wrapper := db.TestWrapper(t)
|
||||
kms := kms.TestKms(t, conn, wrapper)
|
||||
iamRepo := iam.TestRepo(t, conn, wrapper)
|
||||
_, proj := iam.TestScopes(t, iamRepo)
|
||||
org, proj := iam.TestScopes(t, iamRepo)
|
||||
rw := db.New(conn)
|
||||
repo := func() (*static.Repository, error) {
|
||||
return static.NewRepository(rw, rw, kms)
|
||||
@@ -697,7 +720,7 @@ func TestCreate_Plugin(t *testing.T) {
|
||||
}
|
||||
|
||||
name := "test"
|
||||
plg := host.TestPlugin(t, conn, name, name)
|
||||
plg := host.TestPlugin(t, conn, name)
|
||||
pluginHostRepo := func() (*plugin.Repository, error) {
|
||||
return plugin.NewRepository(rw, rw, kms, map[string]plgpb.HostPluginServiceServer{
|
||||
plg.GetPublicId(): &plugin.TestPluginServer{
|
||||
@@ -723,16 +746,23 @@ func TestCreate_Plugin(t *testing.T) {
|
||||
ScopeId: proj.GetPublicId(),
|
||||
Name: &wrappers.StringValue{Value: "name"},
|
||||
Description: &wrappers.StringValue{Value: "desc"},
|
||||
Type: name,
|
||||
Type: plugin.Subtype.String(),
|
||||
PluginId: plg.GetPublicId(),
|
||||
}},
|
||||
res: &pbs.CreateHostCatalogResponse{
|
||||
Uri: fmt.Sprintf("host-catalogs/%s_%s_", plugin.HostCatalogPrefix, name),
|
||||
Uri: fmt.Sprintf("host-catalogs/%s_", plugin.HostCatalogPrefix),
|
||||
Item: &pb.HostCatalog{
|
||||
ScopeId: proj.GetPublicId(),
|
||||
Scope: &scopepb.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: proj.GetParentId()},
|
||||
ScopeId: proj.GetPublicId(),
|
||||
Scope: &scopepb.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: proj.GetParentId()},
|
||||
PluginId: plg.GetPublicId(),
|
||||
Plugin: &plugins.PluginInfo{
|
||||
Id: plg.GetPublicId(),
|
||||
Name: plg.GetName(),
|
||||
Description: plg.GetDescription(),
|
||||
},
|
||||
Name: &wrappers.StringValue{Value: "name"},
|
||||
Description: &wrappers.StringValue{Value: "desc"},
|
||||
Type: name,
|
||||
Type: plugin.Subtype.String(),
|
||||
AuthorizedActions: testAuthorizedActions,
|
||||
AuthorizedCollectionActions: authorizedCollectionActions,
|
||||
},
|
||||
@@ -741,44 +771,45 @@ func TestCreate_Plugin(t *testing.T) {
|
||||
{
|
||||
name: "Cant create in org",
|
||||
req: &pbs.CreateHostCatalogRequest{Item: &pb.HostCatalog{
|
||||
ScopeId: proj.GetParentId(),
|
||||
Name: &wrappers.StringValue{Value: "name"},
|
||||
Description: &wrappers.StringValue{Value: "desc"},
|
||||
Type: name,
|
||||
ScopeId: org.GetParentId(),
|
||||
Type: plugin.Subtype.String(),
|
||||
PluginId: plg.GetPublicId(),
|
||||
}},
|
||||
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
|
||||
},
|
||||
{
|
||||
name: "Cant create in global",
|
||||
req: &pbs.CreateHostCatalogRequest{Item: &pb.HostCatalog{
|
||||
ScopeId: scope.Global.String(),
|
||||
Name: &wrappers.StringValue{Value: "name"},
|
||||
Description: &wrappers.StringValue{Value: "desc"},
|
||||
Type: name,
|
||||
ScopeId: scope.Global.String(),
|
||||
Type: plugin.Subtype.String(),
|
||||
PluginId: plg.GetPublicId(),
|
||||
}},
|
||||
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
|
||||
},
|
||||
{
|
||||
name: "Create with unknown type",
|
||||
req: &pbs.CreateHostCatalogRequest{Item: &pb.HostCatalog{
|
||||
Name: &wrappers.StringValue{Value: "name"},
|
||||
Description: &wrappers.StringValue{Value: "desc"},
|
||||
Type: "thisismadeup",
|
||||
ScopeId: proj.GetPublicId(),
|
||||
PluginId: plg.GetPublicId(),
|
||||
Type: "thisismadeup",
|
||||
}},
|
||||
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
|
||||
},
|
||||
{
|
||||
name: "Create with no type",
|
||||
req: &pbs.CreateHostCatalogRequest{Item: &pb.HostCatalog{
|
||||
Name: &wrappers.StringValue{Value: "name"},
|
||||
Description: &wrappers.StringValue{Value: "desc"},
|
||||
ScopeId: proj.GetPublicId(),
|
||||
PluginId: plg.GetPublicId(),
|
||||
}},
|
||||
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
|
||||
},
|
||||
{
|
||||
name: "Can't specify Id",
|
||||
req: &pbs.CreateHostCatalogRequest{Item: &pb.HostCatalog{
|
||||
Id: "not allowed to be set",
|
||||
Id: "not allowed to be set",
|
||||
ScopeId: proj.GetPublicId(),
|
||||
Type: plugin.Subtype.String(),
|
||||
PluginId: plg.GetPublicId(),
|
||||
}},
|
||||
res: nil,
|
||||
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
|
||||
@@ -787,6 +818,9 @@ func TestCreate_Plugin(t *testing.T) {
|
||||
name: "Can't specify Created Time",
|
||||
req: &pbs.CreateHostCatalogRequest{Item: &pb.HostCatalog{
|
||||
CreatedTime: timestamppb.Now(),
|
||||
ScopeId: proj.GetPublicId(),
|
||||
Type: plugin.Subtype.String(),
|
||||
PluginId: plg.GetPublicId(),
|
||||
}},
|
||||
res: nil,
|
||||
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
|
||||
@@ -795,6 +829,9 @@ func TestCreate_Plugin(t *testing.T) {
|
||||
name: "Can't specify Update Time",
|
||||
req: &pbs.CreateHostCatalogRequest{Item: &pb.HostCatalog{
|
||||
UpdatedTime: timestamppb.Now(),
|
||||
ScopeId: proj.GetPublicId(),
|
||||
Type: plugin.Subtype.String(),
|
||||
PluginId: plg.GetPublicId(),
|
||||
}},
|
||||
res: nil,
|
||||
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
|
||||
@@ -818,7 +855,7 @@ func TestCreate_Plugin(t *testing.T) {
|
||||
require.NoError(gErr)
|
||||
if got != nil {
|
||||
assert.Contains(got.GetUri(), tc.res.GetUri())
|
||||
assert.True(strings.HasPrefix(got.GetItem().GetId(), fmt.Sprintf("%s_%s_", plugin.HostCatalogPrefix, name)))
|
||||
assert.True(strings.HasPrefix(got.GetItem().GetId(), fmt.Sprintf("%s_", plugin.HostCatalogPrefix)))
|
||||
gotCreateTime := got.GetItem().GetCreatedTime().AsTime()
|
||||
require.NoError(err, "Error converting proto to timestamp.")
|
||||
gotUpdateTime := got.GetItem().GetUpdatedTime().AsTime()
|
||||
|
||||
@@ -3,7 +3,6 @@ package host_sets
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/hashicorp/boundary/globals"
|
||||
"github.com/hashicorp/boundary/internal/errors"
|
||||
@@ -14,6 +13,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/host/static/store"
|
||||
"github.com/hashicorp/boundary/internal/libs/endpoint"
|
||||
"github.com/hashicorp/boundary/internal/perms"
|
||||
hostplugin "github.com/hashicorp/boundary/internal/plugin/host"
|
||||
"github.com/hashicorp/boundary/internal/requests"
|
||||
"github.com/hashicorp/boundary/internal/servers/controller/auth"
|
||||
"github.com/hashicorp/boundary/internal/servers/controller/common"
|
||||
@@ -21,6 +21,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/types/action"
|
||||
"github.com/hashicorp/boundary/internal/types/resource"
|
||||
pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/hostsets"
|
||||
"github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/plugins"
|
||||
"github.com/hashicorp/go-secure-stdlib/strutil"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/protobuf/proto"
|
||||
@@ -92,7 +93,7 @@ func (s Service) ListHostSetsWithOptions(ctx context.Context, req *pbs.ListHostS
|
||||
if authResults.Error != nil {
|
||||
return nil, authResults.Error
|
||||
}
|
||||
hl, err := s.listFromRepo(ctx, req.GetHostCatalogId(), opt...)
|
||||
hl, plg, err := s.listFromRepo(ctx, req.GetHostCatalogId(), opt...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -127,6 +128,9 @@ func (s Service) ListHostSetsWithOptions(ctx context.Context, req *pbs.ListHostS
|
||||
if outputFields.Has(globals.AuthorizedActionsField) {
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authorizedActions))
|
||||
}
|
||||
if plg != nil {
|
||||
outputOpts = append(outputOpts, handlers.WithPlugin(plg))
|
||||
}
|
||||
|
||||
item, err := toProto(ctx, item, nil, outputOpts...)
|
||||
if err != nil {
|
||||
@@ -151,7 +155,7 @@ func (s Service) GetHostSet(ctx context.Context, req *pbs.GetHostSetRequest) (*p
|
||||
if authResults.Error != nil {
|
||||
return nil, authResults.Error
|
||||
}
|
||||
hs, hosts, err := s.getFromRepo(ctx, req.GetId())
|
||||
hs, hosts, plg, err := s.getFromRepo(ctx, req.GetId())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -161,7 +165,7 @@ func (s Service) GetHostSet(ctx context.Context, req *pbs.GetHostSetRequest) (*p
|
||||
return nil, errors.New(ctx, errors.Internal, op, "no request context found")
|
||||
}
|
||||
|
||||
outputOpts := make([]handlers.Option, 0, 3)
|
||||
outputOpts := make([]handlers.Option, 0, 4)
|
||||
outputOpts = append(outputOpts, handlers.WithOutputFields(&outputFields))
|
||||
if outputFields.Has(globals.ScopeField) {
|
||||
outputOpts = append(outputOpts, handlers.WithScope(authResults.Scope))
|
||||
@@ -169,6 +173,9 @@ func (s Service) GetHostSet(ctx context.Context, req *pbs.GetHostSetRequest) (*p
|
||||
if outputFields.Has(globals.AuthorizedActionsField) {
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, hs.GetPublicId(), IdActions).Strings()))
|
||||
}
|
||||
if plg != nil {
|
||||
outputOpts = append(outputOpts, handlers.WithPlugin(plg))
|
||||
}
|
||||
|
||||
item, err := toProto(ctx, hs, hosts, outputOpts...)
|
||||
if err != nil {
|
||||
@@ -189,7 +196,7 @@ func (s Service) CreateHostSet(ctx context.Context, req *pbs.CreateHostSetReques
|
||||
if authResults.Error != nil {
|
||||
return nil, authResults.Error
|
||||
}
|
||||
hs, err := s.createInRepo(ctx, authResults.Scope.GetId(), req.GetItem().GetHostCatalogId(), req.GetItem())
|
||||
hs, plg, err := s.createInRepo(ctx, authResults.Scope.GetId(), req.GetItem().GetHostCatalogId(), req.GetItem())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -207,6 +214,9 @@ func (s Service) CreateHostSet(ctx context.Context, req *pbs.CreateHostSetReques
|
||||
if outputFields.Has(globals.AuthorizedActionsField) {
|
||||
outputOpts = append(outputOpts, handlers.WithAuthorizedActions(authResults.FetchActionSetForId(ctx, hs.GetPublicId(), IdActions).Strings()))
|
||||
}
|
||||
if plg != nil {
|
||||
outputOpts = append(outputOpts, handlers.WithPlugin(plg))
|
||||
}
|
||||
|
||||
item, err := toProto(ctx, hs, nil, outputOpts...)
|
||||
if err != nil {
|
||||
@@ -386,21 +396,22 @@ func (s Service) RemoveHostSetHosts(ctx context.Context, req *pbs.RemoveHostSetH
|
||||
return &pbs.RemoveHostSetHostsResponse{Item: item}, nil
|
||||
}
|
||||
|
||||
func (s Service) getFromRepo(ctx context.Context, id string) (host.Set, []host.Host, error) {
|
||||
func (s Service) getFromRepo(ctx context.Context, id string) (host.Set, []host.Host, *plugins.PluginInfo, error) {
|
||||
var hs host.Set
|
||||
var hl []host.Host
|
||||
var plg *plugins.PluginInfo
|
||||
switch host.SubtypeFromId(id) {
|
||||
case static.Subtype:
|
||||
repo, err := s.staticRepoFn()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
hset, hosts, err := repo.LookupSet(ctx, id)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
if hset == nil {
|
||||
return nil, nil, handlers.NotFoundErrorf("Host Set %q doesn't exist.", id)
|
||||
return nil, nil, nil, handlers.NotFoundErrorf("Host Set %q doesn't exist.", id)
|
||||
}
|
||||
for _, h := range hosts {
|
||||
hl = append(hl, h)
|
||||
@@ -409,65 +420,68 @@ func (s Service) getFromRepo(ctx context.Context, id string) (host.Set, []host.H
|
||||
case plugin.Subtype:
|
||||
repo, err := s.pluginRepoFn()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
hset, err := repo.LookupSet(ctx, id)
|
||||
hset, hsplg, err := repo.LookupSet(ctx, id)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
if hset == nil {
|
||||
return nil, nil, handlers.NotFoundErrorf("Host Set %q doesn't exist.", id)
|
||||
return nil, nil, nil, handlers.NotFoundErrorf("Host Set %q doesn't exist.", id)
|
||||
}
|
||||
hs = hset
|
||||
plg = toPluginInfo(hsplg)
|
||||
}
|
||||
return hs, hl, nil
|
||||
return hs, hl, plg, nil
|
||||
}
|
||||
|
||||
func (s Service) createInRepo(ctx context.Context, scopeId, catalogId string, item *pb.HostSet) (host.Set, error) {
|
||||
func (s Service) createInRepo(ctx context.Context, scopeId, catalogId string, item *pb.HostSet) (host.Set, *plugins.PluginInfo, error) {
|
||||
const op = "host_sets.(Service).createInRepo"
|
||||
if item == nil {
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing item")
|
||||
return nil, nil, errors.New(ctx, errors.InvalidParameter, op, "missing item")
|
||||
}
|
||||
var hSet host.Set
|
||||
var plg *plugins.PluginInfo
|
||||
switch host.SubtypeFromId(catalogId) {
|
||||
case static.Subtype:
|
||||
h, err := toStorageStaticSet(ctx, catalogId, item)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
repo, err := s.staticRepoFn()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
out, err := repo.CreateSet(ctx, scopeId, h)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to create host set"))
|
||||
return nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to create host set"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create host set but no error returned from repository.")
|
||||
return nil, nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create host set but no error returned from repository.")
|
||||
}
|
||||
hSet = out
|
||||
case plugin.Subtype:
|
||||
h, err := toStoragePluginSet(ctx, catalogId, item)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
repo, err := s.pluginRepoFn()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
out, err := repo.CreateSet(ctx, scopeId, h)
|
||||
out, hsplg, err := repo.CreateSet(ctx, scopeId, h)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to create host set"))
|
||||
return nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to create host set"))
|
||||
}
|
||||
if out == nil {
|
||||
return nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create host set but no error returned from repository.")
|
||||
return nil, nil, handlers.ApiErrorWithCodeAndMessage(codes.Internal, "Unable to create host set but no error returned from repository.")
|
||||
}
|
||||
hSet = out
|
||||
plg = toPluginInfo(hsplg)
|
||||
default:
|
||||
return nil, errors.New(ctx, errors.InvalidParameter, op, "unrecognized catalog type")
|
||||
return nil, nil, errors.New(ctx, errors.InvalidParameter, op, "unrecognized catalog type")
|
||||
}
|
||||
return hSet, nil
|
||||
return hSet, plg, nil
|
||||
}
|
||||
|
||||
func (s Service) updateInRepo(ctx context.Context, scopeId, catalogId string, req *pbs.UpdateHostSetRequest) (host.Set, []host.Host, error) {
|
||||
@@ -513,18 +527,19 @@ func (s Service) deleteFromRepo(ctx context.Context, scopeId, id string) (bool,
|
||||
return rows > 0, nil
|
||||
}
|
||||
|
||||
func (s Service) listFromRepo(ctx context.Context, catalogId string, opt ...host.Option) ([]host.Set, error) {
|
||||
func (s Service) listFromRepo(ctx context.Context, catalogId string, opt ...host.Option) ([]host.Set, *plugins.PluginInfo, error) {
|
||||
const op = "host_sets.(Service).listFromRepo"
|
||||
var plg *plugins.PluginInfo
|
||||
var sets []host.Set
|
||||
switch host.SubtypeFromId(catalogId) {
|
||||
case static.Subtype:
|
||||
repo, err := s.staticRepoFn()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
sl, err := repo.ListSets(ctx, catalogId)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
return nil, nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
for _, a := range sl {
|
||||
sets = append(sets, a)
|
||||
@@ -532,17 +547,18 @@ func (s Service) listFromRepo(ctx context.Context, catalogId string, opt ...host
|
||||
case plugin.Subtype:
|
||||
repo, err := s.pluginRepoFn()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
sl, err := repo.ListSets(ctx, catalogId, opt...)
|
||||
sl, hsplg, err := repo.ListSets(ctx, catalogId, opt...)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(ctx, err, op)
|
||||
return nil, nil, errors.Wrap(ctx, err, op)
|
||||
}
|
||||
for _, a := range sl {
|
||||
sets = append(sets, a)
|
||||
}
|
||||
plg = toPluginInfo(hsplg)
|
||||
}
|
||||
return sets, nil
|
||||
return sets, plg, nil
|
||||
}
|
||||
|
||||
func (s Service) addInRepo(ctx context.Context, scopeId, setId string, hostIds []string, version uint32) (*static.HostSet, []host.Host, error) {
|
||||
@@ -652,7 +668,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
|
||||
}
|
||||
set = ss
|
||||
case plugin.Subtype:
|
||||
ps, err := pluginRepo.LookupSet(ctx, id)
|
||||
ps, _, err := pluginRepo.LookupSet(ctx, id)
|
||||
if err != nil {
|
||||
res.Error = err
|
||||
return nil, res
|
||||
@@ -681,7 +697,7 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
|
||||
}
|
||||
cat = cs
|
||||
case plugin.Subtype:
|
||||
pc, err := pluginRepo.LookupCatalog(ctx, parentId)
|
||||
pc, _, err := pluginRepo.LookupCatalog(ctx, parentId)
|
||||
if err != nil {
|
||||
res.Error = err
|
||||
return nil, res
|
||||
@@ -696,6 +712,17 @@ func (s Service) parentAndAuthResult(ctx context.Context, id string, a action.Ty
|
||||
return cat, auth.Verify(ctx, opts...)
|
||||
}
|
||||
|
||||
func toPluginInfo(plg *hostplugin.Plugin) *plugins.PluginInfo {
|
||||
if plg == nil {
|
||||
return nil
|
||||
}
|
||||
return &plugins.PluginInfo{
|
||||
Id: plg.GetPublicId(),
|
||||
Name: plg.GetName(),
|
||||
Description: plg.GetDescription(),
|
||||
}
|
||||
}
|
||||
|
||||
func toProto(ctx context.Context, in host.Set, hosts []host.Host, opt ...handlers.Option) (*pb.HostSet, error) {
|
||||
const op = "host_set_service.toProto"
|
||||
opts := handlers.GetOpts(opt...)
|
||||
@@ -712,15 +739,11 @@ func toProto(ctx context.Context, in host.Set, hosts []host.Host, opt ...handler
|
||||
out.HostCatalogId = in.GetCatalogId()
|
||||
}
|
||||
if outputFields.Has(globals.TypeField) {
|
||||
switch host.SubtypeFromId(in.GetPublicId()) {
|
||||
case static.Subtype:
|
||||
switch in.(type) {
|
||||
case *static.HostSet:
|
||||
out.Type = static.Subtype.String()
|
||||
case plugin.Subtype:
|
||||
out.Type = "plugin"
|
||||
idParts := strings.Split(in.GetPublicId(), "_")
|
||||
if len(idParts) > 2 {
|
||||
out.Type = idParts[1]
|
||||
}
|
||||
case *plugin.HostSet:
|
||||
out.Type = plugin.Subtype.String()
|
||||
}
|
||||
}
|
||||
if outputFields.Has(globals.DescriptionField) && in.GetDescription() != "" {
|
||||
@@ -741,6 +764,9 @@ func toProto(ctx context.Context, in host.Set, hosts []host.Host, opt ...handler
|
||||
if outputFields.Has(globals.ScopeField) {
|
||||
out.Scope = opts.WithScope
|
||||
}
|
||||
if outputFields.Has(globals.PluginField) {
|
||||
out.Plugin = opts.WithPlugin
|
||||
}
|
||||
if outputFields.Has(globals.AuthorizedActionsField) {
|
||||
out.AuthorizedActions = opts.WithAuthorizedActions
|
||||
}
|
||||
@@ -816,26 +842,14 @@ func toStoragePluginSet(ctx context.Context, catalogId string, item *pb.HostSet)
|
||||
// * The type asserted by the ID and/or field is known
|
||||
// * If relevant, the type derived from the id prefix matches what is claimed by the type field
|
||||
func validateGetRequest(req *pbs.GetHostSetRequest) error {
|
||||
pluginPrefix := plugin.HostSetPrefix
|
||||
idParts := strings.Split(req.GetId(), "_")
|
||||
if len(idParts) > 2 && idParts[0] == plugin.HostSetPrefix {
|
||||
pluginPrefix = strings.Join(idParts[:2], "_")
|
||||
}
|
||||
|
||||
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, static.HostSetPrefix, pluginPrefix)
|
||||
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, static.HostSetPrefix, plugin.HostSetPrefix)
|
||||
}
|
||||
|
||||
func validateCreateRequest(ctx context.Context, req *pbs.CreateHostSetRequest) error {
|
||||
return handlers.ValidateCreateRequest(req.GetItem(), func() map[string]string {
|
||||
badFields := map[string]string{}
|
||||
pluginPrefix := plugin.HostCatalogPrefix
|
||||
idParts := strings.Split(req.GetItem().GetHostCatalogId(), "_")
|
||||
if len(idParts) > 2 && idParts[0] == plugin.HostCatalogPrefix {
|
||||
pluginPrefix = strings.Join(idParts[:2], "_")
|
||||
}
|
||||
|
||||
if !handlers.ValidId(handlers.Id(req.GetItem().GetHostCatalogId()), static.HostCatalogPrefix, pluginPrefix) {
|
||||
badFields["host_catalog_id"] = "The field is incorrectly formatted."
|
||||
if !handlers.ValidId(handlers.Id(req.GetItem().GetHostCatalogId()), static.HostCatalogPrefix, plugin.HostCatalogPrefix) {
|
||||
badFields[globals.HostCatalogIdField] = "The field is incorrectly formatted."
|
||||
}
|
||||
if len(req.GetItem().GetPreferredEndpoints()) > 0 {
|
||||
_, err := endpoint.NewPreferencer(ctx, endpoint.WithPreferenceOrder(req.GetItem().GetPreferredEndpoints()))
|
||||
@@ -846,21 +860,11 @@ func validateCreateRequest(ctx context.Context, req *pbs.CreateHostSetRequest) e
|
||||
switch host.SubtypeFromId(req.GetItem().GetHostCatalogId()) {
|
||||
case static.Subtype:
|
||||
if req.GetItem().GetType() != "" && req.GetItem().GetType() != static.Subtype.String() {
|
||||
badFields["type"] = "Doesn't match the parent resource's type."
|
||||
badFields[globals.TypeField] = "Doesn't match the parent resource's type."
|
||||
}
|
||||
case plugin.Subtype:
|
||||
// TODO: Remove this check when plugin id prefixes can differ from plugin name
|
||||
if req.GetItem().GetType() == "" {
|
||||
break
|
||||
}
|
||||
idParts := strings.Split(req.GetItem().GetHostCatalogId(), "_")
|
||||
if len(idParts) < 2 {
|
||||
badFields["host_catalog_id"] = "The field is incorrectly formatted for a plugin id."
|
||||
break
|
||||
}
|
||||
plgType := idParts[1]
|
||||
if plgType != req.GetItem().GetType() {
|
||||
badFields["type"] = "This type must match the type of the host catalog."
|
||||
if req.GetItem().GetType() != "" && req.GetItem().GetType() != plugin.Subtype.String() {
|
||||
badFields[globals.TypeField] = "Doesn't match the parent resource's type."
|
||||
}
|
||||
}
|
||||
return badFields
|
||||
@@ -891,18 +895,12 @@ func validateDeleteRequest(req *pbs.DeleteHostSetRequest) error {
|
||||
}
|
||||
|
||||
func validateListRequest(req *pbs.ListHostSetsRequest) error {
|
||||
pluginPrefix := plugin.HostCatalogPrefix
|
||||
idParts := strings.Split(req.GetHostCatalogId(), "_")
|
||||
if len(idParts) > 2 && idParts[0] == plugin.HostCatalogPrefix {
|
||||
pluginPrefix = strings.Join(idParts[:2], "_")
|
||||
}
|
||||
|
||||
badFields := map[string]string{}
|
||||
if !handlers.ValidId(handlers.Id(req.GetHostCatalogId()), static.HostCatalogPrefix, pluginPrefix) {
|
||||
badFields["host_catalog_id"] = "The field is incorrectly formatted."
|
||||
if !handlers.ValidId(handlers.Id(req.GetHostCatalogId()), static.HostCatalogPrefix, plugin.HostCatalogPrefix) {
|
||||
badFields[globals.HostCatalogIdField] = "The field is incorrectly formatted."
|
||||
}
|
||||
if _, err := handlers.NewFilter(req.GetFilter()); err != nil {
|
||||
badFields["filter"] = fmt.Sprintf("This field could not be parsed. %v", err)
|
||||
badFields[globals.FilterField] = fmt.Sprintf("This field could not be parsed. %v", err)
|
||||
}
|
||||
if len(badFields) > 0 {
|
||||
return handlers.InvalidArgumentErrorf("Improperly formatted identifier.", badFields)
|
||||
@@ -913,17 +911,17 @@ func validateListRequest(req *pbs.ListHostSetsRequest) error {
|
||||
func validateAddRequest(req *pbs.AddHostSetHostsRequest) error {
|
||||
badFields := map[string]string{}
|
||||
if !handlers.ValidId(handlers.Id(req.GetId()), static.HostSetPrefix) {
|
||||
badFields["id"] = "Incorrectly formatted identifier."
|
||||
badFields[globals.IdField] = "Incorrectly formatted identifier."
|
||||
}
|
||||
if req.GetVersion() == 0 {
|
||||
badFields["version"] = "Required field."
|
||||
badFields[globals.VersionField] = "Required field."
|
||||
}
|
||||
if len(req.GetHostIds()) == 0 {
|
||||
badFields["host_ids"] = "Must be non-empty."
|
||||
badFields[globals.HostIdsField] = "Must be non-empty."
|
||||
}
|
||||
for _, id := range req.GetHostIds() {
|
||||
if !handlers.ValidId(handlers.Id(id), static.HostPrefix) {
|
||||
badFields["host_ids"] = "Incorrectly formatted host identifier."
|
||||
badFields[globals.HostIdsField] = "Incorrectly formatted host identifier."
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -936,14 +934,14 @@ func validateAddRequest(req *pbs.AddHostSetHostsRequest) error {
|
||||
func validateSetRequest(req *pbs.SetHostSetHostsRequest) error {
|
||||
badFields := map[string]string{}
|
||||
if !handlers.ValidId(handlers.Id(req.GetId()), static.HostSetPrefix) {
|
||||
badFields["id"] = "Incorrectly formatted identifier."
|
||||
badFields[globals.IdField] = "Incorrectly formatted identifier."
|
||||
}
|
||||
if req.GetVersion() == 0 {
|
||||
badFields["version"] = "Required field."
|
||||
badFields[globals.VersionField] = "Required field."
|
||||
}
|
||||
for _, id := range req.GetHostIds() {
|
||||
if !handlers.ValidId(handlers.Id(id), static.HostPrefix) {
|
||||
badFields["host_ids"] = "Incorrectly formatted host identifier."
|
||||
badFields[globals.HostIdsField] = "Incorrectly formatted host identifier."
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -956,17 +954,17 @@ func validateSetRequest(req *pbs.SetHostSetHostsRequest) error {
|
||||
func validateRemoveRequest(req *pbs.RemoveHostSetHostsRequest) error {
|
||||
badFields := map[string]string{}
|
||||
if !handlers.ValidId(handlers.Id(req.GetId()), static.HostSetPrefix) {
|
||||
badFields["id"] = "Incorrectly formatted identifier."
|
||||
badFields[globals.IdField] = "Incorrectly formatted identifier."
|
||||
}
|
||||
if req.GetVersion() == 0 {
|
||||
badFields["version"] = "Required field."
|
||||
badFields[globals.VersionField] = "Required field."
|
||||
}
|
||||
if len(req.GetHostIds()) == 0 {
|
||||
badFields["host_ids"] = "Must be non-empty."
|
||||
badFields[globals.HostIdsField] = "Must be non-empty."
|
||||
}
|
||||
for _, id := range req.GetHostIds() {
|
||||
if !handlers.ValidId(handlers.Id(id), static.HostPrefix) {
|
||||
badFields["host_ids"] = "Incorrectly formatted host identifier."
|
||||
badFields[globals.HostIdsField] = "Incorrectly formatted host identifier."
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"github.com/hashicorp/boundary/internal/servers/controller/handlers/host_sets"
|
||||
"github.com/hashicorp/boundary/internal/types/scope"
|
||||
pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/hostsets"
|
||||
"github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/plugins"
|
||||
"github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/scopes"
|
||||
plgpb "github.com/hashicorp/boundary/sdk/pbs/plugin"
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -153,7 +154,7 @@ func TestGet_Plugin(t *testing.T) {
|
||||
|
||||
name := "test"
|
||||
prefEndpoints := []string{"cidr:1.2.3.4", "cidr:2.3.4.5/24"}
|
||||
plg := hostplugin.TestPlugin(t, conn, name, name)
|
||||
plg := hostplugin.TestPlugin(t, conn, name)
|
||||
hc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId())
|
||||
hs := plugin.TestSet(t, conn, kms, hc, map[string]plgpb.HostPluginServiceServer{
|
||||
plg.GetPublicId(): &plugin.TestPluginServer{},
|
||||
@@ -162,12 +163,17 @@ func TestGet_Plugin(t *testing.T) {
|
||||
toMerge := &pbs.GetHostSetRequest{}
|
||||
|
||||
pHost := &pb.HostSet{
|
||||
HostCatalogId: hc.GetPublicId(),
|
||||
Id: hs.GetPublicId(),
|
||||
CreatedTime: hs.CreateTime.GetTimestamp(),
|
||||
UpdatedTime: hs.UpdateTime.GetTimestamp(),
|
||||
Type: name,
|
||||
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
|
||||
HostCatalogId: hc.GetPublicId(),
|
||||
Id: hs.GetPublicId(),
|
||||
CreatedTime: hs.CreateTime.GetTimestamp(),
|
||||
UpdatedTime: hs.UpdateTime.GetTimestamp(),
|
||||
Type: plugin.Subtype.String(),
|
||||
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
|
||||
Plugin: &plugins.PluginInfo{
|
||||
Id: plg.GetPublicId(),
|
||||
Name: plg.GetName(),
|
||||
Description: plg.GetDescription(),
|
||||
},
|
||||
PreferredEndpoints: prefEndpoints,
|
||||
AuthorizedActions: testAuthorizedActions,
|
||||
}
|
||||
@@ -342,7 +348,7 @@ func TestList_Plugin(t *testing.T) {
|
||||
return static.NewRepository(rw, rw, kms)
|
||||
}
|
||||
name := "test"
|
||||
plg := hostplugin.TestPlugin(t, conn, name, name)
|
||||
plg := hostplugin.TestPlugin(t, conn, name)
|
||||
plgm := map[string]plgpb.HostPluginServiceServer{
|
||||
plg.GetPublicId(): &plugin.TestPluginServer{},
|
||||
}
|
||||
@@ -357,13 +363,18 @@ func TestList_Plugin(t *testing.T) {
|
||||
for i := 0; i < 10; i++ {
|
||||
h := plugin.TestSet(t, conn, kms, hc, plgm, plugin.WithPreferredEndpoints(preferredEndpoints))
|
||||
wantHs = append(wantHs, &pb.HostSet{
|
||||
Id: h.GetPublicId(),
|
||||
HostCatalogId: h.GetCatalogId(),
|
||||
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
|
||||
Id: h.GetPublicId(),
|
||||
HostCatalogId: h.GetCatalogId(),
|
||||
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
|
||||
Plugin: &plugins.PluginInfo{
|
||||
Id: plg.GetPublicId(),
|
||||
Name: plg.GetName(),
|
||||
Description: plg.GetDescription(),
|
||||
},
|
||||
CreatedTime: h.GetCreateTime().GetTimestamp(),
|
||||
UpdatedTime: h.GetUpdateTime().GetTimestamp(),
|
||||
Version: h.GetVersion(),
|
||||
Type: name,
|
||||
Type: plugin.Subtype.String(),
|
||||
AuthorizedActions: testAuthorizedActions,
|
||||
PreferredEndpoints: preferredEndpoints,
|
||||
})
|
||||
@@ -707,7 +718,7 @@ func TestCreate_Plugin(t *testing.T) {
|
||||
return static.NewRepository(rw, rw, kms)
|
||||
}
|
||||
name := "test"
|
||||
plg := hostplugin.TestPlugin(t, conn, name, name)
|
||||
plg := hostplugin.TestPlugin(t, conn, name)
|
||||
plgRepoFn := func() (*plugin.Repository, error) {
|
||||
return plugin.NewRepository(rw, rw, kms, map[string]plgpb.HostPluginServiceServer{
|
||||
plg.GetPublicId(): &plugin.TestPluginServer{
|
||||
@@ -757,16 +768,21 @@ func TestCreate_Plugin(t *testing.T) {
|
||||
HostCatalogId: hc.GetPublicId(),
|
||||
Name: &wrappers.StringValue{Value: "No Attributes"},
|
||||
Description: &wrappers.StringValue{Value: "desc"},
|
||||
Type: name,
|
||||
Type: plugin.Subtype.String(),
|
||||
}},
|
||||
res: &pbs.CreateHostSetResponse{
|
||||
Uri: fmt.Sprintf("host-sets/%s_%s_", plugin.HostSetPrefix, name),
|
||||
Uri: fmt.Sprintf("host-sets/%s_", plugin.HostSetPrefix),
|
||||
Item: &pb.HostSet{
|
||||
HostCatalogId: hc.GetPublicId(),
|
||||
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
|
||||
HostCatalogId: hc.GetPublicId(),
|
||||
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
|
||||
Plugin: &plugins.PluginInfo{
|
||||
Id: plg.GetPublicId(),
|
||||
Name: plg.GetName(),
|
||||
Description: plg.GetDescription(),
|
||||
},
|
||||
Name: &wrappers.StringValue{Value: "No Attributes"},
|
||||
Description: &wrappers.StringValue{Value: "desc"},
|
||||
Type: name,
|
||||
Type: plugin.Subtype.String(),
|
||||
AuthorizedActions: testAuthorizedActions,
|
||||
},
|
||||
},
|
||||
@@ -777,17 +793,22 @@ func TestCreate_Plugin(t *testing.T) {
|
||||
HostCatalogId: hc.GetPublicId(),
|
||||
Name: &wrappers.StringValue{Value: "With Attributes"},
|
||||
Description: &wrappers.StringValue{Value: "desc"},
|
||||
Type: name,
|
||||
Type: plugin.Subtype.String(),
|
||||
Attributes: testAttrs,
|
||||
}},
|
||||
res: &pbs.CreateHostSetResponse{
|
||||
Uri: fmt.Sprintf("host-sets/%s_%s_", plugin.HostSetPrefix, name),
|
||||
Uri: fmt.Sprintf("host-sets/%s_", plugin.HostSetPrefix),
|
||||
Item: &pb.HostSet{
|
||||
HostCatalogId: hc.GetPublicId(),
|
||||
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
|
||||
HostCatalogId: hc.GetPublicId(),
|
||||
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
|
||||
Plugin: &plugins.PluginInfo{
|
||||
Id: plg.GetPublicId(),
|
||||
Name: plg.GetName(),
|
||||
Description: plg.GetDescription(),
|
||||
},
|
||||
Name: &wrappers.StringValue{Value: "With Attributes"},
|
||||
Description: &wrappers.StringValue{Value: "desc"},
|
||||
Type: name,
|
||||
Type: plugin.Subtype.String(),
|
||||
AuthorizedActions: testAuthorizedActions,
|
||||
Attributes: testAttrs,
|
||||
},
|
||||
@@ -799,17 +820,22 @@ func TestCreate_Plugin(t *testing.T) {
|
||||
HostCatalogId: hc.GetPublicId(),
|
||||
Name: &wrappers.StringValue{Value: "name"},
|
||||
Description: &wrappers.StringValue{Value: "desc"},
|
||||
Type: name,
|
||||
Type: plugin.Subtype.String(),
|
||||
PreferredEndpoints: prefEndpoints,
|
||||
}},
|
||||
res: &pbs.CreateHostSetResponse{
|
||||
Uri: fmt.Sprintf("host-sets/%s_%s_", plugin.HostSetPrefix, name),
|
||||
Uri: fmt.Sprintf("host-sets/%s_", plugin.HostSetPrefix),
|
||||
Item: &pb.HostSet{
|
||||
HostCatalogId: hc.GetPublicId(),
|
||||
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
|
||||
HostCatalogId: hc.GetPublicId(),
|
||||
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
|
||||
Plugin: &plugins.PluginInfo{
|
||||
Id: plg.GetPublicId(),
|
||||
Name: plg.GetName(),
|
||||
Description: plg.GetDescription(),
|
||||
},
|
||||
Name: &wrappers.StringValue{Value: "name"},
|
||||
Description: &wrappers.StringValue{Value: "desc"},
|
||||
Type: name,
|
||||
Type: plugin.Subtype.String(),
|
||||
PreferredEndpoints: prefEndpoints,
|
||||
AuthorizedActions: testAuthorizedActions,
|
||||
},
|
||||
@@ -821,7 +847,7 @@ func TestCreate_Plugin(t *testing.T) {
|
||||
HostCatalogId: hc.GetPublicId(),
|
||||
Name: &wrappers.StringValue{Value: "name"},
|
||||
Description: &wrappers.StringValue{Value: "desc"},
|
||||
Type: name,
|
||||
Type: plugin.Subtype.String(),
|
||||
PreferredEndpoints: append(prefEndpoints, "foobar:1.2.3.4"),
|
||||
}},
|
||||
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
|
||||
@@ -844,13 +870,18 @@ func TestCreate_Plugin(t *testing.T) {
|
||||
Description: &wrappers.StringValue{Value: "no type desc"},
|
||||
}},
|
||||
res: &pbs.CreateHostSetResponse{
|
||||
Uri: fmt.Sprintf("host-sets/%s_%s_", plugin.HostSetPrefix, name),
|
||||
Uri: fmt.Sprintf("host-sets/%s_", plugin.HostSetPrefix),
|
||||
Item: &pb.HostSet{
|
||||
HostCatalogId: hc.GetPublicId(),
|
||||
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
|
||||
HostCatalogId: hc.GetPublicId(),
|
||||
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
|
||||
Plugin: &plugins.PluginInfo{
|
||||
Id: plg.GetPublicId(),
|
||||
Name: plg.GetName(),
|
||||
Description: plg.GetDescription(),
|
||||
},
|
||||
Name: &wrappers.StringValue{Value: "no type name"},
|
||||
Description: &wrappers.StringValue{Value: "no type desc"},
|
||||
Type: name,
|
||||
Type: plugin.Subtype.String(),
|
||||
AuthorizedActions: testAuthorizedActions,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -2,6 +2,7 @@ package handlers
|
||||
|
||||
import (
|
||||
"github.com/hashicorp/boundary/internal/perms"
|
||||
"github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/plugins"
|
||||
"github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/scopes"
|
||||
"google.golang.org/protobuf/types/known/structpb"
|
||||
)
|
||||
@@ -26,6 +27,7 @@ type options struct {
|
||||
WithUserIsAnonymous bool
|
||||
WithOutputFields *perms.OutputFieldsMap
|
||||
WithScope *scopes.ScopeInfo
|
||||
WithPlugin *plugins.PluginInfo
|
||||
WithAuthorizedActions []string
|
||||
WithAuthorizedCollectionActions map[string]*structpb.ListValue
|
||||
WithManagedGroupIds []string
|
||||
@@ -69,6 +71,14 @@ func WithScope(scp *scopes.ScopeInfo) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// WithPlugin provides an option when creating responses to include the given
|
||||
// plugin if allowed
|
||||
func WithPlugin(plg *plugins.PluginInfo) Option {
|
||||
return func(o *options) {
|
||||
o.WithPlugin = plg
|
||||
}
|
||||
}
|
||||
|
||||
// WithAuthorizedActions provides an option when creating responses to include the given
|
||||
// authorized actions if allowed
|
||||
func WithAuthorizedActions(acts []string) Option {
|
||||
|
||||
@@ -982,7 +982,7 @@ func TestAddTargetHostSets(t *testing.T) {
|
||||
hc := static.TestCatalogs(t, conn, proj.GetPublicId(), 1)[0]
|
||||
hs := static.TestSets(t, conn, hc.GetPublicId(), 2)
|
||||
|
||||
plg := host.TestPlugin(t, conn, "test", "test")
|
||||
plg := host.TestPlugin(t, conn, "test")
|
||||
pluginHc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId())
|
||||
pluginHs := plugin.TestSet(t, conn, kms, pluginHc, map[string]plgpb.HostPluginServiceServer{
|
||||
plg.GetPublicId(): &plugin.TestPluginServer{},
|
||||
@@ -1116,7 +1116,7 @@ func TestSetTargetHostSets(t *testing.T) {
|
||||
hc := static.TestCatalogs(t, conn, proj.GetPublicId(), 1)[0]
|
||||
hs := static.TestSets(t, conn, hc.GetPublicId(), 2)
|
||||
|
||||
plg := host.TestPlugin(t, conn, "test", "test")
|
||||
plg := host.TestPlugin(t, conn, "test")
|
||||
pluginHc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId())
|
||||
pluginHs := plugin.TestSet(t, conn, kms, pluginHc, map[string]plgpb.HostPluginServiceServer{
|
||||
plg.GetPublicId(): &plugin.TestPluginServer{},
|
||||
@@ -1244,7 +1244,7 @@ func TestRemoveTargetHostSets(t *testing.T) {
|
||||
hc := static.TestCatalogs(t, conn, proj.GetPublicId(), 1)[0]
|
||||
hs := static.TestSets(t, conn, hc.GetPublicId(), 2)
|
||||
|
||||
plg := host.TestPlugin(t, conn, "test", "test")
|
||||
plg := host.TestPlugin(t, conn, "test")
|
||||
pluginHc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId())
|
||||
pluginHs := plugin.TestSet(t, conn, kms, pluginHc, map[string]plgpb.HostPluginServiceServer{
|
||||
plg.GetPublicId(): &plugin.TestPluginServer{},
|
||||
@@ -1384,7 +1384,7 @@ func TestAddTargetHostSources(t *testing.T) {
|
||||
hc := static.TestCatalogs(t, conn, proj.GetPublicId(), 1)[0]
|
||||
hs := static.TestSets(t, conn, hc.GetPublicId(), 2)
|
||||
|
||||
plg := host.TestPlugin(t, conn, "test", "test")
|
||||
plg := host.TestPlugin(t, conn, "test")
|
||||
pluginHc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId())
|
||||
pluginHs := plugin.TestSet(t, conn, kms, pluginHc, map[string]plgpb.HostPluginServiceServer{
|
||||
plg.GetPublicId(): &plugin.TestPluginServer{},
|
||||
@@ -1518,7 +1518,7 @@ func TestSetTargetHostSources(t *testing.T) {
|
||||
hc := static.TestCatalogs(t, conn, proj.GetPublicId(), 1)[0]
|
||||
hs := static.TestSets(t, conn, hc.GetPublicId(), 2)
|
||||
|
||||
plg := host.TestPlugin(t, conn, "test", "test")
|
||||
plg := host.TestPlugin(t, conn, "test")
|
||||
pluginHc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId())
|
||||
pluginHs := plugin.TestSet(t, conn, kms, pluginHc, map[string]plgpb.HostPluginServiceServer{
|
||||
plg.GetPublicId(): &plugin.TestPluginServer{},
|
||||
@@ -1640,7 +1640,7 @@ func TestRemoveTargetHostSources(t *testing.T) {
|
||||
hc := static.TestCatalogs(t, conn, proj.GetPublicId(), 1)[0]
|
||||
hs := static.TestSets(t, conn, hc.GetPublicId(), 2)
|
||||
|
||||
plg := host.TestPlugin(t, conn, "test", "test")
|
||||
plg := host.TestPlugin(t, conn, "test")
|
||||
pluginHc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId())
|
||||
pluginHs := plugin.TestSet(t, conn, kms, pluginHc, map[string]plgpb.HostPluginServiceServer{
|
||||
plg.GetPublicId(): &plugin.TestPluginServer{},
|
||||
|
||||
Reference in new issue
Block a user