forked from irinazheltisheva/powergate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathffs_config_set_default.go
More file actions
69 lines (58 loc) · 1.48 KB
/
ffs_config_set_default.go
File metadata and controls
69 lines (58 loc) · 1.48 KB
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
package cmd
import (
"bytes"
"context"
"encoding/json"
"io"
"os"
"time"
"github.com/caarlos0/spin"
logging "github.com/ipfs/go-log/v2"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/textileio/powergate/ffs"
)
var (
log = logging.Logger("cmd")
)
func init() {
ffsConfigSetCmd.Flags().StringP("token", "t", "", "FFS auth token")
ffsConfigCmd.AddCommand(ffsConfigSetCmd)
}
var ffsConfigSetCmd = &cobra.Command{
Use: "set-default [(optional)file]",
Short: "Sets the default cid storage config from stdin or a file",
Long: `Sets the default cid storage config from stdin or a file`,
PreRun: func(cmd *cobra.Command, args []string) {
err := viper.BindPFlags(cmd.Flags())
checkErr(err)
},
Run: func(cmd *cobra.Command, args []string) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*60)
defer cancel()
var reader io.Reader
if len(args) > 0 {
file, err := os.Open(args[0])
defer func() {
if err := file.Close(); err != nil {
log.Errorf("closing config file: %s", err)
}
}()
reader = file
checkErr(err)
} else {
reader = cmd.InOrStdin()
}
buf := new(bytes.Buffer)
_, err := buf.ReadFrom(reader)
checkErr(err)
config := ffs.StorageConfig{}
checkErr(json.Unmarshal(buf.Bytes(), &config))
s := spin.New("%s Setting default storage config...")
s.Start()
err = fcClient.FFS.SetDefaultStorageConfig(authCtx(ctx), config)
s.Stop()
checkErr(err)
Success("Default storage config updated")
},
}