Skip to content

Commit

Permalink
Merge branch 'logout' of https://github.com/waits/dbxcli into waits-l…
Browse files Browse the repository at this point in the history
…ogout
  • Loading branch information
Diwaker Gupta committed Aug 1, 2016
2 parents 0d0f065 + ed1180f commit 27e0d3e
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
68 changes: 68 additions & 0 deletions cmd/logout.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright © 2016 Dropbox, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
"os"
"path"

"github.com/dropbox/dropbox-sdk-go-unofficial/dropbox"
"github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/auth"
"github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
)

// Command logout revokes all saved API tokens and deletes auth.json.
func logout(cmd *cobra.Command, args []string) error {
dir, err := homedir.Dir()
if err != nil {
return err
}
filePath := path.Join(dir, ".config", "dbxcli", configFileName)

tokMap, err := readTokens(filePath)
if err != nil {
return err
}

for domain, tokens := range tokMap {
for _, token := range tokens {
config := dropbox.Config{token, false, "", domain}
client := auth.New(config)
client.TokenRevoke()
if err != nil {
return err
}
}
}

err = os.Remove(filePath)
if err != nil {
return err
}

return nil
}

// logoutCmd represents the logout command
var logoutCmd = &cobra.Command{
Use: "logout [flags]",
Short: "Log out of the current session",
RunE: logout,
}

func init() {
RootCmd.AddCommand(logoutCmd)
}
6 changes: 6 additions & 0 deletions vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
"revision": "13ed6f02d47dc93e1db59be7baf38e23f98115f6",
"revisionTime": "2016-07-29T17:17:04Z"
},
{
"checksumSHA1": "gkqoyxhExzsn7cdvhu7QGK121mk=",
"path": "github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/auth",
"revision": "13ed6f02d47dc93e1db59be7baf38e23f98115f6",
"revisionTime": "2016-07-29T17:17:04Z"
},
{
"checksumSHA1": "5T6WkbCA/i4yc3ygXroJcBXYMyo=",
"path": "github.com/dropbox/dropbox-sdk-go-unofficial/dropbox/files",
Expand Down

0 comments on commit 27e0d3e

Please sign in to comment.