-
Notifications
You must be signed in to change notification settings - Fork 186
/
cloud.go
65 lines (56 loc) 路 1.86 KB
/
cloud.go
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package cmd
import (
"fmt"
"os"
"github.com/google/uuid"
"github.com/odigos-io/odigos/cli/cmd/resources"
"github.com/odigos-io/odigos/cli/cmd/resources/odigospro"
"github.com/odigos-io/odigos/cli/pkg/kube"
"github.com/odigos-io/odigos/common"
"github.com/spf13/cobra"
)
func verifyOdigosCloudApiKey(apikey string) error {
_, err := uuid.Parse(apikey)
if err != nil {
return fmt.Errorf("invalid apikey format. expected uuid format")
}
return nil
}
// cloudCmd represents the cloud command
var cloudCmd = &cobra.Command{
Use: "cloud",
Short: "Manage odigos cloud",
Long: `Used to interact with odigos managed service.`,
Run: func(cmd *cobra.Command, args []string) {
client, err := kube.CreateClient(cmd)
if err != nil {
kube.PrintClientErrorAndExit(err)
}
ctx := cmd.Context()
ns, err := resources.GetOdigosNamespace(client, ctx)
if resources.IsErrNoOdigosNamespaceFound(err) {
fmt.Println("\033[31mERROR\033[0m no odigos installation found in the current cluster. use \"odigos install\" to install odigos in the cluster or check that kubeconfig is pointing to the correct cluster.")
os.Exit(1)
} else if err != nil {
fmt.Printf("\033[31mERROR\033[0m Failed to check if Odigos is already installed: %s\n", err)
os.Exit(1)
}
currentTier, err := odigospro.GetCurrentOdigosTier(ctx, client, ns)
if err != nil {
fmt.Println("Error reading current odigos tier")
os.Exit(1)
}
if currentTier == common.CloudOdigosTier {
fmt.Println("Odigos cloud is currently enabled")
} else if currentTier == common.CommunityOdigosTier {
fmt.Println(`You are using the community version of Odigos.
To enable odigos cloud run 'odigos cloud login'`)
} else {
fmt.Println(`You are using the on-prem enterprise version of Odigos.
Contact your Odigos representative to enable odigos cloud`)
}
},
}
func init() {
rootCmd.AddCommand(cloudCmd)
}