-
Notifications
You must be signed in to change notification settings - Fork 534
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Secrets manager introduced to commands (#1251)
secret manager introduced to commands stake/unstake/withdraw/info
- Loading branch information
Showing
12 changed files
with
160 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package polybftsecrets | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/0xPolygon/polygon-edge/secrets" | ||
"github.com/0xPolygon/polygon-edge/secrets/helper" | ||
) | ||
|
||
// common flags for all polybft commands | ||
const ( | ||
DataPathFlag = "data-dir" | ||
ConfigFlag = "config" | ||
|
||
DataPathFlagDesc = "the directory for the Polygon Edge data if the local FS is used" | ||
ConfigFlagDesc = "the path to the SecretsManager config file, if omitted, the local FS secrets manager is used" | ||
) | ||
|
||
// common errors for all polybft commands | ||
var ( | ||
ErrInvalidNum = fmt.Errorf("num flag value should be between 1 and %d", maxInitNum) | ||
ErrInvalidConfig = errors.New("invalid secrets configuration") | ||
ErrInvalidParams = errors.New("no config file or data directory passed in") | ||
ErrUnsupportedType = errors.New("unsupported secrets manager") | ||
ErrSecureLocalStoreNotImplemented = errors.New( | ||
"use a secrets backend, or supply an --insecure flag " + | ||
"to store the private keys locally on the filesystem, " + | ||
"avoid doing so in production") | ||
) | ||
|
||
// GetSecretsManager function resolves secrets manager instance based on provided data or config paths. | ||
// insecureLocalStore defines if utilization of local secrets manager is allowed. | ||
func GetSecretsManager(dataPath, configPath string, insecureLocalStore bool) (secrets.SecretsManager, error) { | ||
if configPath != "" { | ||
secretsConfig, readErr := secrets.ReadConfig(configPath) | ||
if readErr != nil { | ||
return nil, errors.New(ErrInvalidConfig.Error() + ": " + readErr.Error()) | ||
} | ||
|
||
if !secrets.SupportedServiceManager(secretsConfig.Type) { | ||
return nil, ErrUnsupportedType | ||
} | ||
|
||
return helper.InitCloudSecretsManager(secretsConfig) | ||
} | ||
|
||
// Storing secrets on a local file system should only be allowed with --insecure flag, | ||
// to raise awareness that it should be only used in development/testing environments. | ||
// Production setups should use one of the supported secrets managers | ||
if !insecureLocalStore { | ||
return nil, ErrSecureLocalStoreNotImplemented | ||
} | ||
|
||
return helper.SetupLocalSecretsManager(dataPath) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.