m/c/metroctl: accept multiple node IDs in approve
This makes possible to issue commands of the form
"metroctl approve [NodeID, ...]" instead of
"metroctl approve NodeID".
Change-Id: Ic5b4b3240aa0ff811aa3b52fb5f82b3966320dd9
Reviewed-on: https://review.monogon.dev/c/monogon/+/852
Reviewed-by: Sergiusz Bazanski <serge@monogon.tech>
Tested-by: Jenkins CI
diff --git a/metropolis/cli/metroctl/approve.go b/metropolis/cli/metroctl/approve.go
index f7aa049..9d685a1 100644
--- a/metropolis/cli/metroctl/approve.go
+++ b/metropolis/cli/metroctl/approve.go
@@ -57,19 +57,19 @@
log.Print("There are no nodes pending approval at this time.")
}
} else {
- // Otherwise, try to approve the node matching the id.
- tgtNodeId := args[0]
-
- n := nodeById(nodes, tgtNodeId)
- if n == nil {
- log.Fatalf("Couldn't find a new node matching id %s", tgtNodeId)
+ // Otherwise, try to approve the nodes matching the supplied ids.
+ for _, tgtNodeId := range args {
+ n := nodeById(nodes, tgtNodeId)
+ if n == nil {
+ log.Fatalf("Couldn't find a new node matching id %s", tgtNodeId)
+ }
+ _, err := mgmt.ApproveNode(ctx, &api.ApproveNodeRequest{
+ Pubkey: n.Pubkey,
+ })
+ if err != nil {
+ log.Fatalf("While approving node %s: %v", tgtNodeId, err)
+ }
+ log.Printf("Approved node %s.", tgtNodeId)
}
- _, err := mgmt.ApproveNode(ctx, &api.ApproveNodeRequest{
- Pubkey: n.Pubkey,
- })
- if err != nil {
- log.Fatalf("While approving node %s: %v", tgtNodeId, err)
- }
- log.Printf("Approved node %s.", tgtNodeId)
}
}