Single Fetcher.Fetch on the Guard that holds DenyPrefixes. skipTlsVerification is ignored. No 502. keys add writes the secret only to --out. Release binary has no -test-allow-prefix.
76 lines
1.8 KiB
Go
76 lines
1.8 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
|
|
"git.wntrmute.dev/kyle/sift/internal/auth"
|
|
)
|
|
|
|
func keysMain() {
|
|
if len(os.Args) < 2 {
|
|
fmt.Fprintln(os.Stderr, "usage: sift keys add|list|revoke")
|
|
os.Exit(2)
|
|
}
|
|
sub := os.Args[1]
|
|
rest := os.Args[2:]
|
|
switch sub {
|
|
case "add":
|
|
keysAdd(rest)
|
|
case "list":
|
|
keysList(rest)
|
|
case "revoke":
|
|
keysRevoke(rest)
|
|
default:
|
|
fmt.Fprintf(os.Stderr, "sift keys: unknown %q\n", sub)
|
|
os.Exit(2)
|
|
}
|
|
}
|
|
|
|
func keysAdd(args []string) {
|
|
fs := flag.NewFlagSet("keys add", flag.ExitOnError)
|
|
caller := fs.String("caller", "", "caller name")
|
|
ws := fs.String("workspace", "hermes-fleet", "Honcho workspace")
|
|
keys := fs.String("keys", "/var/lib/sift/keys.toml", "keys.toml path")
|
|
out := fs.String("out", "", "write the secret key here (0600, must not exist)")
|
|
_ = fs.Parse(args)
|
|
if *caller == "" || *out == "" {
|
|
fmt.Fprintln(os.Stderr, "sift keys add --caller NAME --out FILE [--keys PATH] [--workspace WS]")
|
|
os.Exit(2)
|
|
}
|
|
if err := auth.Add(*keys, *caller, *ws, *out); err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func keysList(args []string) {
|
|
fs := flag.NewFlagSet("keys list", flag.ExitOnError)
|
|
keys := fs.String("keys", "/var/lib/sift/keys.toml", "keys.toml path")
|
|
_ = fs.Parse(args)
|
|
cs, err := auth.List(*keys)
|
|
if err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
for _, c := range cs {
|
|
fmt.Printf("%s\t%s\n", c.Name, c.Workspace)
|
|
}
|
|
}
|
|
|
|
func keysRevoke(args []string) {
|
|
fs := flag.NewFlagSet("keys revoke", flag.ExitOnError)
|
|
caller := fs.String("caller", "", "caller name")
|
|
keys := fs.String("keys", "/var/lib/sift/keys.toml", "keys.toml path")
|
|
_ = fs.Parse(args)
|
|
if *caller == "" {
|
|
fmt.Fprintln(os.Stderr, "sift keys revoke --caller NAME")
|
|
os.Exit(2)
|
|
}
|
|
if err := auth.Revoke(*keys, *caller); err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
}
|