2021-05-26 21:19:29 +01:00
|
|
|
// Copyright (C) 2021 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2022-02-07 20:21:55 +00:00
|
|
|
"storj.io/common/rpc"
|
2022-04-15 15:10:39 +01:00
|
|
|
"storj.io/common/rpc/rpcpool"
|
2022-01-06 19:55:46 +00:00
|
|
|
"storj.io/storj/cmd/uplink/ulext"
|
|
|
|
"storj.io/storj/cmd/uplink/ulfs"
|
2021-05-26 21:19:29 +01:00
|
|
|
"storj.io/uplink"
|
|
|
|
privateAccess "storj.io/uplink/private/access"
|
2022-02-07 20:21:55 +00:00
|
|
|
"storj.io/uplink/private/transport"
|
2021-05-26 21:19:29 +01:00
|
|
|
)
|
|
|
|
|
2021-12-14 10:48:14 +00:00
|
|
|
const uplinkCLIUserAgent = "uplink-cli"
|
|
|
|
|
2021-05-26 21:19:29 +01:00
|
|
|
func (ex *external) OpenFilesystem(ctx context.Context, accessName string, options ...ulext.Option) (ulfs.Filesystem, error) {
|
|
|
|
project, err := ex.OpenProject(ctx, accessName, options...)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return ulfs.NewMixed(ulfs.NewLocal(), ulfs.NewRemote(project)), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ex *external) OpenProject(ctx context.Context, accessName string, options ...ulext.Option) (*uplink.Project, error) {
|
|
|
|
opts := ulext.LoadOptions(options...)
|
|
|
|
|
2021-06-22 23:41:22 +01:00
|
|
|
access, err := ex.OpenAccess(accessName)
|
2021-05-26 21:19:29 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if opts.EncryptionBypass {
|
|
|
|
if err := privateAccess.EnablePathEncryptionBypass(access); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-14 10:48:14 +00:00
|
|
|
config := uplink.Config{
|
|
|
|
UserAgent: uplinkCLIUserAgent,
|
|
|
|
}
|
|
|
|
|
2022-02-07 20:21:55 +00:00
|
|
|
if ex.quic {
|
|
|
|
transport.SetConnector(&config, rpc.NewHybridConnector())
|
|
|
|
}
|
|
|
|
|
2022-04-15 15:10:39 +01:00
|
|
|
if opts.ConnectionPoolOptions != (rpcpool.Options{}) {
|
|
|
|
if err := transport.SetConnectionPool(ctx, &config, rpcpool.New(opts.ConnectionPoolOptions)); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-14 10:48:14 +00:00
|
|
|
return config.OpenProject(ctx, access)
|
2021-05-26 21:19:29 +01:00
|
|
|
}
|