2026-04-06 15:48:37 +05:30
|
|
|
// Copyright IBM Corp. 2020, 2026
|
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"
|
|
|
|
|
|
2026-10-12 10:33:41 -07:00
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/globals"
|
|
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/db"
|
|
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/errors"
|
2022-05-18 17:03:24 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|