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 .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
paths:
- README.md

permissions:
contents: read

jobs:
deploy:
runs-on: ubuntu-latest
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
tags:
- "v*"

permissions:
contents: read

jobs:
release:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions cmd/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func account(cmd *cobra.Command, args []string) error {

if len(args) == 0 {
// If no arguments are provided get the current user's account
res, err := dbx.GetCurrentAccount()
res, err := dbx.GetCurrentAccountContext(currentContext())
if err != nil {
return err
}
Expand All @@ -161,7 +161,7 @@ func account(cmd *cobra.Command, args []string) error {

// Otherwise look up an account with the provided ID
arg := users.NewGetAccountArg(args[0])
res, err := dbx.GetAccount(arg)
res, err := dbx.GetAccountContext(currentContext(), arg)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/add-member.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func addMember(cmd *cobra.Command, args []string) (err error) {
member.MemberGivenName = firstName
member.MemberSurname = lastName
arg := team.NewMembersAddArg([]*team.MemberAddArg{member})
res, err := dbx.MembersAdd(arg)
res, err := dbx.MembersAddContext(currentContext(), arg)
if err != nil {
return withJSONErrorDetails(err, operationErrorDetails("team_add_member"), emailErrorDetails(email))
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func requestAccessCredential(tokType string, domain string) (storedCredential, e
if err != nil {
return storedCredential{}, err
}
token, err := exchangeAuthorizationCode(context.Background(), conf, code, verifier)
token, err := exchangeAuthorizationCode(currentContext(), conf, code, verifier)
if err != nil {
return storedCredential{}, authExchangeFailedErrorfWithDetails("exchange authorization code: %w", map[string]any{
"token_type": authTokenTypeName(tokType),
Expand Down Expand Up @@ -407,7 +407,7 @@ func refreshStoredCredential(tokType string, domain string, credential storedCre
})
}

token, err := refreshOAuthToken(context.Background(), oauthConfigWithAppKey(appKey, domain), credential.oauthToken())
token, err := refreshOAuthToken(currentContext(), oauthConfigWithAppKey(appKey, domain), credential.oauthToken())
if err != nil {
return storedCredential{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cp.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func cp(cmd *cobra.Command, args []string) error {
}

for _, arg := range relocationArgs {
res, err := dbx.CopyV2(arg)
res, err := dbx.CopyV2Context(currentContext(), arg)
if err != nil {
if result, skipped := relocationSkipAfterDestinationConflict(dbx, arg, err, opts); skipped {
if collectResults {
Expand Down
4 changes: 2 additions & 2 deletions cmd/cp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import (
"github.com/spf13/cobra"
)

func stubFilesClient(t *testing.T, client files.Client) {
func stubFilesClient(t *testing.T, client filesClient) {
t.Helper()

origNew := filesNewFunc
filesNewFunc = func(_ dropbox.Config) files.Client { return client }
filesNewFunc = func(_ dropbox.Config) filesClient { return client }
t.Cleanup(func() { filesNewFunc = origNew })
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/dropbox_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ func relocationDestination(source, destination string, destinationIsFolder bool)
return destination
}

func isRemoteFolder(dbx files.Client, dst string) bool {
func isRemoteFolder(dbx filesClient, dst string) bool {
p, err := validatePath(dst)
if err != nil {
return false
}
meta, err := dbx.GetMetadata(files.NewGetMetadataArg(p))
meta, err := dbx.GetMetadataContext(currentContext(), files.NewGetMetadataArg(p))
if err != nil {
return false
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/du.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const (

func du(cmd *cobra.Command, args []string) (err error) {
dbx := usersNewFunc(config)
usage, err := dbx.GetSpaceUsage()
usage, err := dbx.GetSpaceUsageContext(currentContext())
if err != nil {
return
}
Expand Down
33 changes: 33 additions & 0 deletions cmd/files_client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package cmd

import (
"context"
"io"

"github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox"
"github.com/dropbox/dropbox-sdk-go-unofficial/v6/dropbox/files"
)

type filesClient interface {
CopyV2Context(context.Context, *files.RelocationArg) (*files.RelocationResult, error)
CreateFolderV2Context(context.Context, *files.CreateFolderArg) (*files.CreateFolderResult, error)
DeleteV2Context(context.Context, *files.DeleteArg) (*files.DeleteResult, error)
DownloadContext(context.Context, *files.DownloadArg) (*files.FileMetadata, io.ReadCloser, error)
GetMetadataContext(context.Context, *files.GetMetadataArg) (files.IsMetadata, error)
ListFolderContext(context.Context, *files.ListFolderArg) (*files.ListFolderResult, error)
ListFolderContinueContext(context.Context, *files.ListFolderContinueArg) (*files.ListFolderResult, error)
ListRevisionsContext(context.Context, *files.ListRevisionsArg) (*files.ListRevisionsResult, error)
MoveV2Context(context.Context, *files.RelocationArg) (*files.RelocationResult, error)
PermanentlyDeleteContext(context.Context, *files.DeleteArg) error
RestoreContext(context.Context, *files.RestoreArg) (*files.FileMetadata, error)
SearchV2Context(context.Context, *files.SearchV2Arg) (*files.SearchV2Result, error)
SearchContinueV2Context(context.Context, *files.SearchV2ContinueArg) (*files.SearchV2Result, error)
UploadContext(context.Context, *files.UploadArg, io.Reader) (*files.FileMetadata, error)
UploadSessionAppendV2Context(context.Context, *files.UploadSessionAppendArg, io.Reader) error
UploadSessionFinishContext(context.Context, *files.UploadSessionFinishArg, io.Reader) (*files.FileMetadata, error)
UploadSessionStartContext(context.Context, *files.UploadSessionStartArg, io.Reader) (*files.UploadSessionStartResult, error)
}

var filesNewFunc = func(cfg dropbox.Config) filesClient {
return files.NewContext(cfg)
}
26 changes: 13 additions & 13 deletions cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func get(cmd *cobra.Command, args []string) (err error) {

dbx := filesNewFunc(config)

meta, err := dbx.GetMetadata(files.NewGetMetadataArg(src))
meta, err := dbx.GetMetadataContext(currentContext(), files.NewGetMetadataArg(src))
if err != nil {
if recursive {
return withJSONErrorDetails(fmt.Errorf("get metadata for %s: %v", src, err), operationErrorDetails("download"), pathErrorDetails(src))
Expand Down Expand Up @@ -204,7 +204,7 @@ func getStdout(cmd *cobra.Command, src string, recursive bool) error {

dbx := filesNewFunc(config)

meta, err := dbx.GetMetadata(files.NewGetMetadataArg(src))
meta, err := dbx.GetMetadataContext(currentContext(), files.NewGetMetadataArg(src))
if err == nil {
if _, ok := meta.(*files.FolderMetadata); ok {
return invalidArgumentsErrorfWithDetails("%s is a folder; cannot download folder to stdout", mergeJSONErrorDetails(operationErrorDetails("download"), pathErrorDetails(src)), src)
Expand All @@ -214,7 +214,7 @@ func getStdout(cmd *cobra.Command, src string, recursive bool) error {
return withJSONErrorDetails(downloadToStdout(dbx, src, cmd.OutOrStdout()), operationErrorDetails("download"), pathErrorDetails(src))
}

func getWithClient(dbx files.Client, args []string) (err error) {
func getWithClient(dbx filesClient, args []string) (err error) {
if len(args) == 0 || len(args) > 2 {
return invalidArgumentsErrorWithDetails("`get` requires `src` and/or `dst` arguments", argumentsErrorDetails("src", "dst"))
}
Expand All @@ -235,20 +235,20 @@ func getWithClient(dbx files.Client, args []string) (err error) {
return withJSONErrorDetails(downloadFile(dbx, src, dst), operationErrorDetails("download"), pathErrorDetails(src), relocationErrorDetails(src, dst))
}

func getRecursive(dbx files.Client, src, dst string) error {
func getRecursive(dbx filesClient, src, dst string) error {
_, err := getRecursiveInternal(dbx, src, dst, nil, getOptions{}, false)
return err
}

func getRecursiveWithResults(dbx files.Client, src, dst string, rootMeta files.IsMetadata, opts getOptions) ([]getResult, error) {
func getRecursiveWithResults(dbx filesClient, src, dst string, rootMeta files.IsMetadata, opts getOptions) ([]getResult, error) {
return getRecursiveInternal(dbx, src, dst, rootMeta, opts, true)
}

func getRecursiveInternal(dbx files.Client, src, dst string, rootMeta files.IsMetadata, opts getOptions, collectResults bool) ([]getResult, error) {
func getRecursiveInternal(dbx filesClient, src, dst string, rootMeta files.IsMetadata, opts getOptions, collectResults bool) ([]getResult, error) {
arg := files.NewListFolderArg(src)
arg.Recursive = true

res, err := dbx.ListFolder(arg)
res, err := dbx.ListFolderContext(currentContext(), arg)
if err != nil {
return nil, withJSONErrorDetails(fmt.Errorf("list folder %s: %v", src, err), operationErrorDetails("download"), pathErrorDetails(src))
}
Expand All @@ -257,7 +257,7 @@ func getRecursiveInternal(dbx files.Client, src, dst string, rootMeta files.IsMe
entries = append(entries, res.Entries...)
for res.HasMore {
cont := files.NewListFolderContinueArg(res.Cursor)
res, err = dbx.ListFolderContinue(cont)
res, err = dbx.ListFolderContinueContext(currentContext(), cont)
if err != nil {
return nil, withJSONErrorDetails(fmt.Errorf("list folder continue: %v", err), operationErrorDetails("download"), pathErrorDetails(src))
}
Expand Down Expand Up @@ -369,20 +369,20 @@ func relativeTo(base, full string) (string, error) {
return rel, nil
}

func downloadFile(dbx files.Client, src string, dst string) error {
func downloadFile(dbx filesClient, src string, dst string) error {
_, err := downloadFileWithMetadata(dbx, src, dst, os.Stderr)
return err
}

func downloadFileWithResult(dbx files.Client, src string, dst string, opts getOptions) (getResult, error) {
func downloadFileWithResult(dbx filesClient, src string, dst string, opts getOptions) (getResult, error) {
metadata, err := downloadFileWithMetadata(dbx, src, dst, getErrorOutput(opts))
if err != nil {
return getResult{}, err
}
return newGetResult(getStatusDownloaded, getKindFile, src, dst, metadata)
}

func downloadFileWithMetadata(dbx files.Client, src string, dst string, errOut io.Writer) (*files.FileMetadata, error) {
func downloadFileWithMetadata(dbx filesClient, src string, dst string, errOut io.Writer) (*files.FileMetadata, error) {
arg := files.NewDownloadArg(src)
var metadata *files.FileMetadata

Expand Down Expand Up @@ -434,8 +434,8 @@ func downloadDestinationPath(dst string) (string, error) {
return "", fmt.Errorf("too many symlinks resolving %s", dst)
}

func downloadFileOnce(dbx files.Client, arg *files.DownloadArg, dst string, errOut io.Writer) (*files.FileMetadata, error) {
res, contents, err := dbx.Download(arg)
func downloadFileOnce(dbx filesClient, arg *files.DownloadArg, dst string, errOut io.Writer) (*files.FileMetadata, error) {
res, contents, err := dbx.DownloadContext(currentContext(), arg)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

func info(cmd *cobra.Command, args []string) (err error) {
dbx := teamNewFunc(config)
res, err := dbx.GetInfo()
res, err := dbx.GetInfoContext(currentContext())
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/json_contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,10 @@ func TestAccountAuthContractOmitsSensitiveFields(t *testing.T) {
t.Fatal(err)
}

output := string(encoded)
payload := string(encoded)
for _, forbidden := range []string{"access_token", "refresh_token", "app_key", "auth.json", ".config"} {
if strings.Contains(output, forbidden) {
t.Fatalf("account JSON contains %q: %s", forbidden, output)
if strings.Contains(payload, forbidden) {
t.Fatalf("account JSON contains %q: %s", forbidden, payload)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/list-groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func listGroups(cmd *cobra.Command, args []string) (err error) {

func listTeamGroups(dbx teamClient, arg *team.GroupsListArg) ([]*team_common.GroupSummary, error) {
var groups []*team_common.GroupSummary
res, err := dbx.GroupsList(arg)
res, err := dbx.GroupsListContext(currentContext(), arg)
if err != nil {
return nil, err
}
Expand All @@ -52,7 +52,7 @@ func listTeamGroups(dbx teamClient, arg *team.GroupsListArg) ([]*team_common.Gro
if res.Cursor == "" {
return nil, errors.New("team group list has more results but no cursor")
}
res, err = dbx.GroupsListContinue(team.NewGroupsListContinueArg(res.Cursor))
res, err = dbx.GroupsListContinueContext(currentContext(), team.NewGroupsListContinueArg(res.Cursor))
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/list-members.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func listMembers(cmd *cobra.Command, args []string) (err error) {

func listTeamMembers(dbx teamClient, arg *team.MembersListArg) ([]*team.TeamMemberInfo, error) {
var members []*team.TeamMemberInfo
res, err := dbx.MembersList(arg)
res, err := dbx.MembersListContext(currentContext(), arg)
if err != nil {
return nil, err
}
Expand All @@ -51,7 +51,7 @@ func listTeamMembers(dbx teamClient, arg *team.MembersListArg) ([]*team.TeamMemb
if res.Cursor == "" {
return nil, errors.New("team member list has more results but no cursor")
}
res, err = dbx.MembersListContinue(team.NewMembersListContinueArg(res.Cursor))
res, err = dbx.MembersListContinueContext(currentContext(), team.NewMembersListContinueArg(res.Cursor))
if err != nil {
return nil, err
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ By default, login stores credentials for regular Dropbox user commands.
Use "team-access" for --as-member commands or "team-manage" for team commands.`,
Args: cobra.MaximumNArgs(1),
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if err := initCommandContext(cmd); err != nil {
return err
}
return validateOutputFormat(cmd)
},
RunE: login,
Expand Down
7 changes: 5 additions & 2 deletions cmd/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ var revokeAccessToken = func(domain string, token string) error {
HeaderGenerator: nil,
URLGenerator: nil,
}
client := auth.New(cfg)
return client.TokenRevoke()
client := auth.NewContext(cfg)
return client.TokenRevokeContext(currentContext())
}

// Command logout revokes all saved API tokens and deletes auth.json.
Expand Down Expand Up @@ -141,6 +141,9 @@ credentials. If DBXCLI_ACCESS_TOKEN is set, unset it before running logout;
environment-provided tokens are not saved locally and cannot be removed by
dbxcli.`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
if err := initCommandContext(cmd); err != nil {
return err
}
return validateOutputFormat(cmd)
},
RunE: logout,
Expand Down
Loading
Loading