2011-07-08 19:48:01 +00:00
|
|
|
/*
|
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
|
|
|
Copyright 2014 The Perkeep Authors.
|
2011-07-08 19:48:01 +00:00
|
|
|
|
|
|
|
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 main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
"encoding/json"
|
2013-02-25 20:40:11 +00:00
|
|
|
"flag"
|
2011-07-08 19:48:01 +00:00
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
Rename import paths from camlistore.org to perkeep.org.
Part of the project renaming, issue #981.
After this, users will need to mv their $GOPATH/src/camlistore.org to
$GOPATH/src/perkeep.org. Sorry.
This doesn't yet rename the tools like camlistored, camput, camget,
camtool, etc.
Also, this only moves the lru package to internal. More will move to
internal later.
Also, this doesn't yet remove the "/pkg/" directory. That'll likely
happen later.
This updates some docs, but not all.
devcam test now passes again, even with Go 1.10 (which requires vet
checks are clean too). So a bunch of vet tests are fixed in this CL
too, and a bunch of other broken tests are now fixed (introduced from
the past week of merging the CL backlog).
Change-Id: If580db1691b5b99f8ed6195070789b1f44877dd4
2018-01-01 22:41:41 +00:00
|
|
|
"perkeep.org/pkg/blobserver/google/drive"
|
|
|
|
"perkeep.org/pkg/cmdmain"
|
2015-04-07 16:02:33 +00:00
|
|
|
|
2016-09-07 18:27:11 +00:00
|
|
|
"cloud.google.com/go/storage"
|
2015-11-26 23:31:36 +00:00
|
|
|
"go4.org/oauthutil"
|
2015-08-18 08:19:49 +00:00
|
|
|
"golang.org/x/oauth2"
|
2016-06-08 19:09:10 +00:00
|
|
|
"golang.org/x/oauth2/google"
|
2011-07-08 19:48:01 +00:00
|
|
|
)
|
|
|
|
|
2014-03-23 15:08:14 +00:00
|
|
|
type googinitCmd struct {
|
|
|
|
storageType string
|
|
|
|
}
|
2013-02-25 20:40:11 +00:00
|
|
|
|
|
|
|
func init() {
|
2014-03-23 15:08:14 +00:00
|
|
|
cmdmain.RegisterCommand("googinit", func(flags *flag.FlagSet) cmdmain.CommandRunner {
|
|
|
|
cmd := new(googinitCmd)
|
2014-07-06 15:11:28 +00:00
|
|
|
flags.StringVar(&cmd.storageType, "type", "", "Storage type: drive or cloud")
|
2014-03-23 15:08:14 +00:00
|
|
|
return cmd
|
2013-02-25 20:40:11 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-03-23 15:08:14 +00:00
|
|
|
func (c *googinitCmd) Describe() string {
|
|
|
|
return "Init Google Drive or Google Cloud Storage."
|
2013-02-25 20:40:11 +00:00
|
|
|
}
|
|
|
|
|
2014-03-23 15:08:14 +00:00
|
|
|
func (c *googinitCmd) Usage() {
|
|
|
|
fmt.Fprintf(cmdmain.Stderr, "Usage: camtool [globalopts] googinit [commandopts] \n")
|
2013-02-25 20:40:11 +00:00
|
|
|
}
|
|
|
|
|
2014-03-23 15:08:14 +00:00
|
|
|
func (c *googinitCmd) RunCommand(args []string) error {
|
2011-07-08 19:48:01 +00:00
|
|
|
var (
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
err error
|
2011-07-08 19:48:01 +00:00
|
|
|
clientId string
|
|
|
|
clientSecret string
|
2015-04-07 16:02:33 +00:00
|
|
|
oauthConfig *oauth2.Config
|
2011-07-08 19:48:01 +00:00
|
|
|
)
|
|
|
|
|
2014-03-23 15:08:14 +00:00
|
|
|
if c.storageType != "drive" && c.storageType != "cloud" {
|
2014-07-06 15:11:28 +00:00
|
|
|
return cmdmain.UsageError("Invalid storage type: must be drive for Google Drive or cloud for Google Cloud Storage.")
|
2014-03-23 15:08:14 +00:00
|
|
|
}
|
|
|
|
|
2015-04-07 16:02:33 +00:00
|
|
|
clientId, clientSecret = getClientInfo()
|
2014-03-23 15:08:14 +00:00
|
|
|
|
|
|
|
switch c.storageType {
|
|
|
|
case "drive":
|
2015-04-07 16:02:33 +00:00
|
|
|
oauthConfig = &oauth2.Config{
|
|
|
|
Scopes: []string{drive.Scope},
|
|
|
|
Endpoint: google.Endpoint,
|
|
|
|
ClientID: clientId,
|
|
|
|
ClientSecret: clientSecret,
|
|
|
|
RedirectURL: oauthutil.TitleBarRedirectURL,
|
|
|
|
}
|
2014-03-23 15:08:14 +00:00
|
|
|
case "cloud":
|
2015-04-07 16:02:33 +00:00
|
|
|
oauthConfig = &oauth2.Config{
|
2015-12-07 23:10:09 +00:00
|
|
|
Scopes: []string{storage.ScopeReadWrite},
|
2015-04-07 16:02:33 +00:00
|
|
|
Endpoint: google.Endpoint,
|
|
|
|
ClientID: clientId,
|
|
|
|
ClientSecret: clientSecret,
|
|
|
|
RedirectURL: oauthutil.TitleBarRedirectURL,
|
|
|
|
}
|
2014-03-23 15:08:14 +00:00
|
|
|
}
|
2011-07-08 19:48:01 +00:00
|
|
|
|
2015-04-07 16:02:33 +00:00
|
|
|
token, err := oauth2.ReuseTokenSource(nil, &oauthutil.TokenSource{
|
|
|
|
Config: oauthConfig,
|
|
|
|
AuthCode: func() string {
|
|
|
|
fmt.Fprintf(cmdmain.Stdout, "Get auth code from:\n\n")
|
|
|
|
fmt.Fprintf(cmdmain.Stdout, "%v\n\n", oauthConfig.AuthCodeURL("", oauth2.AccessTypeOffline, oauth2.ApprovalForce))
|
|
|
|
return prompt("Enter auth code:")
|
|
|
|
},
|
|
|
|
}).Token()
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("could not acquire token: %v", err)
|
2011-07-08 19:48:01 +00:00
|
|
|
}
|
|
|
|
|
2014-03-23 15:08:14 +00:00
|
|
|
fmt.Fprintf(cmdmain.Stdout, "\nYour Google auth object:\n\n")
|
|
|
|
enc := json.NewEncoder(cmdmain.Stdout)
|
2011-07-08 19:48:01 +00:00
|
|
|
authObj := map[string]string{
|
2015-04-07 16:02:33 +00:00
|
|
|
"client_id": clientId,
|
|
|
|
"client_secret": clientSecret,
|
|
|
|
"refresh_token": token.RefreshToken,
|
2011-07-08 19:48:01 +00:00
|
|
|
}
|
|
|
|
enc.Encode(authObj)
|
2016-04-23 22:04:09 +00:00
|
|
|
fmt.Fprint(cmdmain.Stdout, "\n\nFor server-config.json, your 'googlecloudstorage' value (update with your bucket name and path):\n\n")
|
|
|
|
fmt.Fprintf(cmdmain.Stdout, "%s:%s:%s:bucketName[/optional/dir]\n", clientId, clientSecret, token.RefreshToken)
|
2013-02-25 20:40:11 +00:00
|
|
|
return nil
|
2011-07-08 19:48:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prompt the user for an input line. Return the given input.
|
2015-04-07 16:02:33 +00:00
|
|
|
func prompt(promptText string) string {
|
2014-03-23 15:08:14 +00:00
|
|
|
fmt.Fprint(cmdmain.Stdout, promptText)
|
2015-04-07 16:02:33 +00:00
|
|
|
sc := bufio.NewScanner(cmdmain.Stdin)
|
|
|
|
sc.Scan()
|
|
|
|
return strings.TrimSpace(sc.Text())
|
2011-07-08 19:48:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prompt for client id / secret
|
2015-04-07 16:02:33 +00:00
|
|
|
func getClientInfo() (string, string) {
|
2014-03-23 15:08:14 +00:00
|
|
|
fmt.Fprintf(cmdmain.Stdout, "Please provide the client id and client secret \n")
|
2016-04-23 22:04:09 +00:00
|
|
|
fmt.Fprintf(cmdmain.Stdout, "(You can find these at https://console.developers.google.com/apis/credentials)\n")
|
2011-07-08 19:48:01 +00:00
|
|
|
var (
|
|
|
|
clientId string
|
|
|
|
clientSecret string
|
|
|
|
)
|
2015-04-07 16:02:33 +00:00
|
|
|
clientId = prompt("Client ID:")
|
|
|
|
clientSecret = prompt("Client Secret:")
|
|
|
|
return clientId, clientSecret
|
2011-07-08 19:48:01 +00:00
|
|
|
}
|