From bfce01e7b2936c03ddcbf65eb9993b7da8c1fb0d Mon Sep 17 00:00:00 2001 From: mpl Date: Fri, 11 Nov 2016 00:50:46 +0100 Subject: [PATCH] cmd/camput: print share URL After successfully issueing a shared blob. Fixes #330 Change-Id: I51d4fa8434e8df471a29922bfdb5e9a7f22aec1a --- cmd/camput/share.go | 14 ++++++++++++-- pkg/client/client.go | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/cmd/camput/share.go b/cmd/camput/share.go index 931731923..373ed4816 100644 --- a/cmd/camput/share.go +++ b/cmd/camput/share.go @@ -87,7 +87,17 @@ func (c *shareCmd) RunCommand(args []string) error { unsigned.SetShareExpiration(time.Now().Add(c.duration)) } - pr, err := getUploader().UploadAndSignBlob(unsigned) - handleResult("share", pr, err) + up := getUploader() + shareRoot, err := up.ShareRoot() + if err != nil { + return err + } + + pr, err := up.UploadAndSignBlob(unsigned) + if err := handleResult("share", pr, err); err != nil { + // Because handling the failure is left to cmdmain + return nil + } + fmt.Fprintf(cmdmain.Stdout, "%s%s\n", shareRoot, pr.BlobRef) return nil } diff --git a/pkg/client/client.go b/pkg/client/client.go index 860563942..3519d73da 100644 --- a/pkg/client/client.go +++ b/pkg/client/client.go @@ -72,6 +72,7 @@ type Client struct { syncHandlers []*SyncInfo // "from" and "to" url prefix for each syncHandler serverKeyID string // Server's GPG public key ID. helpRoot string // Handler prefix, or "" if none + shareRoot string // Share handler prefix, or "" if none signerOnce sync.Once signer *schema.Signer @@ -401,6 +402,9 @@ var ErrNoSearchRoot = errors.New("client: server doesn't support search") // ErrNoHelpRoot is returned by HelpRoot if the server doesn't have a help handler. var ErrNoHelpRoot = errors.New("client: server does not have a help handler") +// ErrNoShareRoot is returned by ShareRoot if the server doesn't have a share handler. +var ErrNoShareRoot = errors.New("client: server does not have a share handler") + // ErrNoSigning is returned by ServerKeyID if the server doesn't support signing. var ErrNoSigning = fmt.Errorf("client: server doesn't support signing") @@ -462,6 +466,19 @@ func (c *Client) HelpRoot() (string, error) { return c.helpRoot, nil } +// ShareRoot returns the server's share handler prefix URL. +// If the server isn't running a share handler, the error will be +// ErrNoShareRoot. +func (c *Client) ShareRoot() (string, error) { + if err := c.condDiscovery(); err != nil { + return "", err + } + if c.shareRoot == "" { + return "", ErrNoShareRoot + } + return c.shareRoot, nil +} + // StorageGeneration returns the server's unique ID for its storage // generation, reset whenever storage is reset, moved, or partially // lost. @@ -820,6 +837,12 @@ func (c *Client) doDiscovery() error { } c.helpRoot = u.String() + u, err = root.Parse(disco.ShareRoot) + if err != nil { + return fmt.Errorf("client: invalid shareRoot %q; failed to resolve", disco.ShareRoot) + } + c.shareRoot = u.String() + c.storageGen = disco.StorageGeneration u, err = root.Parse(disco.BlobRoot)