blob: 512f5f0595719f810c52e05bd00a8fad47f92631 (
plain) (
blame)
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
|
package main
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
var (
clientID = ""
clientSecret = ""
)
var rootCmd = &cobra.Command{
Use: "colabctl",
}
func main() {
if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func init() {
// Allow credentials to be provided via environment variables as a
// convenient alternative to build-time injection.
if id := os.Getenv("COLAB_CLIENT_ID"); id != "" {
clientID = id
}
if secret := os.Getenv("COLAB_CLIENT_SECRET"); secret != "" {
clientSecret = secret
}
}
// requireCredentials prints a helpful error and exits if the OAuth2 client
// credentials have not been configured.
func requireCredentials() {
if clientID == "" || clientSecret == "" {
fmt.Fprintln(os.Stderr, `Error: OAuth2 credentials not set.
Set COLAB_CLIENT_ID and COLAB_CLIENT_SECRET environment variables, or run:
colabctl auth login --client-id <id> --client-secret <secret>
To create credentials, visit:
https://console.cloud.google.com/apis/credentials`)
os.Exit(1)
}
}
|