f5227abd36
* uplink: Mark encryption key config field for setup Set the "setup" property to the `EncryptionConfig.EncrptionKey` for avoiding to save it in the configuration file. This field is only meant for using in the command line parameters which need to use a different encryption key than the one present in the key file or use it when there is not set any encryption key file path. * cmd/uplink: Setup non-interactive accept enc key Change the uplink CLI setup command non-interactive to save the encryption key into a file when it's passed through the flag --enc.encryption-key Previous to this change it wasn't possible to create an key file despite of that the flag was provided, so it was useless on the setup command. * cmd/uplink: Reuse logic to read pwd from terminal Reuse the logic which is already implemented in the pkg/cfgstruct for reading a password from the terminal on interactive mode, rather than duplicating it in the setup command. * cmd/gateway: Use encryption key file flags The cmd/gateway was still using the `enc.key` configuration field which doesn't exist anymore and its setup command wasn't using the `enc.key-filepath` with combination of the `enc.encryption-key` for generating a file with the encryption key. This commit update the cmd/gateway appropriately and move to the uplink package the function used by cmd/uplink to save the encryption key for allowing to also be used by the cmd/gateway without duplicating the logic. * cmd/storj-sim: Adapt gateway config cmd changes Adapt the cmd/storj-sim to correctly pass the parameters to the cmd/gateway setup and run command. * scripts: Don't pass the --enc.encryption-key flag uplink configuration has changed to only support the `--enc.encryption-key` flag for setup commands and consequently the cmd/uplink and cmd/gateway don't accept this flag over other commands, hence the test for the uplink had to be updated for no passing the flag on the multiples calls that the test do to cmd/uplink. * uplink: Remove func which aren't useful anymore Remove the function which allows to user or load an encryption key because it isn't needed anymore since the `--enc.encryption-key` flag is only available for the setup command. Consequently remove its usage from cmd/uplink and cmd/gateway, because such flag will always be empty because in case that's passed Cobra will return an error due to a "unknown flag".
42 lines
888 B
Go
42 lines
888 B
Go
// Copyright (C) 2019 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package uplink
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/zeebo/errs"
|
|
)
|
|
|
|
// SaveEncryptionKey generates a Storj key from the inputKey and save it into a
|
|
// new file created in filepath.
|
|
func SaveEncryptionKey(inputKey string, filepath string) error {
|
|
switch {
|
|
case len(inputKey) == 0:
|
|
return Error.New("inputKey is empty")
|
|
case filepath == "":
|
|
return Error.New("filepath is empty")
|
|
}
|
|
|
|
file, err := os.OpenFile(filepath, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0600)
|
|
if err != nil {
|
|
if os.IsNotExist(err) {
|
|
return Error.New("directory path doesn't exist. %+v", err)
|
|
}
|
|
|
|
if os.IsExist(err) {
|
|
return Error.New("file key already exists. %+v", err)
|
|
}
|
|
|
|
return Error.Wrap(err)
|
|
}
|
|
|
|
defer func() {
|
|
err = Error.Wrap(errs.Combine(err, file.Close()))
|
|
}()
|
|
|
|
_, err = file.Write([]byte(inputKey))
|
|
return err
|
|
}
|