-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlock.go
More file actions
56 lines (48 loc) · 1.6 KB
/
Copy pathlock.go
File metadata and controls
56 lines (48 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package cmd
import (
"errors"
"fmt"
"github.com/spf13/cobra"
"github.com/arimxyer/pass-cli/internal/agent"
)
// runLock is shared by the top-level `pass-cli lock` and `pass-cli agent lock`.
func runLock(cmd *cobra.Command, _ []string) error {
if err := agent.LockAgent(); err != nil {
if errors.Is(err, agent.ErrNoAgent) {
// Nothing to lock is not a failure — a one-shot command already locks the
// vault when it exits.
_, _ = fmt.Fprintln(cmd.OutOrStdout(), "no agent is running (nothing to lock)")
return nil
}
return err
}
_, _ = fmt.Fprintln(cmd.OutOrStdout(), "agent locked and stopped")
return nil
}
const lockLong = `Lock zeroes the secrets held by a running agent and stops it, freeing the
socket. Subsequent commands fall back to opening the vault directly (with a
prompt); to re-establish the agent, run 'pass-cli agent' again. If no agent is
running there is nothing to lock (a one-shot command already locks the vault
when it exits).`
// lockCmd is the top-level shortcut: `pass-cli lock`.
var lockCmd = &cobra.Command{
Use: "lock",
GroupID: "vault",
Short: "Lock the running agent (zero its secrets and stop it)",
Long: lockLong,
Args: cobra.NoArgs,
RunE: runLock,
}
// agentLockCmd is the same action under `agent`, where it sits next to
// `agent stop` and `agent status` — the first place people look for it.
var agentLockCmd = &cobra.Command{
Use: "lock",
Short: "Lock the running agent (zero its secrets and stop it)",
Long: lockLong,
Args: cobra.NoArgs,
RunE: runLock,
}
func init() {
rootCmd.AddCommand(lockCmd)
agentCmd.AddCommand(agentLockCmd)
}