storj/cmd/uplinkng/external_project.go
Michał Niewrzał 75acd6109d cmd/{uplink,uplinkng}: set user agent for uplink binaries
We want to monitor traffic and tools that are used
to interact with our network so we need to append
its user agent.
The same user agent is appended for current uplink
and uplinkng as eventually we will remove first.

Change-Id: I116080d6c2c6c85d591771facf01356de02a9392
2021-12-14 13:00:01 +00:00

45 lines
1.1 KiB
Go

// Copyright (C) 2021 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"context"
"storj.io/storj/cmd/uplinkng/ulext"
"storj.io/storj/cmd/uplinkng/ulfs"
"storj.io/uplink"
privateAccess "storj.io/uplink/private/access"
)
const uplinkCLIUserAgent = "uplink-cli"
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...)
access, err := ex.OpenAccess(accessName)
if err != nil {
return nil, err
}
if opts.EncryptionBypass {
if err := privateAccess.EnablePathEncryptionBypass(access); err != nil {
return nil, err
}
}
config := uplink.Config{
UserAgent: uplinkCLIUserAgent,
}
return config.OpenProject(ctx, access)
}