Skip to content
This repository has been archived by the owner on Sep 3, 2020. It is now read-only.

Use GOOGLE_API_CLIENT_ID and GOOGLE_API_CLIENT_SECRET #35

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

go get github.com/rakyll/drive/cmd/drive

You must set `GOOGLE_API_CLIENT_ID` and `GOOGLE_API_CLIENT_SECRET` appropriately in your environment before running `drive`. For more information, see [the Google API docs](https://developers.google.com/drive/web/quickstart/quickstart-go#step_1_enable_the_drive_api).
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use these values if there are set. If not, fallback to the embedded credentials.


Use `drive help` for further reference.

$ drive init [path]
Expand Down
26 changes: 23 additions & 3 deletions init.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,31 @@

package drive

import (
"os"
"errors"
)

const (
clientIdEnvKey = "GOOGLE_API_CLIENT_ID"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clientIDEnvKey

clientSecretEnvKey = "GOOGLE_API_CLIENT_SECRET"
)

func (g *Commands) Init() (err error) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func (g *Commands) Init() error {

var refresh string
// TODO: read from env variable.
g.context.ClientId = "354790962074-7rrlnuanmamgg1i4feed12dpuq871bvd.apps.googleusercontent.com"
g.context.ClientSecret = "RHjKdah8RrHFwu6fcc0uEVCw"

g.context.ClientId = os.Getenv(clientIdEnvKey)
if len(g.context.ClientId) == 0 {
err = errors.New("environment variable " + clientIdEnvKey + " must be set")
return
}

g.context.ClientSecret = os.Getenv(clientSecretEnvKey)
if len(g.context.ClientSecret) == 0 {
err = errors.New("environment variable " + clientSecretEnvKey + " must be set")
return
}

if refresh, err = RetrieveRefreshToken(g.context); err != nil {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refresh, err := RetrieveRefreshToken(g.context)
if err != nil {
return err
}

return
}
Expand Down