cmd/swarm: Make encrypted upload a flag instead of a command

This commit is contained in:
Balint Gabor 2018-04-12 14:44:15 +02:00
parent f0dc791adf
commit a0ae2a37dd
3 changed files with 20 additions and 24 deletions

View file

@ -141,6 +141,10 @@ var (
Name: "mime",
Usage: "force mime type",
}
SwarmEncryptedFlag = cli.BoolFlag{
Name: "encrypted",
Usage: "use encrypted upload",
}
SwarmPssEnabledFlag = cli.BoolFlag{
Name: "pss",
Usage: "Enable pss (message passing over swarm)",
@ -218,19 +222,11 @@ The output of this command is supposed to be machine-readable.
`,
},
{
Action: nonEncryptedUpload,
Action: upload,
Name: "up",
Usage: "upload a file or directory to swarm using the HTTP API",
ArgsUsage: " <file>",
Description: `
"upload a file or directory to swarm using the HTTP API and prints the root hash",
`,
},
{
Action: encryptedUpload,
Name: "encrypted-up",
Usage: "Upload a file or directory with encryption to swarm using the HTTP API. NOTE: Currently the reference for the uploaded content is non-deterministic, so you will receive different references if you upload it twice.",
ArgsUsage: " <file>",
Flags: []cli.Flag{SwarmEncryptedFlag},
Description: `
"upload a file or directory to swarm using the HTTP API and prints the root hash",
`,

View file

@ -35,15 +35,7 @@ import (
"gopkg.in/urfave/cli.v1"
)
func encryptedUpload(ctx *cli.Context) {
upload(ctx, true)
}
func nonEncryptedUpload(ctx *cli.Context) {
upload(ctx, false)
}
func upload(ctx *cli.Context, toEncrypt bool) {
func upload(ctx *cli.Context) {
args := ctx.Args()
var (
@ -54,6 +46,7 @@ func upload(ctx *cli.Context, toEncrypt bool) {
fromStdin = ctx.GlobalBool(SwarmUpFromStdinFlag.Name)
mimeType = ctx.GlobalString(SwarmUploadMimeType.Name)
client = swarm.NewClient(bzzapi)
toEncrypt = ctx.Bool(SwarmEncryptedFlag.Name)
file string
)

View file

@ -59,15 +59,22 @@ func testCLISwarmUp(toEncrypt bool, t *testing.T) {
t.Fatal(err)
}
cmd := "up"
hashRegexp := `[a-f\d]{64}`
flags := []string{
"--bzzapi", cluster.Nodes[0].URL,
"up",
tmp.Name()}
if toEncrypt {
cmd = "encrypted-up"
hashRegexp = `[a-f\d]{128}`
flags = []string{
"--bzzapi", cluster.Nodes[0].URL,
"up",
"--encrypted",
tmp.Name()}
}
// upload the file with 'swarm up' or 'swarm encrypted-up' and expect a hash
log.Info(fmt.Sprintf("uploading file with '%s'", cmd))
up := runSwarm(t, "--bzzapi", cluster.Nodes[0].URL, cmd, tmp.Name())
// upload the file with 'swarm up' and expect a hash
log.Info(fmt.Sprintf("uploading file with 'swarm up'"))
up := runSwarm(t, flags...)
_, matches := up.ExpectRegexp(hashRegexp)
up.ExpectExit()
hash := matches[0]