2011-05-09 13:32:24 +00:00
|
|
|
/*
|
2018-01-04 00:52:49 +00:00
|
|
|
Copyright 2011 The Perkeep Authors
|
2011-05-09 13:32:24 +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.
|
|
|
|
*/
|
|
|
|
|
2013-07-08 01:52:14 +00:00
|
|
|
/*
|
|
|
|
Package remote registers the "remote" blobserver storage type, storing
|
2018-01-30 11:02:56 +00:00
|
|
|
and fetching blobs from a remote Perkeep server over HTTPS.
|
2013-07-08 01:52:14 +00:00
|
|
|
|
|
|
|
Example low-level config:
|
|
|
|
|
|
|
|
"/peer/": {
|
|
|
|
"handler": "storage-remote",
|
|
|
|
"handlerArgs": {
|
2016-10-09 14:28:08 +00:00
|
|
|
"url": "https://some-other-server/base",
|
2013-12-26 08:48:29 +00:00
|
|
|
"auth": "userpass:user:pass",
|
2013-07-08 01:52:14 +00:00
|
|
|
"skipStartupCheck": false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-10-09 14:28:08 +00:00
|
|
|
The "handlerArgs" may also contain an optional "trustedCert" option to
|
|
|
|
trust a self-signed TLS certificate. The value is the 20 byte hex prefix
|
2018-04-21 18:04:53 +00:00
|
|
|
of the SHA-256 of the cert, as printed by the perkeepd server
|
2016-10-09 14:28:08 +00:00
|
|
|
on start-up.
|
2013-07-08 01:52:14 +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
|
|
|
package remote // import "perkeep.org/pkg/blobserver/remote"
|
2011-05-09 13:32:24 +00:00
|
|
|
|
|
|
|
import (
|
2017-11-26 09:05:38 +00:00
|
|
|
"context"
|
2011-05-09 13:32:24 +00:00
|
|
|
"io"
|
|
|
|
|
2015-12-01 16:19:49 +00:00
|
|
|
"go4.org/jsonconfig"
|
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/blob"
|
|
|
|
"perkeep.org/pkg/blobserver"
|
|
|
|
"perkeep.org/pkg/client"
|
2011-05-09 13:32:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// remoteStorage is a blobserver.Storage proxy for a remote camlistore
|
|
|
|
// blobserver.
|
|
|
|
type remoteStorage struct {
|
2013-08-21 20:57:28 +00:00
|
|
|
client *client.Client
|
2011-05-09 13:32:24 +00:00
|
|
|
}
|
|
|
|
|
2018-01-24 16:20:21 +00:00
|
|
|
var (
|
|
|
|
_ blobserver.Storage = (*remoteStorage)(nil)
|
|
|
|
_ io.Closer = (*remoteStorage)(nil)
|
|
|
|
)
|
2011-05-10 18:32:47 +00:00
|
|
|
|
2013-07-08 01:52:14 +00:00
|
|
|
// NewFromClient returns a new Storage implementation using the
|
2018-01-30 11:02:56 +00:00
|
|
|
// provided Perkeep client.
|
2011-09-28 18:05:35 +00:00
|
|
|
func NewFromClient(c *client.Client) blobserver.Storage {
|
|
|
|
return &remoteStorage{client: c}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
func newFromConfig(_ blobserver.Loader, config jsonconfig.Obj) (storage blobserver.Storage, err error) {
|
2011-05-09 13:32:24 +00:00
|
|
|
url := config.RequiredString("url")
|
2013-12-26 08:48:29 +00:00
|
|
|
auth := config.RequiredString("auth")
|
2011-05-09 13:32:24 +00:00
|
|
|
skipStartupCheck := config.OptionalBool("skipStartupCheck", false)
|
2016-10-09 14:28:08 +00:00
|
|
|
trustedCert := config.OptionalString("trustedCert", "")
|
2011-05-09 13:32:24 +00:00
|
|
|
if err := config.Validate(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2011-11-16 10:41:38 +00:00
|
|
|
|
2018-01-24 00:38:26 +00:00
|
|
|
client, err := client.New(
|
|
|
|
client.OptionServer(url),
|
2016-10-09 14:28:08 +00:00
|
|
|
client.OptionTrustedCert(trustedCert),
|
|
|
|
)
|
2018-01-24 00:38:26 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2013-12-26 08:48:29 +00:00
|
|
|
if err = client.SetupAuthFromString(auth); err != nil {
|
2011-11-16 10:41:38 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2011-05-09 13:32:24 +00:00
|
|
|
sto := &remoteStorage{
|
2011-11-16 10:41:38 +00:00
|
|
|
client: client,
|
2011-05-09 13:32:24 +00:00
|
|
|
}
|
|
|
|
if !skipStartupCheck {
|
2012-07-22 22:03:02 +00:00
|
|
|
// Do a quick dummy operation to check that our credentials are
|
|
|
|
// correct.
|
|
|
|
// TODO(bradfitz,mpl): skip this operation smartly if it turns out this is annoying/slow for whatever reason.
|
2013-08-04 02:54:30 +00:00
|
|
|
c := make(chan blob.SizedRef, 1)
|
2013-12-02 21:20:51 +00:00
|
|
|
err = sto.EnumerateBlobs(context.TODO(), c, "", 1)
|
2012-07-22 22:03:02 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2011-05-09 13:32:24 +00:00
|
|
|
}
|
|
|
|
return sto, nil
|
|
|
|
}
|
|
|
|
|
2018-01-24 16:20:21 +00:00
|
|
|
func (sto *remoteStorage) Close() error {
|
|
|
|
return sto.client.Close()
|
|
|
|
}
|
|
|
|
|
2018-01-19 17:19:02 +00:00
|
|
|
func (sto *remoteStorage) RemoveBlobs(ctx context.Context, blobs []blob.Ref) error {
|
|
|
|
return sto.client.RemoveBlobs(ctx, blobs)
|
2011-05-09 13:32:24 +00:00
|
|
|
}
|
|
|
|
|
2018-01-06 03:16:52 +00:00
|
|
|
func (sto *remoteStorage) StatBlobs(ctx context.Context, blobs []blob.Ref, fn func(blob.SizedRef) error) error {
|
2011-05-10 20:04:20 +00:00
|
|
|
// TODO: cache the stat response's uploadUrl to save a future
|
|
|
|
// stat later? otherwise clients will just Stat + Upload, but
|
|
|
|
// Upload will also Stat. should be smart and make sure we
|
|
|
|
// avoid ReceiveBlob's Stat whenever it would be redundant.
|
2018-01-06 03:16:52 +00:00
|
|
|
return sto.client.StatBlobs(ctx, blobs, fn)
|
2011-05-09 13:32:24 +00:00
|
|
|
}
|
|
|
|
|
2018-01-16 23:03:16 +00:00
|
|
|
func (sto *remoteStorage) ReceiveBlob(ctx context.Context, blob blob.Ref, source io.Reader) (outsb blob.SizedRef, outerr error) {
|
2011-05-10 22:51:10 +00:00
|
|
|
h := &client.UploadHandle{
|
|
|
|
BlobRef: blob,
|
2014-01-28 20:46:52 +00:00
|
|
|
Size: 0, // size isn't known; 0 is fine, but TODO: ask source if it knows its size
|
2011-05-10 22:51:10 +00:00
|
|
|
Contents: source,
|
|
|
|
}
|
2018-01-16 23:03:16 +00:00
|
|
|
pr, err := sto.client.Upload(ctx, h)
|
2011-05-10 22:51:10 +00:00
|
|
|
if err != nil {
|
2011-05-10 23:13:37 +00:00
|
|
|
outerr = err
|
|
|
|
return
|
2011-05-10 22:51:10 +00:00
|
|
|
}
|
2011-05-10 23:13:37 +00:00
|
|
|
return pr.SizedBlobRef(), nil
|
2011-05-09 13:32:24 +00:00
|
|
|
}
|
|
|
|
|
2018-01-16 23:03:16 +00:00
|
|
|
func (sto *remoteStorage) Fetch(ctx context.Context, b blob.Ref) (file io.ReadCloser, size uint32, err error) {
|
|
|
|
return sto.client.Fetch(ctx, b)
|
2011-05-09 13:32:24 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
func (sto *remoteStorage) MaxEnumerate() int { return 1000 }
|
2011-05-09 13:32:24 +00:00
|
|
|
|
2015-12-12 21:47:31 +00:00
|
|
|
func (sto *remoteStorage) EnumerateBlobs(ctx context.Context, dest chan<- blob.SizedRef, after string, limit int) error {
|
2013-12-02 21:20:51 +00:00
|
|
|
return sto.client.EnumerateBlobsOpts(ctx, dest, client.EnumerateOpts{
|
2013-08-21 20:57:28 +00:00
|
|
|
After: after,
|
|
|
|
Limit: limit,
|
2011-05-10 18:32:47 +00:00
|
|
|
})
|
2011-05-09 13:32:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
blobserver.RegisterStorageConstructor("remote", blobserver.StorageConstructor(newFromConfig))
|
|
|
|
}
|