From 9bb2bfb327f7de88e45e1cc0223190f239eec1be Mon Sep 17 00:00:00 2001 From: Diwaker Gupta Date: Mon, 1 Aug 2016 12:14:15 -0700 Subject: [PATCH] Actually vendor in the auth package from the Go SDK. Also fix `share list folders` invocation in test script. --- contrib/test.sh | 4 +- .../dropbox/auth/client.go | 108 ++++++++++++++++++ .../dropbox/auth/types.go | 66 +++++++++++ vendor/vendor.json | 4 +- 4 files changed, 178 insertions(+), 4 deletions(-) create mode 100644 vendor/github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/auth/client.go create mode 100644 vendor/github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/auth/types.go diff --git a/contrib/test.sh b/contrib/test.sh index c876711..6fc8c9e 100755 --- a/contrib/test.sh +++ b/contrib/test.sh @@ -46,8 +46,8 @@ ${dbxcli} rmdir ${d} echo "Testing share commands" -echo "Testing share list-folders" -${dbxcli} share list-folders +echo "Testing share list folders" +${dbxcli} share list folders echo "Testing team commands" echo "Testing team info" diff --git a/vendor/github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/auth/client.go b/vendor/github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/auth/client.go new file mode 100644 index 0000000..afe8c50 --- /dev/null +++ b/vendor/github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/auth/client.go @@ -0,0 +1,108 @@ +// Copyright (c) Dropbox, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +// Package auth : has no documentation (yet) +package auth + +import ( + "encoding/json" + "io/ioutil" + "log" + "net/http" + + "github.com/dropbox/dropbox-sdk-go-unofficial/dropbox" +) + +// Client interface describes all routes in this namespace +type Client interface { + // TokenRevoke : Disables the access token used to authenticate the call. + TokenRevoke() (err error) +} + +type apiImpl dropbox.Context + +//TokenRevokeAPIError is an error-wrapper for the token/revoke route +type TokenRevokeAPIError struct { + dropbox.APIError + EndpointError struct{} `json:"error"` +} + +func (dbx *apiImpl) TokenRevoke() (err error) { + cli := dbx.Client + + req, err := http.NewRequest("POST", (*dropbox.Context)(dbx).GenerateURL("api", "auth", "token/revoke"), nil) + if err != nil { + return + } + + if dbx.Config.AsMemberID != "" { + req.Header.Set("Dropbox-API-Select-User", dbx.Config.AsMemberID) + } + if dbx.Config.Verbose { + log.Printf("req: %v", req) + } + resp, err := cli.Do(req) + if dbx.Config.Verbose { + log.Printf("resp: %v", resp) + } + if err != nil { + return + } + + defer resp.Body.Close() + body, err := ioutil.ReadAll(resp.Body) + if err != nil { + return + } + + if dbx.Config.Verbose { + log.Printf("body: %s", body) + } + if resp.StatusCode == http.StatusOK { + return + } + if resp.StatusCode == http.StatusConflict { + var apiError TokenRevokeAPIError + err = json.Unmarshal(body, &apiError) + if err != nil { + return + } + err = apiError + return + } + var apiError dropbox.APIError + if resp.StatusCode == http.StatusBadRequest { + apiError.ErrorSummary = string(body) + err = apiError + return + } + err = json.Unmarshal(body, &apiError) + if err != nil { + return + } + err = apiError + return +} + +// New returns a Client implementation for this namespace +func New(c dropbox.Config) *apiImpl { + ctx := apiImpl(dropbox.NewContext(c)) + return &ctx +} diff --git a/vendor/github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/auth/types.go b/vendor/github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/auth/types.go new file mode 100644 index 0000000..b691f4f --- /dev/null +++ b/vendor/github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/auth/types.go @@ -0,0 +1,66 @@ +// Copyright (c) Dropbox, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +// Package auth : has no documentation (yet) +package auth + +import "github.com/dropbox/dropbox-sdk-go-unofficial/dropbox" + +// AuthError : Errors occurred during authentication. +type AuthError struct { + dropbox.Tagged +} + +// Valid tag values for AuthError +const ( + AuthErrorInvalidAccessToken = "invalid_access_token" + AuthErrorInvalidSelectUser = "invalid_select_user" + AuthErrorInvalidSelectAdmin = "invalid_select_admin" + AuthErrorOther = "other" +) + +// RateLimitError : Error occurred because the app is being rate limited. +type RateLimitError struct { + // Reason : The reason why the app is being rate limited. + Reason *RateLimitReason `json:"reason"` + // RetryAfter : The number of seconds that the app should wait before making + // another request. + RetryAfter uint64 `json:"retry_after"` +} + +// NewRateLimitError returns a new RateLimitError instance +func NewRateLimitError(Reason *RateLimitReason) *RateLimitError { + s := new(RateLimitError) + s.Reason = Reason + s.RetryAfter = 1 + return s +} + +// RateLimitReason : has no documentation (yet) +type RateLimitReason struct { + dropbox.Tagged +} + +// Valid tag values for RateLimitReason +const ( + RateLimitReasonTooManyRequests = "too_many_requests" + RateLimitReasonTooManyWriteOperations = "too_many_write_operations" + RateLimitReasonOther = "other" +) diff --git a/vendor/vendor.json b/vendor/vendor.json index 9b296cb..20b6523 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -117,8 +117,8 @@ { "checksumSHA1": "9jjO5GjLa0XF/nfWihF02RoH4qc=", "path": "golang.org/x/net/context", - "revision": "6a513affb38dc9788b449d59ffed099b8de18fa0", - "revisionTime": "2016-07-26T08:19:14Z" + "revision": "35028a49ca5a73b486af60cd20ac21cd6b67bfdb", + "revisionTime": "2016-07-31T22:09:09Z" }, { "checksumSHA1": "DSW8n4bSrd8JdBINM/DFoRWK64w=",