blob: a050e9b9e9f3cb70a530feed7445a04707894a87 [file] [log] [blame]
Mateusz Zalegad5f2f7a2022-07-05 18:48:56 +02001package main
2
3import (
4 "context"
Mateusz Zalegab2cac082022-07-14 14:55:43 +02005 "log"
Mateusz Zalegad5f2f7a2022-07-05 18:48:56 +02006
Mateusz Zalegad5f2f7a2022-07-05 18:48:56 +02007 "google.golang.org/grpc"
8
Mateusz Zalega18a67b02022-08-02 13:37:50 +02009 "source.monogon.dev/metropolis/cli/metroctl/core"
10 clicontext "source.monogon.dev/metropolis/cli/pkg/context"
Mateusz Zalegad5f2f7a2022-07-05 18:48:56 +020011)
12
Mateusz Zalega18a67b02022-08-02 13:37:50 +020013func dialAuthenticated() *grpc.ClientConn {
14 if len(flags.clusterEndpoints) == 0 {
15 log.Fatal("Please provide at least one cluster endpoint using the --endpoint parameter.")
Mateusz Zalegad5f2f7a2022-07-05 18:48:56 +020016 }
17
Mateusz Zalega18a67b02022-08-02 13:37:50 +020018 // Collect credentials, validate command parameters, and try dialing the
19 // cluster.
20 ocert, opkey, err := getCredentials()
21 if err == noCredentialsError {
22 log.Fatalf("You have to take ownership of the cluster first: %v", err)
Mateusz Zalegad5f2f7a2022-07-05 18:48:56 +020023 }
24
Mateusz Zalega18a67b02022-08-02 13:37:50 +020025 ctx := clicontext.WithInterrupt(context.Background())
26 cc, err := core.DialCluster(ctx, opkey, ocert, flags.proxyAddr, flags.clusterEndpoints, rpcLogger)
Mateusz Zalegad5f2f7a2022-07-05 18:48:56 +020027 if err != nil {
Mateusz Zalega18a67b02022-08-02 13:37:50 +020028 log.Fatalf("While dialing the cluster: %v", err)
Mateusz Zalegad5f2f7a2022-07-05 18:48:56 +020029 }
Mateusz Zalega18a67b02022-08-02 13:37:50 +020030 return cc
Mateusz Zalegad5f2f7a2022-07-05 18:48:56 +020031}