You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
consul/command/intention/finder/finder.go

35 lines
682 B

package finder
import (
"fmt"
"github.com/hashicorp/consul/api"
)
// IDFromArgs returns the intention ID for the given CLI args. An error is returned
// if args is not 1 or 2 elements.
func IDFromArgs(client *api.Client, args []string) (string, error) {
switch len(args) {
case 1:
return args[0], nil
case 2:
ixn, _, err := client.Connect().IntentionGetExact(
args[0], args[1], nil,
)
if err != nil {
return "", err
}
if ixn == nil {
return "", fmt.Errorf(
"Intention with source %q and destination %q not found.",
args[0], args[1])
}
return ixn.ID, nil
default:
return "", fmt.Errorf("command requires exactly 1 or 2 arguments")
}
}