feat(workers): worker operational state (#2427)
* feat(workers): worker operational state
This commit is contained in:
1 parent
f3f0c55d91
commit
fc0ead73e6
17 files changed
+696
-166
No files matched your search
+50
-21
@@ -12,12 +12,18 @@ import (
|
||||
"google.golang.org/protobuf/types/known/structpb"
|
||||
)
|
||||
|
||||
type WorkerType string
|
||||
type (
|
||||
WorkerType string
|
||||
OperationalState string
|
||||
)
|
||||
|
||||
const (
|
||||
UnknownWorkerType WorkerType = "unknown"
|
||||
KmsWorkerType WorkerType = "kms"
|
||||
PkiWorkerType WorkerType = "pki"
|
||||
UnknownWorkerType WorkerType = "unknown"
|
||||
KmsWorkerType WorkerType = "kms"
|
||||
PkiWorkerType WorkerType = "pki"
|
||||
ActiveOperationalState OperationalState = "active"
|
||||
ShutdownOperationalState OperationalState = "shutdown"
|
||||
UnknownOperationalState OperationalState = "unknown"
|
||||
)
|
||||
|
||||
func (t WorkerType) Valid() bool {
|
||||
@@ -29,13 +35,33 @@ func (t WorkerType) Valid() bool {
|
||||
}
|
||||
|
||||
func (t WorkerType) String() string {
|
||||
return string(t)
|
||||
switch t {
|
||||
case KmsWorkerType, PkiWorkerType:
|
||||
return string(t)
|
||||
}
|
||||
return string(UnknownWorkerType)
|
||||
}
|
||||
|
||||
type workerAuthWorkerId struct {
|
||||
WorkerId string `mapstructure:"worker_id"`
|
||||
}
|
||||
|
||||
func ValidOperationalState(s string) bool {
|
||||
switch s {
|
||||
case ActiveOperationalState.String(), ShutdownOperationalState.String():
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (t OperationalState) String() string {
|
||||
switch t {
|
||||
case ActiveOperationalState, ShutdownOperationalState:
|
||||
return string(t)
|
||||
}
|
||||
return string(UnknownOperationalState)
|
||||
}
|
||||
|
||||
// AttachWorkerIdToState accepts a workerId and creates a struct for use with the Nodeenrollment lib
|
||||
// This is intended for use in worker authorization; AuthorizeNode in the lib accepts the option WithState
|
||||
// so that the workerId is passed through to storage and associated with a WorkerAuth record
|
||||
@@ -79,11 +105,12 @@ func NewWorker(scopeId string, opt ...Option) *Worker {
|
||||
opts := GetOpts(opt...)
|
||||
return &Worker{
|
||||
Worker: &store.Worker{
|
||||
ScopeId: scopeId,
|
||||
Name: opts.withName,
|
||||
Description: opts.withDescription,
|
||||
Address: opts.withAddress,
|
||||
ReleaseVersion: opts.withReleaseVersion,
|
||||
ScopeId: scopeId,
|
||||
Name: opts.withName,
|
||||
Description: opts.withDescription,
|
||||
Address: opts.withAddress,
|
||||
ReleaseVersion: opts.withReleaseVersion,
|
||||
OperationalState: opts.withOperationalState,
|
||||
},
|
||||
inputTags: opts.withWorkerTags,
|
||||
}
|
||||
@@ -196,6 +223,7 @@ type workerAggregate struct {
|
||||
ReleaseVersion string
|
||||
ApiTags string
|
||||
ActiveConnectionCount uint32
|
||||
OperationalState string
|
||||
// Config Fields
|
||||
LastStatusTime *timestamp.Timestamp
|
||||
WorkerConfigTags string
|
||||
@@ -205,17 +233,18 @@ func (a *workerAggregate) toWorker(ctx context.Context) (*Worker, error) {
|
||||
const op = "server.(workerAggregate).toWorker"
|
||||
worker := &Worker{
|
||||
Worker: &store.Worker{
|
||||
PublicId: a.PublicId,
|
||||
Name: a.Name,
|
||||
Description: a.Description,
|
||||
Address: a.Address,
|
||||
CreateTime: a.CreateTime,
|
||||
UpdateTime: a.UpdateTime,
|
||||
ScopeId: a.ScopeId,
|
||||
Version: a.Version,
|
||||
LastStatusTime: a.LastStatusTime,
|
||||
Type: a.Type,
|
||||
ReleaseVersion: a.ReleaseVersion,
|
||||
PublicId: a.PublicId,
|
||||
Name: a.Name,
|
||||
Description: a.Description,
|
||||
Address: a.Address,
|
||||
CreateTime: a.CreateTime,
|
||||
UpdateTime: a.UpdateTime,
|
||||
ScopeId: a.ScopeId,
|
||||
Version: a.Version,
|
||||
LastStatusTime: a.LastStatusTime,
|
||||
Type: a.Type,
|
||||
ReleaseVersion: a.ReleaseVersion,
|
||||
OperationalState: a.OperationalState,
|
||||
},
|
||||
activeConnectionCount: a.ActiveConnectionCount,
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user