2020-09-22 15:51:34 +01:00
// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
2020-12-09 16:34:37 +00:00
package nodes
2020-09-22 15:51:34 +01:00
import (
2020-10-02 17:21:58 +01:00
"context"
2020-11-11 22:29:29 +00:00
"encoding/base64"
2020-10-02 17:21:58 +01:00
2020-11-16 12:46:49 +00:00
"github.com/zeebo/errs"
2020-09-22 15:51:34 +01:00
"storj.io/common/storj"
)
// TODO: should this file be placed outside of console in nodes package?
2020-12-09 16:34:37 +00:00
// DB exposes needed by MND NodesDB functionality.
2020-10-02 17:21:58 +01:00
//
// architecture: Database
2020-12-09 16:34:37 +00:00
type DB interface {
2020-10-02 17:21:58 +01:00
// GetByID return node from NodesDB by its id.
GetByID ( ctx context . Context , id storj . NodeID ) ( Node , error )
2020-11-16 12:46:49 +00:00
// GetAll returns all connected nodes.
GetAll ( ctx context . Context ) ( [ ] Node , error )
// Add creates new node in NodesDB.
Add ( ctx context . Context , id storj . NodeID , apiSecret [ ] byte , publicAddress string ) error
2020-10-02 17:21:58 +01:00
// Remove removed node from NodesDB.
Remove ( ctx context . Context , id storj . NodeID ) error
2020-12-09 16:34:37 +00:00
// UpdateName will update name of the specified node in database.
UpdateName ( ctx context . Context , id storj . NodeID , name string ) error
2020-10-02 17:21:58 +01:00
}
2020-11-16 12:46:49 +00:00
// ErrNoNode is a special error type that indicates about absence of node in NodesDB.
var ErrNoNode = errs . Class ( "no such node" )
2020-09-22 15:51:34 +01:00
// Node is a representation of storeganode, that SNO could add to the Multinode Dashboard.
type Node struct {
ID storj . NodeID
// APISecret is a secret issued by storagenode, that will be main auth mechanism in MND <-> SNO api. is a secret issued by storagenode, that will be main auth mechanism in MND <-> SNO api.
2020-10-02 17:21:58 +01:00
APISecret [ ] byte
PublicAddress string
2020-11-16 12:46:49 +00:00
Name string
2020-09-22 15:51:34 +01:00
}
2020-11-11 22:29:29 +00:00
// APISecretFromBase64 decodes API secret from base 64 string.
func APISecretFromBase64 ( s string ) ( [ ] byte , error ) {
return base64 . URLEncoding . DecodeString ( s )
}