Dmitrii Stepanov
eac61fe9b2
Some checks failed
DCO action / DCO (pull_request) Successful in 1m14s
Vulncheck / Vulncheck (pull_request) Failing after 3m22s
Build / Build Components (1.20) (pull_request) Successful in 3m16s
Build / Build Components (1.21) (pull_request) Successful in 3m13s
Tests and linters / Tests (1.21) (pull_request) Successful in 5m2s
Tests and linters / Tests (1.20) (pull_request) Successful in 5m8s
Tests and linters / Staticcheck (pull_request) Successful in 4m57s
Tests and linters / Tests with -race (pull_request) Successful in 5m3s
Tests and linters / Lint (pull_request) Successful in 5m24s
Signed-off-by: Dmitrii Stepanov <d.stepanov@yadro.com>
57 lines
1.4 KiB
Go
57 lines
1.4 KiB
Go
package control
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/container"
|
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/morph/client/netmap"
|
|
)
|
|
|
|
// 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
|
|
netmapClient *netmap.Client
|
|
containerClient *container.Client
|
|
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, netmapClient *netmap.Client, containerClient *container.Client, 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,
|
|
netmapClient: netmapClient,
|
|
containerClient: containerClient,
|
|
|
|
allowedKeys: append(o.allowedKeys, prm.key.PublicKey().Bytes()),
|
|
}
|
|
}
|