frostfs-node/cmd/frostfs-node/config/billing/config.go
Dmitrii Stepanov 020281a0e9 [#9999] node: Add billing service
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
2024-06-24 16:39:43 +03:00

58 lines
1.3 KiB
Go

package billing
import (
"fmt"
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config"
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
)
type GRPCConfig struct {
cfg *config.Config
}
const (
subsection = "billing"
grpcSubsection = "grpc"
// GRPCEndpointDefault is a default endpoint of gRPC Billing service.
GRPCEndpointDefault = ""
)
// AuthorizedKeys parses and returns an array of "authorized_keys" config
// parameter from "control" section.
//
// Returns an empty list if not set.
func AuthorizedKeys(c *config.Config) keys.PublicKeys {
strKeys := config.StringSliceSafe(c.Sub(subsection), "authorized_keys")
pubs := make(keys.PublicKeys, 0, len(strKeys))
for i := range strKeys {
pub, err := keys.NewPublicKeyFromString(strKeys[i])
if err != nil {
panic(fmt.Errorf("invalid permitted key for Billing service %s: %w", strKeys[i], err))
}
pubs = append(pubs, pub)
}
return pubs
}
func GRPC(c *config.Config) GRPCConfig {
return GRPCConfig{
c.Sub(subsection).Sub(grpcSubsection),
}
}
// Endpoint returns the value of "endpoint" config parameter.
//
// Returns GRPCEndpointDefault if the value is not a non-empty string.
func (g GRPCConfig) Endpoint() string {
v := config.String(g.cfg, "endpoint")
if v != "" {
return v
}
return GRPCEndpointDefault
}