diff --git a/CHANGELOG.md b/CHANGELOG.md index 82c16c3..0a45a8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,12 @@ Version History Latest: +## Sep 4, 2020: +### v2.0.0 +**Key Updates** +- Updated to use v2 of the API. +- Added `version` command. + ## Aug 13, 2020: ### v1.1.0 **Key Updates** @@ -20,5 +26,4 @@ Latest: ## Jun 16, 2020: ### v1.0.0 **Key Updates** -- Created skynet cli - +- Created skynet cli with upload and download. diff --git a/cmd/skynet/main.go b/cmd/skynet/main.go index 983074b..cc590b5 100644 --- a/cmd/skynet/main.go +++ b/cmd/skynet/main.go @@ -26,7 +26,7 @@ built on top of Sia.` mainDocFile = "./doc/skynet.md" // version is the current version of skynet-cli. - version = "1.1.0" + version = "2.0.0" ) // Exit codes. diff --git a/cmd/skynet/skynetcmd.go b/cmd/skynet/skynetcmd.go index ce1d835..8935508 100644 --- a/cmd/skynet/skynetcmd.go +++ b/cmd/skynet/skynetcmd.go @@ -4,7 +4,7 @@ import ( "fmt" "os" - "github.com/NebulousLabs/go-skynet" + "github.com/NebulousLabs/go-skynet/v2" "github.com/spf13/cobra" "gitlab.com/NebulousLabs/errors" ) @@ -89,7 +89,7 @@ func skynetcmd() { fmt.Printf("%s\n\n", binDescription) // Get Default Portal - fmt.Printf("Default Skynet Portal: %v\n", skynet.DefaultPortalURL) + fmt.Printf("Default Skynet Portal: %v\n", skynet.DefaultPortalURL()) } // skynetaddskykey stores the given base-64 encoded skykey with the skykey @@ -97,9 +97,10 @@ func skynetcmd() { func skynetaddskykeycmd(skykey string) { // Get the addskykey options. opts := skynet.DefaultAddSkykeyOptions - opts.Options = getCommonOptions(opts.Options) + client, commonOpts := initClientAndOptions() + opts.Options = commonOpts - err := skynet.AddSkykey(skykey, opts) + err := client.AddSkykey(skykey, opts) if err != nil { err = errors.AddContext(err, fmt.Sprintf("AddSkykey Options: %+v\n", opts)) die("Unable to add skykey:", err) @@ -111,9 +112,10 @@ func skynetaddskykeycmd(skykey string) { func skynetcreateskykeycmd(name, skykeyType string) { // Get the createskykey options. opts := skynet.DefaultCreateSkykeyOptions - opts.Options = getCommonOptions(opts.Options) + client, commonOpts := initClientAndOptions() + opts.Options = commonOpts - skykey, err := skynet.CreateSkykey(name, skykeyType, opts) + skykey, err := client.CreateSkykey(name, skykeyType, opts) if err != nil { err = errors.AddContext(err, fmt.Sprintf("CreateSkykey Options: %+v\n", opts)) die("Unable to create skykey:", err) @@ -124,9 +126,10 @@ func skynetcreateskykeycmd(name, skykeyType string) { func skynetgetskykeyidcmd(id string) { // Get the getskykeyid options. opts := skynet.DefaultGetSkykeyOptions - opts.Options = getCommonOptions(opts.Options) + client, commonOpts := initClientAndOptions() + opts.Options = commonOpts - skykey, err := skynet.GetSkykeyByID(id, opts) + skykey, err := client.GetSkykeyByID(id, opts) if err != nil { err = errors.AddContext(err, fmt.Sprintf("GetSkykey Options: %+v\n", opts)) die("Unable to get skykey by id:", err) @@ -137,9 +140,10 @@ func skynetgetskykeyidcmd(id string) { func skynetgetskykeynamecmd(name string) { // Get the getskykeyname options. opts := skynet.DefaultGetSkykeyOptions - opts.Options = getCommonOptions(opts.Options) + client, commonOpts := initClientAndOptions() + opts.Options = commonOpts - skykey, err := skynet.GetSkykeyByName(name, opts) + skykey, err := client.GetSkykeyByName(name, opts) if err != nil { err = errors.AddContext(err, fmt.Sprintf("GetSkykey Options: %+v\n", opts)) die("Unable to get skykey by name:", err) @@ -151,9 +155,10 @@ func skynetgetskykeynamecmd(name string) { func skynetgetskykeyscmd() { // Get the getskykeys options. opts := skynet.DefaultGetSkykeysOptions - opts.Options = getCommonOptions(opts.Options) + client, commonOpts := initClientAndOptions() + opts.Options = commonOpts - skykeys, err := skynet.GetSkykeys(opts) + skykeys, err := client.GetSkykeys(opts) if err != nil { err = errors.AddContext(err, fmt.Sprintf("GetSkykeys Options: %+v\n", opts)) die("Unable to get skykeys:", err) @@ -174,7 +179,8 @@ func skynetdownloadcmd(cmd *cobra.Command, args []string) { // Get the download options. opts := skynet.DefaultDownloadOptions - opts.Options = getCommonOptions(opts.Options) + client, commonOpts := initClientAndOptions() + opts.Options = commonOpts if downloadSkykeyName != "" { opts.SkykeyName = downloadSkykeyName } @@ -183,7 +189,7 @@ func skynetdownloadcmd(cmd *cobra.Command, args []string) { } // Download Skylink - err := skynet.DownloadFile(filename, skylink, opts) + err := client.DownloadFile(filename, skylink, opts) if err != nil { err = errors.AddContext(err, fmt.Sprintf("Download Options: %+v\n", opts)) die("Unable to download skylink:", err) @@ -196,7 +202,8 @@ func skynetdownloadcmd(cmd *cobra.Command, args []string) { func skynetuploadcmd(sourcePath string) { // Get the upload options. opts := skynet.DefaultUploadOptions - opts.Options = getCommonOptions(opts.Options) + client, commonOpts := initClientAndOptions() + opts.Options = commonOpts if portalFileFieldName != "" { opts.PortalFileFieldName = portalFileFieldName } @@ -216,7 +223,7 @@ func skynetuploadcmd(sourcePath string) { opts.SkykeyID = uploadSkykeyID } - skylink, uploadType, err := upload(sourcePath, opts) + skylink, uploadType, err := upload(sourcePath, client, opts) if err != nil { err = errors.AddContext(err, fmt.Sprintf("Upload Options: %+v\n", opts)) die(fmt.Sprintf("Unable to upload %v: %v\n", uploadType, err)) @@ -226,7 +233,7 @@ func skynetuploadcmd(sourcePath string) { } // upload uploads the given path. -func upload(sourcePath string, opts skynet.UploadOptions) (skylink string, uploadType string, err error) { +func upload(sourcePath string, client skynet.SkynetClient, opts skynet.UploadOptions) (skylink string, uploadType string, err error) { // Open the source file. file, err := os.Open(sourcePath) if err != nil { @@ -242,7 +249,7 @@ func upload(sourcePath string, opts skynet.UploadOptions) (skylink string, uploa // Upload File if !fi.IsDir() { - skylink, err = skynet.UploadFile(sourcePath, opts) + skylink, err = client.UploadFile(sourcePath, opts) if err != nil { return "", "file", errors.AddContext(err, "Unable to upload file") } @@ -250,19 +257,18 @@ func upload(sourcePath string, opts skynet.UploadOptions) (skylink string, uploa } // Upload directory - skylink, err = skynet.UploadDirectory(sourcePath, opts) + skylink, err = client.UploadDirectory(sourcePath, opts) if err != nil { return "", "directory", errors.AddContext(err, "Unable to upload directory") } return skylink, "directory", nil } -// getCommonOptions gets options from the persistent root flags that are common -// to all commands. -func getCommonOptions(opts skynet.Options) skynet.Options { - if skynetPortal != "" { - opts.PortalURL = skynetPortal - } +// initClientAndOptions initializes a client and common options from the +// persistent root flags that are common to all commands. Any available options +// in `opts` will be used if the option is not overridden with a root flag. +func initClientAndOptions() (skynet.SkynetClient, skynet.Options) { + opts := skynet.Options{} if endpointPath != "" { opts.EndpointPath = endpointPath } @@ -272,5 +278,8 @@ func getCommonOptions(opts skynet.Options) skynet.Options { if customUserAgent != "" { opts.CustomUserAgent = customUserAgent } - return opts + // Create a client with specified portal (or "" if not specified) default + // options. Custom options will be passed into the API call itself. + client := skynet.NewCustom(skynetPortal, skynet.Options{}) + return client, opts } diff --git a/go.mod b/go.mod index 0fa82c7..427b1fb 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,9 @@ module github.com/NebulousLabs/skynet-cli go 1.13 require ( - github.com/NebulousLabs/go-skynet v0.0.0-20200805105931-985c5804db66 + github.com/NebulousLabs/go-skynet/v2 v2.0.0 github.com/spf13/cobra v1.0.0 github.com/spf13/pflag v1.0.5 // indirect gitlab.com/NebulousLabs/errors v0.0.0-20171229012116-7ead97ef90b8 - golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect gopkg.in/yaml.v2 v2.3.0 // indirect ) diff --git a/go.sum b/go.sum index 241dc32..938ef63 100644 --- a/go.sum +++ b/go.sum @@ -1,11 +1,7 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= -github.com/NebulousLabs/go-skynet v0.0.0-20200615123241-9b30d4ffd492 h1:KPJHmIBb5szkxU4acjpLVFQxPIU/vfjhghAYxEixuNU= -github.com/NebulousLabs/go-skynet v0.0.0-20200615123241-9b30d4ffd492/go.mod h1:uOpyXOndZfQYn/hIdGgR0DJCK2I4uz+NNmXtxlaCUyg= -github.com/NebulousLabs/go-skynet v0.0.0-20200721163935-c56e138c1a03 h1:E+UMrK7thvS73wxDhTgE35fxN0hSCT6KBI2vWao4zj8= -github.com/NebulousLabs/go-skynet v0.0.0-20200721163935-c56e138c1a03/go.mod h1:6vr7Kb2aMpGrAuLmZ2LOtuqLusO1ISRglRXDv+vkmdI= -github.com/NebulousLabs/go-skynet v0.0.0-20200805105931-985c5804db66 h1:dboQMHW8YhTQcsjnBB/s4ZPXk/O1Jf8R6O9BaStll2o= -github.com/NebulousLabs/go-skynet v0.0.0-20200805105931-985c5804db66/go.mod h1:6vr7Kb2aMpGrAuLmZ2LOtuqLusO1ISRglRXDv+vkmdI= +github.com/NebulousLabs/go-skynet/v2 v2.0.0 h1:hPgml8Qc5RalldibBZ9p66Oggoud45OIZZnut9pWNUo= +github.com/NebulousLabs/go-skynet/v2 v2.0.0/go.mod h1:uhGD1M7Qe1nXsnqRD90B5CJVgjqSqwJUmDosgAn4CdQ= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= @@ -120,32 +116,24 @@ go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/ go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 h1:XQyxROzUlZH+WIQwySDgnISgOivlhjIEwaQaJEJrrN0= golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7YapZaRvUcLFFJhusH0k= -golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -153,9 +141,6 @@ golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190311212946-11955173bddd h1:/e+gpKk9r3dJobndpTytxS2gOy6m5uvpg+ISQoEcusQ= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7 h1:EBZoQjiKKPaLbPrbpssUfuHtwM6KV/vb4U85g/cigFY= -golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=