1// Copyright (C) 2021 Storj Labs, Inc.
2// See LICENSE for copying information.
3
4package main
5
6import (
7	"context"
8
9	"storj.io/storj/cmd/uplinkng/ulext"
10	"storj.io/storj/cmd/uplinkng/ulfs"
11	"storj.io/uplink"
12	privateAccess "storj.io/uplink/private/access"
13)
14
15func (ex *external) OpenFilesystem(ctx context.Context, accessName string, options ...ulext.Option) (ulfs.Filesystem, error) {
16	project, err := ex.OpenProject(ctx, accessName, options...)
17	if err != nil {
18		return nil, err
19	}
20	return ulfs.NewMixed(ulfs.NewLocal(), ulfs.NewRemote(project)), nil
21}
22
23func (ex *external) OpenProject(ctx context.Context, accessName string, options ...ulext.Option) (*uplink.Project, error) {
24	opts := ulext.LoadOptions(options...)
25
26	access, err := ex.OpenAccess(accessName)
27	if err != nil {
28		return nil, err
29	}
30
31	if opts.EncryptionBypass {
32		if err := privateAccess.EnablePathEncryptionBypass(access); err != nil {
33			return nil, err
34		}
35	}
36
37	return uplink.OpenProject(ctx, access)
38}
39