Files
threshold/internal/cmd/commands/workerscmd/worker-led_funcs.go
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

70 lines
2.2 KiB
Go
Raw Normal View History

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
2023-02-02 17:15:17 -08:00
2022-06-10 09:05:43 -04:00
package workerscmd
import (
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/workers"
"github.com/hashicorp/boundary/internal/cmd/base"
)
func init() {
extraWorkerLedActionsFlagsMapFunc = extraWorkerLedActionsFlagsMapFuncImpl
extraWorkerLedFlagsFunc = extraWorkerLedFlagsFuncImpl
executeExtraWorkerLedActions = executeExtraWorkerLedActionsImpl
}
type extraWorkerLedCmdVars struct {
flagWorkerGeneratedAuthToken string
}
func extraWorkerLedActionsFlagsMapFuncImpl() map[string][]string {
return map[string][]string{
"create": {"worker-generated-auth-token"},
}
}
func (c *WorkerLedCommand) extraWorkerLedHelpFunc(helpMap map[string]func() string) string {
var helpStr string
switch c.Func {
case "create":
helpStr = base.WrapForHelpText([]string{
"Usage: boundary workers create worker-led [options] [args]",
"",
" Create a worker using the worker-led approach by providing an auth token from the worker. Example:",
"",
` $ boundary workers create worker-led -name us-east-1-1 -worker-generated-auth-token <token>"`,
"",
"",
})
}
return helpStr + c.Flags().Help()
}
2024-02-13 10:54:48 -05:00
func extraWorkerLedFlagsFuncImpl(c *WorkerLedCommand, set *base.FlagSets, _ *base.FlagSet) {
f := set.NewFlagSet("Worker Creation Options")
2022-06-10 09:05:43 -04:00
for _, name := range flagsWorkerLedMap[c.Func] {
switch name {
case "worker-generated-auth-token":
f.StringVar(&base.StringVar{
Name: "worker-generated-auth-token",
Target: &c.flagWorkerGeneratedAuthToken,
Usage: "The auth token provided by the worker to use to register it to Boundary",
})
}
}
}
func executeExtraWorkerLedActionsImpl(c *WorkerLedCommand, origResp *api.Response, origItem *workers.Worker, origError error, workerClient *workers.Client, version uint32, opts []workers.Option) (*api.Response, *workers.Worker, error) {
2022-06-10 09:05:43 -04:00
switch c.Func {
case "create":
result, err := workerClient.CreateWorkerLed(c.Context, c.flagWorkerGeneratedAuthToken, c.FlagScopeId, opts...)
if err != nil {
return nil, nil, err
}
return result.GetResponse(), result.GetItem(), nil
2022-06-10 09:05:43 -04:00
}
return origResp, origItem, origError
2022-06-10 09:05:43 -04:00
}