Skip to content

Commit

Permalink
feat: add new subcommand addS3PieceStorageCmd
Browse files Browse the repository at this point in the history
  • Loading branch information
LinZexiao committed Jun 23, 2022
1 parent faa1bee commit 0a1ce19
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions cli/piece-storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var PieceStorageCmd = &cli.Command{
Description: "The piece storage will decide where to store pieces and how to store them",
Subcommands: []*cli.Command{
addFsPieceStorageCmd,
addS3PieceStorageCmd,
PieceStorageListCmd,
PieceStorageRemoveCmd,
},
Expand Down Expand Up @@ -59,6 +60,77 @@ var addFsPieceStorageCmd = &cli.Command{
},
}

var addS3PieceStorageCmd = &cli.Command{
Name: "add-s3",
Usage: "add a object storage for piece storage",
Flags: []cli.Flag{
// read only
&cli.BoolFlag{
Name: "readonly",
Aliases: []string{"r"},
Usage: "set true if you want the piece storage only fro reading",
DefaultText: "false",
},
// Endpoint
&cli.StringFlag{
Name: "endpoint",
Aliases: []string{"e"},
Usage: "endpoint of the S3 bucket",
},
// access key
&cli.StringFlag{
Name: "access-key",
Aliases: []string{"a"},
Usage: "access key of the S3 bucket",
},
// secret key
&cli.StringFlag{
Name: "secret-key",
Aliases: []string{"s"},
Usage: "secret key of the S3 bucket",
},
// token
&cli.StringFlag{
Name: "token",
Aliases: []string{"t"},
Usage: "token of the S3 bucket",
},
},
Action: func(cctx *cli.Context) error {
nodeApi, closer, err := NewMarketNode(cctx)
if err != nil {
return err
}
defer closer()

ctx := ReqContext(cctx)

readOnly := cctx.Bool("readonly")
endpoint := cctx.String("endpoint")
accessKey := cctx.String("access-key")
secretKey := cctx.String("secret-key")
token := cctx.String("token")

if endpoint == "" {
return fmt.Errorf("endpoint are required")
}
if accessKey == "" {
return fmt.Errorf("access key are required")
}
if secretKey == "" {
return fmt.Errorf("secret key are required")
}

err = nodeApi.AddS3PieceStorage(ctx, readOnly, endpoint, accessKey, secretKey, token)
if err != nil {
return err
}
fmt.Println("Adding S3 piece storage:", endpoint)

return nil
},
}

var PieceStorageListCmd = &cli.Command{
Name: "list",
Usage: "list piece storages",
Expand Down

0 comments on commit 0a1ce19

Please sign in to comment.