[#414] ir/control: Implement service server
Implement `ControlServiceServer` on `Server` type. The `Server` requires all requests to be signed with keys from the so-called whitelist. To obtain health status, it uses the abstraction in the form of `HealthChecker` interface. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
93803b1a90
commit
dcfe9a6504
6 changed files with 200 additions and 0 deletions
55
pkg/services/control/ir/server/server.go
Normal file
55
pkg/services/control/ir/server/server.go
Normal file
|
@ -0,0 +1,55 @@
|
|||
package control
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
crypto "github.com/nspcc-dev/neofs-crypto"
|
||||
)
|
||||
|
||||
// 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 interface{}) {
|
||||
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.key == nil:
|
||||
panicOnPrmValue("key", prm.key)
|
||||
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, crypto.MarshalPublicKey(&prm.key.PublicKey)),
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue