2021-06-09 15:40:02 +00:00
|
|
|
package control
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-04-25 12:09:20 +00:00
|
|
|
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/netmap"
|
2021-06-09 15:40:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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 {
|
2023-04-25 12:09:20 +00:00
|
|
|
prm Prm
|
|
|
|
netmapClient *netmap.Client
|
2021-06-09 15:40:02 +00:00
|
|
|
|
|
|
|
allowedKeys [][]byte
|
|
|
|
}
|
|
|
|
|
2023-02-21 11:42:45 +00:00
|
|
|
func panicOnPrmValue(n string, v any) {
|
2021-06-09 15:40:02 +00:00
|
|
|
const invalidPrmValFmt = "invalid %s parameter (%T): %v"
|
|
|
|
panic(fmt.Sprintf(invalidPrmValFmt, n, v, v))
|
|
|
|
}
|
|
|
|
|
|
|
|
// New creates a new instance of the Server.
|
|
|
|
//
|
|
|
|
// Panics if:
|
2022-08-15 16:20:20 +00:00
|
|
|
// - parameterized private key is nil;
|
|
|
|
// - parameterized HealthChecker is nil.
|
2021-06-09 15:40:02 +00:00
|
|
|
//
|
|
|
|
// Forms white list from all keys specified via
|
|
|
|
// WithAllowedKeys option and a public key of
|
|
|
|
// the parameterized private key.
|
2023-04-25 12:09:20 +00:00
|
|
|
func New(prm Prm, netmapClient *netmap.Client, opts ...Option) *Server {
|
2021-06-09 15:40:02 +00:00
|
|
|
// 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{
|
2023-04-25 12:09:20 +00:00
|
|
|
prm: prm,
|
|
|
|
netmapClient: netmapClient,
|
2021-06-09 15:40:02 +00:00
|
|
|
|
2021-06-09 15:49:10 +00:00
|
|
|
allowedKeys: append(o.allowedKeys, prm.key.PublicKey().Bytes()),
|
2021-06-09 15:40:02 +00:00
|
|
|
}
|
|
|
|
}
|