storj/uplink/setup/setup.go
Jeff Wendling 1a65e42d33 rename EncryptionCtx back to EncryptionAccess (#2368)
* rename EncryptionCtx back to EncryptionAccess

Change-Id: I5e58915a59979ad6f2e83d36e191b2bbf3ba2ba2

* missed some stuff

Change-Id: Ib65fb186d7f854c0406e5fd7d11498e8941da59e

* oops protolock

Change-Id: I85a5ab4bafb9dd6a804d3dcd17a70811702f07e4

* retrigger

Change-Id: I2d0e3f02b4dbae0299b090e9617662b4437980b0
2019-06-27 23:18:24 -06:00

52 lines
1.2 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package setup
import (
"context"
"io/ioutil"
"strings"
"github.com/zeebo/errs"
"gopkg.in/spacemonkeygo/monkit.v2"
libuplink "storj.io/storj/lib/uplink"
"storj.io/storj/pkg/storj"
"storj.io/storj/uplink"
)
var (
mon = monkit.Package()
// Error is the class of errors returned by this package
Error = errs.Class("uplink setup")
)
// LoadEncryptionAccess loads an EncryptionAccess from the values specified in the encryption config.
func LoadEncryptionAccess(ctx context.Context, cfg uplink.EncryptionConfig) (_ *libuplink.EncryptionAccess, err error) {
defer mon.Task()(&ctx)(&err)
if cfg.EncAccessFilepath != "" {
data, err := ioutil.ReadFile(cfg.EncAccessFilepath)
if err != nil {
return nil, errs.Wrap(err)
}
return libuplink.ParseEncryptionAccess(strings.TrimSpace(string(data)))
}
data := []byte(cfg.EncryptionKey)
if cfg.KeyFilepath != "" {
data, err = ioutil.ReadFile(cfg.KeyFilepath)
if err != nil {
return nil, errs.Wrap(err)
}
}
key, err := storj.NewKey(data)
if err != nil {
return nil, errs.Wrap(err)
}
return libuplink.NewEncryptionAccessWithDefaultKey(*key), nil
}