-
Notifications
You must be signed in to change notification settings - Fork 18
/
sos.go
89 lines (69 loc) · 1.84 KB
/
sos.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package cmd
import (
"fmt"
"os"
"strings"
"github.com/exoscale/cli/pkg/account"
minio "github.com/minio/minio-go/v6"
"github.com/spf13/cobra"
)
const (
minioMaxRetry = 2
)
var sosCmdLongHelp = func() string {
long := "Manage Exoscale Object Storage (SOS)"
return long
}
var sosCmd = &cobra.Command{
Use: "sos",
Short: "Simple Object Storage management",
Long: sosCmdLongHelp(),
TraverseChildren: true,
Hidden: true,
PersistentPreRun: func(_ *cobra.Command, _ []string) {
fmt.Fprintln(os.Stderr,
`**********************************************************************
The "exo sos" commands are deprecated and replaced by "exo storage",
they will be removed in a future version.
**********************************************************************`)
},
}
type sosClient struct {
*minio.Client
}
func newSOSClient() (*sosClient, error) {
var (
c sosClient
err error
)
z := account.CurrentAccount.DefaultZone
if err = c.setZone(z); err != nil {
return nil, err
}
_, ok := os.LookupEnv("EXOSCALE_TRACE")
if ok {
c.TraceOn(os.Stderr)
}
return &c, nil
}
func (s *sosClient) setZone(zone string) error {
// When a user wants to set the SOS zone to use for an operation, we actually have to re-create the
// underlying Minio S3 client to specify the zone-based endpoint.
endpoint := strings.TrimPrefix(
strings.Replace(account.CurrentAccount.SosEndpoint, "{zone}", zone, 1),
"https://")
minioClient, err := minio.NewV4(endpoint, account.CurrentAccount.Key, account.CurrentAccount.APISecret(), true)
if err != nil {
return err
}
minioClient.SetAppInfo("Exoscale-CLI", gVersion)
if _, ok := os.LookupEnv("EXOSCALE_TRACE"); ok {
minioClient.TraceOn(os.Stderr)
}
s.Client = minioClient
return nil
}
func init() {
minio.MaxRetry = minioMaxRetry
RootCmd.AddCommand(sosCmd)
}