2021-09-24 13:16:13 -07:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-02-02 17:15:17 -08:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
2021-09-08 10:06:38 -07:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
|
|
import (
|
2021-09-09 11:15:14 -07:00
|
|
|
"context"
|
2021-09-09 10:45:41 -07:00
|
|
|
|
2023-03-10 15:06:39 -05:00
|
|
|
"github.com/hashicorp/boundary/globals"
|
2021-09-08 10:06:38 -07:00
|
|
|
"github.com/hashicorp/boundary/internal/db"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/errors"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/host"
|
2023-11-15 19:55:46 -05:00
|
|
|
"github.com/hashicorp/boundary/internal/types/resource"
|
2021-09-08 10:06:38 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func init() {
|
2023-11-15 19:55:46 -05:00
|
|
|
globals.RegisterPrefixToResourceInfo(globals.PluginHostCatalogPrefix, resource.HostCatalog, host.Domain, Subtype)
|
|
|
|
|
globals.RegisterPrefixToResourceInfo(globals.PluginHostCatalogPreviousPrefix, resource.HostCatalog, host.Domain, Subtype)
|
|
|
|
|
globals.RegisterPrefixToResourceInfo(globals.PluginHostSetPrefix, resource.HostSet, host.Domain, Subtype)
|
|
|
|
|
globals.RegisterPrefixToResourceInfo(globals.PluginHostSetPreviousPrefix, resource.HostSet, host.Domain, Subtype)
|
|
|
|
|
globals.RegisterPrefixToResourceInfo(globals.PluginHostPrefix, resource.Host, host.Domain, Subtype)
|
|
|
|
|
globals.RegisterPrefixToResourceInfo(globals.PluginHostPreviousPrefix, resource.Host, host.Domain, Subtype)
|
2021-09-08 10:06:38 -07:00
|
|
|
}
|
|
|
|
|
|
2023-11-02 16:03:47 -04:00
|
|
|
// PublicId prefixes for the resources in the plugin package.
|
|
|
|
|
const (
|
2023-11-15 19:55:46 -05:00
|
|
|
Subtype = globals.Subtype("plugin")
|
2023-11-02 16:03:47 -04:00
|
|
|
)
|
|
|
|
|
|
2021-09-24 13:16:13 -07:00
|
|
|
func newHostCatalogId(ctx context.Context) (string, error) {
|
2023-06-06 17:09:08 -04:00
|
|
|
id, err := db.NewPublicId(ctx, globals.PluginHostCatalogPrefix)
|
2021-09-08 10:06:38 -07:00
|
|
|
if err != nil {
|
2021-09-09 11:15:14 -07:00
|
|
|
return "", errors.Wrap(ctx, err, "plugin.newHostCatalogId")
|
2021-09-08 10:06:38 -07:00
|
|
|
}
|
|
|
|
|
return id, nil
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-24 13:16:13 -07:00
|
|
|
func newHostSetId(ctx context.Context) (string, error) {
|
2023-06-06 17:09:08 -04:00
|
|
|
id, err := db.NewPublicId(ctx, globals.PluginHostSetPrefix)
|
2021-09-08 10:06:38 -07:00
|
|
|
if err != nil {
|
2021-09-09 11:15:14 -07:00
|
|
|
return "", errors.Wrap(ctx, err, "plugin.newHostSetId")
|
2021-09-08 10:06:38 -07:00
|
|
|
}
|
|
|
|
|
return id, nil
|
|
|
|
|
}
|
2021-09-26 08:17:21 -07:00
|
|
|
|
|
|
|
|
func newHostId(ctx context.Context, catalogId, externalId string) (string, error) {
|
|
|
|
|
const op = "plugin.newHostId"
|
|
|
|
|
if catalogId == "" {
|
|
|
|
|
return "", errors.New(ctx, errors.InvalidParameter, op, "missing catalog id")
|
|
|
|
|
}
|
|
|
|
|
if externalId == "" {
|
|
|
|
|
return "", errors.New(ctx, errors.InvalidParameter, op, "missing external id")
|
|
|
|
|
}
|
2023-06-06 17:09:08 -04:00
|
|
|
id, err := db.NewPublicId(ctx, globals.PluginHostPrefix, db.WithPrngValues([]string{catalogId, externalId}))
|
2021-09-26 08:17:21 -07:00
|
|
|
if err != nil {
|
|
|
|
|
return "", errors.Wrap(ctx, err, op)
|
|
|
|
|
}
|
|
|
|
|
return id, nil
|
|
|
|
|
}
|