diff --git a/README.md b/README.md index 94698312..f1190442 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,8 @@ Use `drive help` for further reference. $ drive diff [path] # outputs a diff of local and remote $ drive publish [path] # publishes a file, outputs URL +To use your own Google Drive API credentials instead of the built-in credentials, set `GOOGLE_API_CLIENT_ID` and `GOOGLE_API_CLIENT_SECRET` appropriately in your environment before running `drive init`. See [the Google API docs](https://developers.google.com/drive/web/quickstart/quickstart-go#step_1_enable_the_drive_api) for more information. + ## Why another Google Drive client? Background sync is not just hard, it's stupid. My technical and philosophical rants about why it is not worth to implement: diff --git a/init.go b/init.go index c254fb66..8a57865d 100644 --- a/init.go +++ b/init.go @@ -14,11 +14,23 @@ package drive +import "os" + +const ( + clientIDEnvKey = "GOOGLE_API_CLIENT_ID" + clientSecretEnvKey = "GOOGLE_API_CLIENT_SECRET" +) + func (g *Commands) Init() (err 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) + g.context.ClientSecret = os.Getenv(clientSecretEnvKey) + if len(g.context.ClientId) == 0 || len(g.context.ClientSecret) == 0 { + g.context.ClientId = "354790962074-7rrlnuanmamgg1i4feed12dpuq871bvd.apps.googleusercontent.com" + g.context.ClientSecret = "RHjKdah8RrHFwu6fcc0uEVCw" + } + if refresh, err = RetrieveRefreshToken(g.context); err != nil { return }