forked from TrueCloudLab/frostfs-node
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package qos
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/cmd/frostfs-node/config"
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
)
|
|
|
|
const (
|
|
subsection = "qos"
|
|
criticalSubSection = "critical"
|
|
internalSubSection = "internal"
|
|
)
|
|
|
|
// CriticalAuthorizedKeys parses and returns an array of "critical.authorized_keys" config
|
|
// parameter from "qos" section.
|
|
//
|
|
// Returns an empty list if not set.
|
|
func CriticalAuthorizedKeys(c *config.Config) keys.PublicKeys {
|
|
return authorizedKeys(c, criticalSubSection)
|
|
}
|
|
|
|
// InternalAuthorizedKeys parses and returns an array of "internal.authorized_keys" config
|
|
// parameter from "qos" section.
|
|
//
|
|
// Returns an empty list if not set.
|
|
func InternalAuthorizedKeys(c *config.Config) keys.PublicKeys {
|
|
return authorizedKeys(c, internalSubSection)
|
|
}
|
|
|
|
func authorizedKeys(c *config.Config, sub string) keys.PublicKeys {
|
|
strKeys := config.StringSliceSafe(c.Sub(subsection).Sub(sub), "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 authorized key %s for qos.%s: %w", strKeys[i], sub, err))
|
|
}
|
|
|
|
pubs = append(pubs, pub)
|
|
}
|
|
|
|
return pubs
|
|
}
|