Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ $ dbxcli share-link info <url> --path /nested/file.txt # display information for
$ dbxcli share-link list # list existing shared links
$ dbxcli share-link list /file.txt # list direct shared links for a path
$ dbxcli share-link revoke <url> # revoke a shared link
$ dbxcli share-link revoke --path /file.txt # revoke direct shared links for a path
$ dbxcli share-link update <url> --allow-download # update shared link settings
$ dbxcli share-link update <url> --disallow-download # disable downloads from a shared link
$ dbxcli share-link update <url> --audience public # update shared link audience
Expand All @@ -258,6 +259,8 @@ $ dbxcli share list folder # list shared folders

`share-link create --audience` and `share-link update --audience` support `public`, `team`, `members`, and `no-one`. Dropbox team and folder policies can still resolve the effective audience differently.

Dropbox account, team, and folder policies can reject shared-link settings such as passwords, expiration, audience, or disabled downloads. In that case, dbxcli returns the Dropbox API error, for example `settings_error/not_authorized/`.

`share-link create`, `share-link update`, `share-link info`, and `share-link download` support `--password <value>`, `--password-prompt`, and `--password-file <path>` for password-protected links. Use `--password-prompt` for interactive use so the password is not echoed.

`share-link download` writes to the metadata filename when `target` is omitted. Use `-` as the target to write file bytes to stdout. Folder shared links require `--recursive` and cannot be written to stdout.
Expand Down
82 changes: 79 additions & 3 deletions cmd/share_link_revoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,26 @@ package cmd

import (
"errors"
"fmt"

"github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox/sharing"
"github.com/spf13/cobra"
)

type shareLinkRevokeOptions struct {
path string
}

func shareLinkRevoke(cmd *cobra.Command, args []string) error {
opts, err := parseShareLinkRevokeOptions(cmd, args)
if err != nil {
return err
}

if opts.path != "" {
return revokeSharedLinksForPath(cmd, opts.path)
}

if len(args) != 1 {
return errors.New("`share-link revoke` requires a `url` argument")
}
Expand All @@ -41,12 +55,74 @@ func shareLinkRevoke(cmd *cobra.Command, args []string) error {
return nil
}

func parseShareLinkRevokeOptions(cmd *cobra.Command, args []string) (shareLinkRevokeOptions, error) {
var opts shareLinkRevokeOptions

if !localFlagChanged(cmd, "path") {
return opts, nil
}
if len(args) != 0 {
return opts, errors.New("`--path` cannot be used with a shared link URL")
}

pathArg, err := localStringFlag(cmd, "path")
if err != nil {
return opts, err
}
if pathArg == "" {
return opts, errors.New("`--path` requires a non-empty path")
}

path, err := validatePath(pathArg)
if err != nil {
return opts, err
}
if path == "" {
return opts, errors.New("cannot revoke shared links for Dropbox root")
}

opts.path = path
return opts, nil
}

func revokeSharedLinksForPath(cmd *cobra.Command, path string) error {
arg := sharing.NewListSharedLinksArg()
arg.Path = path
arg.DirectOnly = true

dbx := newSharedLinkClient(config)
links, err := listSharedLinks(dbx, arg)
if err != nil {
return err
}
if len(links) == 0 {
return fmt.Errorf("no direct shared links found for %q", path)
}

for _, link := range links {
url, ok := sharedLinkURL(link)
if !ok {
return errors.New("shared link response did not include a URL")
}
if err := dbx.RevokeSharedLink(sharing.NewRevokeSharedLinkArg(url)); err != nil {
return fmt.Errorf("revoke shared link %s: %w", url, err)
}
}

commandVerboseStatus(cmd, "Revoked %d shared links for %s", len(links), path)
return nil
}

var shareLinkRevokeCmd = &cobra.Command{
Use: "revoke <url>",
Short: "Revoke a shared link",
RunE: shareLinkRevoke,
Use: "revoke [url]",
Short: "Revoke shared links",
Long: "Revoke a shared link by URL, or revoke all direct shared links for a Dropbox path with --path.",
Example: ` dbxcli share-link revoke https://www.dropbox.com/s/example/file.txt
dbxcli share-link revoke --path /file.txt`,
RunE: shareLinkRevoke,
}

func init() {
shareLinkRevokeCmd.Flags().String("path", "", "Revoke direct shared links for a Dropbox path")
shareLinkCmd.AddCommand(shareLinkRevokeCmd)
}
Loading