Rename daemon CLI command to cache (#4808)

* internal/cmd/wrapper: add deprecation wrapper

The deprecation wrapper can be used to display a warning to callers
when a command is deprecated.

* all: rename daemon to cache

Rename the boundary daemon command to boundary cache. This
avoids confusion with future client/daemons.

* changes daemon to cache in nav

---------

Co-authored-by: Robin Beck <stellarsquall@protonmail.ch>
This commit is contained in:
Johan Brandhorst-SatzkornandRobin Beck authored and GitHub committed 2024-05-22 11:11:48 -07:00
1 parent be7d72d690
commit e64443c66f
34 files changed
+554 -299

No files matched your search

@@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package daemon
package cache
import (
"context"
@@ -28,16 +28,16 @@ type AddTokenCommand struct {
}
func (c *AddTokenCommand) Synopsis() string {
return "Add an auth token to a running boundary daemon"
return "Add an auth token to a running boundary cache"
}
func (c *AddTokenCommand) Help() string {
helpText := `
Usage: boundary daemon add-token [options]
Usage: boundary cache add-token [options]
Add an auth token to the daemon:
Add an auth token to the cache:
$ boundary daemon add-token
$ boundary cache add-token
For a full list of examples, please see the documentation.
@@ -121,7 +121,7 @@ func (c *AddTokenCommand) Run(args []string) int {
return base.CommandCliError
}
if apiErr != nil {
c.PrintApiError(apiErr, "Error from daemon when adding a token")
c.PrintApiError(apiErr, "Error from cache when adding a token")
return base.CommandApiError
}
switch base.Format(c.UI) {
@@ -130,13 +130,13 @@ func (c *AddTokenCommand) Run(args []string) int {
return base.CommandCliError
}
case "table":
c.UI.Output("The daemon add-token operation completed successfully.")
c.UI.Output("The cache add-token operation completed successfully.")
}
return base.CommandSuccess
}
// Add builds the UpsertTokenRequest using the client's address and token,
// and trying to leverage the keyring. It then sends the request to the daemon.
// and trying to leverage the keyring. It then sends the request to the cache.
// The passed in cli.Ui is used to print out any errors when looking up the
// auth token from the keyring. This allows background operations calling this
// method to pass in a silent UI to suppress any output.
@@ -206,7 +206,7 @@ func addToken(ctx context.Context, daemonPath string, p *daemon.UpsertTokenReque
}
resp, err := c.Post(ctx, "/v1/tokens", p, opt...)
if err != nil {
return nil, nil, fmt.Errorf("Error when sending request to the daemon: %w.", err)
return nil, nil, fmt.Errorf("Error when sending request to the cache: %w.", err)
}
apiErr, err := resp.Decode(nil)
return resp, apiErr, err
+60
View File
@@ -0,0 +1,60 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package cache
import (
"strings"
"github.com/hashicorp/boundary/internal/cmd/base"
"github.com/mitchellh/cli"
"github.com/posener/complete"
)
var (
_ cli.Command = (*StartCommand)(nil)
_ cli.CommandAutocomplete = (*StartCommand)(nil)
)
type CacheCommand struct {
*base.Command
}
func (c *CacheCommand) Synopsis() string {
return "Manages the client side Boundary cache"
}
func (c *CacheCommand) Help() string {
helpText := `
Usage: boundary cache [sub command] [options]
This command allows interacting with the Boundary cache.
Start a cache:
$ boundary cache start
For a full list of examples, please see the documentation.
`
return strings.TrimSpace(helpText)
}
func (c *CacheCommand) Flags() *base.FlagSets {
return c.FlagSet(base.FlagSetNone)
}
func (c *CacheCommand) AutocompleteArgs() complete.Predictor {
return complete.PredictNothing
}
func (c *CacheCommand) AutocompleteFlags() complete.Flags {
return c.Flags().Completions()
}
func (c *CacheCommand) Run(args []string) int {
if len(args) >= 2 && args[1] == "daemon" {
c.UI.Warn("The `boundary daemon` command is deprecated, use `boundary cache` instead")
}
return cli.RunResultHelp
}
@@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package daemon
package cache
import (
"bytes"
@@ -4,7 +4,7 @@
//go:build !windows
// +build !windows
package daemon
package cache
import (
"context"
@@ -16,7 +16,7 @@ import (
)
func writePidFile(ctx context.Context, pidFile string) (pidCleanup, error) {
const op = "daemon.writePidFile"
const op = "cache.writePidFile"
// Determine if we should clean up the file after we are done or if
// it should stick around in the case of lock aquision error since this
@@ -57,7 +57,7 @@ func writePidFile(ctx context.Context, pidFile string) (pidCleanup, error) {
}
func pidFileInUse(ctx context.Context, pidFile string) (*os.Process, error) {
const op = "daemon.pidFileInUse"
const op = "cache.pidFileInUse"
if pidFile == "" {
return nil, errors.New(ctx, errors.InvalidParameter, op, "pid filename is empty")
}
@@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package daemon
package cache
import (
"context"
@@ -4,7 +4,7 @@
//go:build windows
// +build windows
package daemon
package cache
import (
"bytes"
@@ -20,7 +20,7 @@ import (
)
func writePidFile(ctx context.Context, pidFile string) (pidCleanup, error) {
const op = "daemon.writePidFile"
const op = "cache.writePidFile"
// Create the file for writing, and set shared read so following processes
// cannot open this file for writing.
fd, err := windows.CreateFile(&(windows.StringToUTF16(pidFile)[0]), windows.GENERIC_WRITE,
@@ -59,7 +59,7 @@ func writePidFile(ctx context.Context, pidFile string) (pidCleanup, error) {
}
func pidFileInUse(ctx context.Context, pidFile string) (*os.Process, error) {
const op = "daemon.pidFileInUse"
const op = "cache.pidFileInUse"
if pidFile == "" {
return nil, errors.New(ctx, errors.InvalidParameter, op, "pid filename is empty")
}
@@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package daemon
package cache
import (
"context"
@@ -30,7 +30,7 @@ const (
logFileName = "cache.log"
// Mark of process as having been started in the background
backgroundEnvName = "_BOUNDARY_DAEMON_BACKGROUND"
backgroundEnvName = "_BOUNDARY_CACHE_BACKGROUND"
backgroundEnvVal = "1"
)
@@ -54,16 +54,16 @@ type StartCommand struct {
}
func (c *StartCommand) Synopsis() string {
return "Start a Boundary daemon"
return "Start a Boundary cache"
}
func (c *StartCommand) Help() string {
helpText := `
Usage: boundary daemon start [options]
Usage: boundary cache start [options]
Start a daemon:
Start a cache:
$ boundary daemon start
$ boundary cache start
For a full list of examples, please see the documentation.
@@ -132,7 +132,7 @@ func (c *StartCommand) Flags() *base.FlagSets {
Name: "background",
Target: &c.flagBackground,
Default: false,
Usage: `Run the client cache daemon in the background`,
Usage: `Run the cache daemon in the background`,
})
return set
@@ -242,7 +242,7 @@ func (c *StartCommand) Run(args []string) int {
// DefaultDotDirectory returns the default path to the boundary dot directory.
func DefaultDotDirectory(ctx context.Context) (string, error) {
const op = "daemon.DefaultDotDirectory"
const op = "cache.DefaultDotDirectory"
homeDir, err := homedir.Dir()
if err != nil {
return "", errors.Wrap(ctx, err, op)
@@ -256,7 +256,7 @@ func DefaultDotDirectory(ctx context.Context) (string, error) {
// are saved as backup. When a new log file is rotated and there is already 3
// backups created, the oldest one is deleted.
func logFile(ctx context.Context, dotDir string, maxSizeMb int) (io.WriteCloser, string, error) {
const op = "daemon.logFile"
const op = "cache.logFile"
logFilePath := filepath.Join(dotDir, logFileName)
{
// Ensure the file is created with the desired permissions.
@@ -277,14 +277,14 @@ func logFile(ctx context.Context, dotDir string, maxSizeMb int) (io.WriteCloser,
}
func (c *StartCommand) makeBackground(ctx context.Context, dotDir string) (bool, []io.Writer, pidCleanup, error) {
const op = "daemon.makeBackground"
const op = "cache.makeBackground"
writers := []io.Writer{}
pidPath := filepath.Join(dotDir, pidFileName)
if running, err := pidFileInUse(ctx, pidPath); running != nil {
return false, writers, noopPidCleanup, stderrors.New("The daemon is already running.")
return false, writers, noopPidCleanup, stderrors.New("The cache is already running.")
} else if err != nil && !errors.Match(errors.T(errors.NotFound), err) {
return false, writers, noopPidCleanup, fmt.Errorf("Error when checking if the daemon pid is in use: %w.", err)
return false, writers, noopPidCleanup, fmt.Errorf("Error when checking if the cache pid is in use: %w.", err)
}
if !c.flagBackground && os.Getenv(backgroundEnvName) != backgroundEnvVal {
@@ -308,7 +308,7 @@ func (c *StartCommand) makeBackground(ctx context.Context, dotDir string) (bool,
env := os.Environ()
env = append(env, fmt.Sprintf("%s=%s", backgroundEnvName, backgroundEnvVal))
args := []string{"daemon", "start"}
args := []string{"cache", "start"}
args = append(args, "-refresh-interval", c.flagRefreshInterval.String())
args = append(args, "-max-search-staleness", c.flagMaxSearchStaleness.String())
args = append(args, "-max-search-refresh-timeout", c.flagMaxSearchRefreshTimeout.String())
@@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package daemon
package cache
import (
"context"
@@ -22,7 +22,7 @@ import (
"golang.org/x/text/language"
)
var errDaemonNotRunning = stderr.New("The daemon process is not running.")
var errCacheNotRunning = stderr.New("The cache process is not running.")
var (
_ cli.Command = (*AddTokenCommand)(nil)
@@ -34,16 +34,16 @@ type StatusCommand struct {
}
func (c *StatusCommand) Synopsis() string {
return "Get the status information of the running boundary daemon"
return "Get the status information of the running boundary cache"
}
func (c *StatusCommand) Help() string {
helpText := `
Usage: boundary daemon status [options]
Usage: boundary cache status [options]
Get the status of the boundary daemon:
Get the status of the boundary cache:
$ boundary daemon status
$ boundary cache status
For a full list of examples, please see the documentation.
@@ -86,7 +86,7 @@ func (c *StatusCommand) Run(args []string) int {
return base.CommandCliError
}
if apiErr != nil {
c.PrintApiError(apiErr, "Error from daemon when getting the status")
c.PrintApiError(apiErr, "Error from cache when getting the status")
return base.CommandApiError
}
@@ -115,11 +115,11 @@ func (c *StatusCommand) Status(ctx context.Context) (*api.Response, *daemon.Stat
}
func status(ctx context.Context, daemonPath string, opt ...client.Option) (*api.Response, *daemon.StatusResult, *api.Error, error) {
const op = "daemon.status"
const op = "cache.status"
addr := daemon.SocketAddress(daemonPath)
_, err := os.Stat(addr.Path)
if addr.Scheme == "unix" && err != nil {
return nil, nil, nil, errDaemonNotRunning
return nil, nil, nil, errCacheNotRunning
}
c, err := client.New(ctx, addr)
if err != nil {
@@ -134,7 +134,7 @@ func status(ctx context.Context, daemonPath string, opt ...client.Option) (*api.
res := &daemon.StatusResult{}
apiErr, err := resp.Decode(&res)
if err != nil {
return nil, nil, nil, fmt.Errorf("Error when sending request to the daemon: %w.", err)
return nil, nil, nil, fmt.Errorf("Error when sending request to the cache: %w.", err)
}
if apiErr != nil {
return resp, nil, apiErr, nil
@@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package daemon
package cache
import (
"context"
@@ -17,16 +17,16 @@ type StopCommand struct {
}
func (c *StopCommand) Synopsis() string {
return "Stop a Boundary daemon"
return "Stop the Boundary cache"
}
func (c *StopCommand) Help() string {
helpText := `
Usage: boundary daemon stop
Usage: boundary cache stop
Stop a daemon:
Stop a cache:
$ boundary daemon stop
$ boundary cache stop
For a full list of examples, please see the documentation.
@@ -59,7 +59,7 @@ func (c *StopCommand) Run(args []string) int {
}
if err := c.stop(c.Context); err != nil {
if errors.Match(errors.T(errors.NotFound), err) {
c.PrintCliError(errDaemonNotRunning)
c.PrintCliError(errCacheNotRunning)
} else {
c.PrintCliError(err)
}
@@ -4,7 +4,7 @@
//go:build !windows
// +build !windows
package daemon
package cache
import (
"context"
@@ -16,7 +16,7 @@ import (
"github.com/hashicorp/boundary/internal/util"
)
// stop will send a term signal to the daemon to shut down.
// stop will send a term signal to the cache to shut down.
func (c *StopCommand) stop(ctx context.Context) error {
switch {
case util.IsNil(ctx):
@@ -30,13 +30,13 @@ func (c *StopCommand) stop(ctx context.Context) error {
pidPath := filepath.Join(dotPath, pidFileName)
p, err := pidFileInUse(ctx, pidPath)
if err != nil {
return fmt.Errorf("Error when checking if the daemon's pid file is in use: %w", err)
return fmt.Errorf("Error when checking if the cache's pid file is in use: %w", err)
}
if p == nil {
return errors.New("The daemon is not running.")
return errors.New("The cache is not running.")
}
if err := p.Signal(syscall.SIGTERM); err != nil {
return fmt.Errorf("Error when sending sigterm to daemon process: %w", err)
return fmt.Errorf("Error when sending sigterm to cache process: %w", err)
}
return nil
}
@@ -4,7 +4,7 @@
//go:build windows
// +build windows
package daemon
package cache
import (
"context"
@@ -19,7 +19,7 @@ import (
"github.com/hashicorp/boundary/internal/util"
)
// stop will send a term signal to the daemon to shut down.
// stop will send a term signal to the cache to shut down.
func (c *StopCommand) stop(ctx context.Context) error {
switch {
case util.IsNil(ctx):
@@ -40,7 +40,7 @@ func (c *StopCommand) stop(ctx context.Context) error {
} else if apiErr != nil {
errMsg = apiErr.Message
}
c.UI.Warn(fmt.Sprintf("Failed stopping the daemon through the handler: %q, now killing the process", errMsg))
c.UI.Warn(fmt.Sprintf("Failed stopping the cache through the handler: %q, now killing the process", errMsg))
default:
// there wasn't an error stopping it through the handler. No need to
// force kill the process
@@ -51,12 +51,12 @@ func (c *StopCommand) stop(ctx context.Context) error {
p, err := pidFileInUse(ctx, pidPath)
if err != nil {
if os.IsNotExist(err) {
return errors.New("Unable to stop the daemon: pid file not found.")
return errors.New("Unable to stop the cache: pid file not found.")
}
return fmt.Errorf("Error when trying to stop the daemon: %w", err)
return fmt.Errorf("Error when trying to stop the cache: %w", err)
}
if p == nil {
return errors.New("Daemon process was not found.")
return errors.New("Cache process was not found.")
}
if err := p.Kill(); err != nil {
@@ -73,7 +73,7 @@ func stopThroughHandler(ctx context.Context, dotPath string) (*api.Error, error)
}
resp, err := c.Post(ctx, "/v1/stop", nil)
if err != nil {
return nil, fmt.Errorf("Error when sending request to the daemon: %w.", err)
return nil, fmt.Errorf("Error when sending request to the cache: %w.", err)
}
apiErr, err := resp.Decode(nil)
return apiErr, err
@@ -1,7 +1,7 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package daemon
package cache
import (
"bytes"
@@ -53,12 +53,12 @@ func startDaemon(ctx context.Context, baseCmd *base.Command) bool {
cmdName, err := os.Executable()
if err != nil {
baseCmd.UI.Error(fmt.Sprintf("unable to find boundary binary for daemon startup: %s", err.Error()))
baseCmd.UI.Error(fmt.Sprintf("unable to find boundary binary for cache startup: %s", err.Error()))
return false
}
var stdErr bytes.Buffer
cmd := exec.Command(cmdName, "daemon", "start", "-background")
cmd := exec.Command(cmdName, "cache", "start", "-background")
cmd.Stderr = &stdErr
// We use Run here instead of Start because the command spawns off a subprocess and returns.
-57
View File
@@ -1,57 +0,0 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package daemon
import (
"strings"
"github.com/hashicorp/boundary/internal/cmd/base"
"github.com/mitchellh/cli"
"github.com/posener/complete"
)
var (
_ cli.Command = (*StartCommand)(nil)
_ cli.CommandAutocomplete = (*StartCommand)(nil)
)
type DaemonCommand struct {
*base.Command
}
func (c *DaemonCommand) Synopsis() string {
return "Manages the client side Boundary cache daemon"
}
func (c *DaemonCommand) Help() string {
helpText := `
Usage: boundary daemon [sub command] [options]
This command allows interacting with the Boundary daemon.
Start a daemon:
$ boundary daemon start
For a full list of examples, please see the documentation.
`
return strings.TrimSpace(helpText)
}
func (c *DaemonCommand) Flags() *base.FlagSets {
return c.FlagSet(base.FlagSetNone)
}
func (c *DaemonCommand) AutocompleteArgs() complete.Predictor {
return complete.PredictNothing
}
func (c *DaemonCommand) AutocompleteFlags() complete.Flags {
return c.Flags().Completions()
}
func (c *DaemonCommand) Run(args []string) int {
return cli.RunResultHelp
}
+8 -8
View File
@@ -16,7 +16,7 @@ import (
"github.com/hashicorp/boundary/api/aliases"
"github.com/hashicorp/boundary/api/sessions"
"github.com/hashicorp/boundary/api/targets"
daemoncmd "github.com/hashicorp/boundary/internal/clientcache/cmd/daemon"
cachecmd "github.com/hashicorp/boundary/internal/clientcache/cmd/cache"
"github.com/hashicorp/boundary/internal/clientcache/internal/client"
"github.com/hashicorp/boundary/internal/clientcache/internal/daemon"
"github.com/hashicorp/boundary/internal/cmd/base"
@@ -35,7 +35,7 @@ var (
"sessions",
}
errDaemonNotRunning = stderrors.New("The deamon process is not running.")
errCacheNotRunning = stderrors.New("The cache process is not running.")
)
type SearchCommand struct {
@@ -46,7 +46,7 @@ type SearchCommand struct {
}
func (c *SearchCommand) Synopsis() string {
return "Search Boundary resources using client side cache"
return "Search Boundary resources using client cache"
}
func (c *SearchCommand) Help() string {
@@ -154,7 +154,7 @@ func (c *SearchCommand) Run(args []string) int {
return base.CommandCliError
}
if apiErr != nil {
c.PrintApiError(apiErr, "Error from daemon when performing search")
c.PrintApiError(apiErr, "Error from cache when performing search")
return base.CommandApiError
}
@@ -204,7 +204,7 @@ func (c *SearchCommand) Search(ctx context.Context) (*api.Response, *daemon.Sear
opts = append(opts, client.WithOutputCurlString())
}
dotPath, err := daemoncmd.DefaultDotDirectory(ctx)
dotPath, err := cachecmd.DefaultDotDirectory(ctx)
if err != nil {
return nil, nil, nil, err
}
@@ -215,7 +215,7 @@ func search(ctx context.Context, daemonPath string, fb filterBy, opt ...client.O
addr := daemon.SocketAddress(daemonPath)
_, err := os.Stat(addr.Path)
if addr.Scheme == "unix" && err != nil {
return nil, nil, nil, errDaemonNotRunning
return nil, nil, nil, errCacheNotRunning
}
c, err := client.New(ctx, addr)
if err != nil {
@@ -232,12 +232,12 @@ func search(ctx context.Context, daemonPath string, fb filterBy, opt ...client.O
}
resp, err := c.Get(ctx, "/v1/search", q, opt...)
if err != nil {
return nil, nil, nil, fmt.Errorf("Error when sending request to the daemon: %w.", err)
return nil, nil, nil, fmt.Errorf("Error when sending request to the cache: %w.", err)
}
res := &daemon.SearchResult{}
apiErr, err := resp.Decode(&res)
if err != nil {
return nil, nil, nil, fmt.Errorf("Error when decoding request from the daemon: %w.", err)
return nil, nil, nil, fmt.Errorf("Error when decoding request from the cache: %w.", err)
}
if apiErr != nil {
return resp, nil, apiErr, nil
@@ -28,7 +28,7 @@ type RefreshTokenValue string
const sentinelNoRefreshToken RefreshTokenValue = "__no_refresh_token_supported__"
// CacheSupport is an enum that identifies if a boundary instance can be supported
// by the client daemon cache.
// by the client cache.
type CacheSupport string
const (
+1 -1
View File
@@ -189,7 +189,7 @@ type resourceSearcher interface {
// is returned and the returned SearchResults will be empty.
// search implements searcher.
func (l *resourceSearchFns[T]) search(ctx context.Context, p SearchParams) (*SearchResult, error) {
const op = "daemon.(resourceSearchFns).search"
const op = "cache.(resourceSearchFns).search"
var found []T
var err error
@@ -106,7 +106,7 @@ func (c *Client) Post(ctx context.Context, path string, body any, opt ...Option)
}
// request returns a retryablehttp.Request with the url set to the domain socket
// associated with this client and proper headers set for client daemon requests.
// associated with this client and proper headers set for client cache requests.
func request(ctx context.Context, method, path string) *retryablehttp.Request {
req := &http.Request{
Method: method,
+1 -1
View File
@@ -27,7 +27,7 @@ values
('target'),
('session');
-- Contains refresh tokens for list requests sent by the client daemon to the
-- Contains refresh tokens for list requests sent by the client cache to the
-- boundary instance.
create table if not exists refresh_token(
user_id text not null