cmd/uplink: experimental environment variable to change piece hash algorithm

Change-Id: I7420919146c64d29ff1023f7498867d3d30892d0
This commit is contained in:
Márton Elek 2022-08-11 13:37:00 +02:00 committed by Elek, Márton
parent 98fb4c4f32
commit 1646a0ac9e

View File

@ -8,12 +8,15 @@ import (
"flag"
"fmt"
"os"
"strings"
"github.com/spacemonkeygo/monkit/v3"
"github.com/zeebo/clingy"
"storj.io/common/pb"
_ "storj.io/common/rpc/quic" // include quic connector
"storj.io/storj/cmd/uplink/ulext"
"storj.io/uplink/private/piecestore"
)
var mon = monkit.Package()
@ -21,12 +24,15 @@ var mon = monkit.Package()
func main() {
ex := newExternal()
raiseUlimits()
ctx := context.Background()
ctx = withPieceHashAlgorithm(ctx)
ok, err := clingy.Environment{
Name: "uplink",
Args: os.Args[1:],
Dynamic: ex.Dynamic,
Wrap: ex.Wrap,
}.Run(context.Background(), func(cmds clingy.Commands) {
}.Run(ctx, func(cmds clingy.Commands) {
ex.Setup(cmds) // setup ex first so that stdlib flags can consult config
newStdlibFlags(flag.CommandLine).Setup(cmds)
commands(cmds, ex)
@ -39,6 +45,22 @@ func main() {
}
}
func withPieceHashAlgorithm(ctx context.Context) context.Context {
customHashAlgo := os.Getenv("STORJ_PIECE_HASH_ALGORITHM_EXPERIMENTAL")
if customHashAlgo != "" {
var available []string
for value, name := range pb.PieceHashAlgorithm_name {
available = append(available, name)
if name == customHashAlgo {
return piecestore.WithPieceHashAlgo(ctx, pb.PieceHashAlgorithm(value))
}
}
panic("Piece hash algorithm is invalid. Available options: " + strings.Join(available, ","))
}
return ctx
}
func commands(cmds clingy.Commands, ex ulext.External) {
cmds.Group("access", "Access related commands", func() {
cmds.New("create", "Create an access from the satellite UI", newCmdAccessCreate(ex))