-
Notifications
You must be signed in to change notification settings - Fork 24
/
cluster_locked.go
63 lines (54 loc) · 1.59 KB
/
cluster_locked.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
package cmd
import (
"context"
"fmt"
"github.com/qovery/qovery-cli/utils"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"io"
"net/http"
"os"
"strconv"
"text/tabwriter"
"time"
)
var clusterLockedCmd = &cobra.Command{
Use: "locked",
Short: "List locked clusters",
Run: func(cmd *cobra.Command, args []string) {
clusterLocked()
},
}
func init() {
clusterLockedCmd.Flags().StringVarP(&organizationId, "organization-id", "o", "", "Organization ID")
_ = clusterLockedCmd.MarkFlagRequired("organization-id")
clusterCmd.AddCommand(clusterLockedCmd)
}
func clusterLocked() {
tokenType, token, err := utils.GetAccessToken()
if err != nil {
utils.PrintlnError(err)
os.Exit(1)
}
client := utils.GetQoveryClient(tokenType, token)
lockedClusters, res, err := client.OrganizationClusterLockAPI.ListClusterLock(context.Background(), organizationId).Execute()
if res != nil && res.StatusCode != http.StatusOK {
result, _ := io.ReadAll(res.Body)
log.Errorf("Could not list locked clusters : %s. %s", res.Status, string(result))
return
}
if err != nil {
log.Fatal(err)
}
w := tabwriter.NewWriter(os.Stdout, 1, 1, 1, ' ', 0)
format := "%s\t | %s\t | %s\t | %s\t | %s\t | %s\n"
fmt.Fprintf(w, format, "", "cluster_id", "locked_at", "ttl_in_days", "locked_by", "reason")
for idx, lock := range lockedClusters.Results {
ttlInDays := "infinite"
if lock.TtlInDays != nil {
ttlInDays = strconv.Itoa(int(*lock.TtlInDays))
}
fmt.Fprintf(w, format, fmt.Sprintf("%d", idx+1), lock.ClusterId, lock.LockedAt.Format(time.RFC1123), ttlInDays, lock.OwnerName, lock.Reason)
}
w.Flush()
}