2019-10-01 00:33:00 +01:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
|
|
|
package storagenode
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"regexp"
|
|
|
|
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// OperatorConfig defines properties related to storage node operator metadata.
|
2019-10-01 00:33:00 +01:00
|
|
|
type OperatorConfig struct {
|
|
|
|
Email string `user:"true" help:"operator email address" default:""`
|
|
|
|
Wallet string `user:"true" help:"operator wallet address" default:""`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify verifies whether operator config is valid.
|
|
|
|
func (c OperatorConfig) Verify(log *zap.Logger) error {
|
|
|
|
if err := isOperatorEmailValid(log, c.Email); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := isOperatorWalletValid(log, c.Wallet); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func isOperatorEmailValid(log *zap.Logger, email string) error {
|
|
|
|
if email == "" {
|
2020-04-13 10:31:17 +01:00
|
|
|
log.Warn("Operator email address isn't specified.")
|
2019-10-01 00:33:00 +01:00
|
|
|
} else {
|
2020-04-13 10:31:17 +01:00
|
|
|
log.Info("Operator email", zap.String("Address", email))
|
2019-10-01 00:33:00 +01:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func isOperatorWalletValid(log *zap.Logger, wallet string) error {
|
|
|
|
if wallet == "" {
|
|
|
|
return fmt.Errorf("operator wallet address isn't specified")
|
|
|
|
}
|
|
|
|
r := regexp.MustCompile("^0x[a-fA-F0-9]{40}$")
|
|
|
|
if match := r.MatchString(wallet); !match {
|
|
|
|
return fmt.Errorf("operator wallet address isn't valid")
|
|
|
|
}
|
|
|
|
|
2020-04-13 10:31:17 +01:00
|
|
|
log.Info("Operator wallet", zap.String("Address", wallet))
|
2019-10-01 00:33:00 +01:00
|
|
|
return nil
|
|
|
|
}
|