frostfs-node/pkg/services/control/ir/server/server.go
Alejandro Lopez cb5468abb8 [] node: Replace interface{} with any
Signed-off-by: Alejandro Lopez <a.lopez@yadro.com>
2023-02-21 16:47:07 +03:00

51 lines
1 KiB
Go

package control
import (
"fmt"
)
// Server is an entity that serves
// Control service on IR node.
//
// To gain access to the service, any request must be
// signed with a key from the white list.
type Server struct {
prm Prm
allowedKeys [][]byte
}
func panicOnPrmValue(n string, v any) {
const invalidPrmValFmt = "invalid %s parameter (%T): %v"
panic(fmt.Sprintf(invalidPrmValFmt, n, v, v))
}
// New creates a new instance of the Server.
//
// Panics if:
// - parameterized private key is nil;
// - parameterized HealthChecker is nil.
//
// Forms white list from all keys specified via
// WithAllowedKeys option and a public key of
// the parameterized private key.
func New(prm Prm, opts ...Option) *Server {
// verify required parameters
switch {
case prm.healthChecker == nil:
panicOnPrmValue("health checker", prm.healthChecker)
}
// compute optional parameters
o := defaultOptions()
for _, opt := range opts {
opt(o)
}
return &Server{
prm: prm,
allowedKeys: append(o.allowedKeys, prm.key.PublicKey().Bytes()),
}
}