2022-06-15 08:27:08 -07:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2022-06-20 18:20:17 -07:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-02-02 17:15:17 -08:00
|
|
|
|
2022-06-20 18:20:17 -07:00
|
|
|
package server
|
2022-05-18 17:03:24 -07:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
2023-03-10 15:06:39 -05:00
|
|
|
"github.com/hashicorp/boundary/globals"
|
2022-05-18 17:03:24 -07:00
|
|
|
"github.com/hashicorp/boundary/internal/db"
|
|
|
|
|
"github.com/hashicorp/boundary/internal/errors"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func newWorkerId(ctx context.Context) (string, error) {
|
2023-06-06 17:09:08 -04:00
|
|
|
id, err := db.NewPublicId(ctx, globals.WorkerPrefix)
|
2022-05-18 17:03:24 -07:00
|
|
|
if err != nil {
|
2022-06-20 18:20:17 -07:00
|
|
|
return "", errors.Wrap(ctx, err, "server.newWorkerId")
|
2022-05-18 17:03:24 -07:00
|
|
|
}
|
|
|
|
|
return id, nil
|
|
|
|
|
}
|
2022-06-15 08:27:08 -07:00
|
|
|
|
2023-04-03 17:44:41 -04:00
|
|
|
// NewWorkerIdFromScopeAndName generates a predictable public id based on the
|
2022-06-15 08:27:08 -07:00
|
|
|
// scope and the worker name. This should only be used on kms workers at
|
|
|
|
|
// upsert time.
|
2023-04-03 17:44:41 -04:00
|
|
|
func NewWorkerIdFromScopeAndName(ctx context.Context, scope, name string) (string, error) {
|
|
|
|
|
const op = "server.NewWorkerIdFromScopeAndName"
|
2023-06-06 17:09:08 -04:00
|
|
|
id, err := db.NewPublicId(ctx, globals.WorkerPrefix, db.WithPrngValues([]string{scope, name}))
|
2022-06-15 08:27:08 -07:00
|
|
|
if err != nil {
|
2022-06-20 18:20:17 -07:00
|
|
|
return "", errors.Wrap(ctx, err, "server.newWorkerId")
|
2022-06-15 08:27:08 -07:00
|
|
|
}
|
|
|
|
|
return id, nil
|
|
|
|
|
}
|