-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: extract cli connection params * feat: replications cli, misc. improvements * feat: add provider commands * feat: provider list, jq formattable output * feat: add dataset cmd * feat: fix issue incorrectly setting self service * feat: cleanup * feat: wallet list * feat: update docs, add wallet assoc cmd * feat: use http methods everywhere * feat: cleanup & refactor * feat: wip ptolemy doc --------- Co-authored-by: Jason Cihelka <jcihelka@isotechnics.com>
- Loading branch information
Showing
16 changed files
with
585 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package cmd | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/application-research/delta-dm/core" | ||
"github.com/application-research/delta-dm/util" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
func DatasetCmd() []*cli.Command { | ||
var datasetName string | ||
var replicationQuota uint64 | ||
var dealDuration uint64 | ||
|
||
// add a command to run API node | ||
var datasetCmds []*cli.Command | ||
datasetCmd := &cli.Command{ | ||
Name: "dataset", | ||
Usage: "Dataset Commands", | ||
Subcommands: []*cli.Command{ | ||
{ | ||
Name: "add", | ||
Usage: "add dataset", | ||
Flags: []cli.Flag{ | ||
&cli.StringFlag{ | ||
Name: "name", | ||
Aliases: []string{"n"}, | ||
Usage: "dataset name (slug)", | ||
Destination: &datasetName, | ||
Required: true, | ||
}, | ||
&cli.Uint64Flag{ | ||
Name: "replicaion-quota", | ||
Aliases: []string{"q"}, | ||
Usage: "replication quota - how many times the dataset may be replicated", | ||
DefaultText: "6", | ||
Value: 6, | ||
Destination: &replicationQuota, | ||
}, | ||
&cli.Uint64Flag{ | ||
Name: "duration", | ||
Aliases: []string{"d"}, | ||
Usage: "deal duration - how long (in days) should deals for this dataset last", | ||
DefaultText: "540", | ||
Value: 540, | ||
Destination: &dealDuration, | ||
}, | ||
}, | ||
Action: func(c *cli.Context) error { | ||
cmd, err := NewCmdProcessor(c) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !util.ValidateDatasetName(datasetName) { | ||
return fmt.Errorf("invalid dataset name. must contain only lowercase letters, numbers and hyphens. must begin and end with a letter. must not contain consecutive hyphens") | ||
} | ||
|
||
body := core.Dataset{ | ||
Name: datasetName, | ||
ReplicationQuota: replicationQuota, | ||
DealDuration: dealDuration, | ||
} | ||
|
||
b, err := json.Marshal(body) | ||
if err != nil { | ||
return fmt.Errorf("unable to construct request body %s", err) | ||
} | ||
|
||
res, closer, err := cmd.MakeRequest(http.MethodPost, "/api/v1/datasets", b) | ||
if err != nil { | ||
return fmt.Errorf("unable to make request %s", err) | ||
} | ||
defer closer() | ||
|
||
fmt.Printf("%s", string(res)) | ||
|
||
return nil | ||
}, | ||
}, | ||
{ | ||
Name: "list", | ||
Usage: "list datasets", | ||
Action: func(c *cli.Context) error { | ||
cmd, err := NewCmdProcessor(c) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
res, closer, err := cmd.MakeRequest(http.MethodGet, "/api/v1/datasets", nil) | ||
if err != nil { | ||
return fmt.Errorf("unable to make request %s", err) | ||
} | ||
defer closer() | ||
|
||
fmt.Printf("%s", string(res)) | ||
|
||
return nil | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
datasetCmds = append(datasetCmds, datasetCmd) | ||
|
||
return datasetCmds | ||
} |
Oops, something went wrong.