Upsert creates a new KMS and Updates PKI workers (#2187)
This commit is contained in:
25 files changed
+676
-709
No files matched your search
+49
-32
@@ -12,6 +12,26 @@ import (
|
||||
"google.golang.org/protobuf/types/known/structpb"
|
||||
)
|
||||
|
||||
type WorkerType string
|
||||
|
||||
const (
|
||||
UnknownWorkerType WorkerType = "unknown"
|
||||
KmsWorkerType WorkerType = "kms"
|
||||
PkiWorkerType WorkerType = "pki"
|
||||
)
|
||||
|
||||
func (t WorkerType) Valid() bool {
|
||||
switch t {
|
||||
case KmsWorkerType, PkiWorkerType:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (t WorkerType) String() string {
|
||||
return string(t)
|
||||
}
|
||||
|
||||
type workerAuthWorkerId struct {
|
||||
WorkerId string `mapstructure:"worker_id"`
|
||||
}
|
||||
@@ -40,6 +60,13 @@ type Worker struct {
|
||||
activeConnectionCount uint32 `gorm:"-"`
|
||||
apiTags []*Tag `gorm:"-"`
|
||||
configTags []*Tag `gorm:"-"`
|
||||
|
||||
// inputTags is not specified to be api or config tags and is not intended
|
||||
// to be read by clients. Since config tags and api tags are applied in
|
||||
// mutually exclusive contexts, inputTags is interpreted to be one or the
|
||||
// other based on the context in which the worker is passed. As such
|
||||
// inputTags should only be read when performing mutations on the database.
|
||||
inputTags []*Tag `gorm:"-"`
|
||||
}
|
||||
|
||||
// NewWorker returns a new Worker. Valid options are WithName, WithDescription
|
||||
@@ -54,7 +81,7 @@ func NewWorker(scopeId string, opt ...Option) *Worker {
|
||||
Description: opts.withDescription,
|
||||
Address: opts.withAddress,
|
||||
},
|
||||
apiTags: opts.withWorkerTags,
|
||||
inputTags: opts.withWorkerTags,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,16 +90,7 @@ func NewWorker(scopeId string, opt ...Option) *Worker {
|
||||
// are assigned to the worker reported variations of these fields.
|
||||
// All other options are ignored.
|
||||
func NewWorkerForStatus(scopeId string, opt ...Option) *Worker {
|
||||
opts := getOpts(opt...)
|
||||
return &Worker{
|
||||
Worker: &store.Worker{
|
||||
ScopeId: scopeId,
|
||||
WorkerReportedName: opts.withName,
|
||||
WorkerReportedAddress: opts.withAddress,
|
||||
WorkerReportedKeyId: opts.withKeyId,
|
||||
},
|
||||
configTags: opts.withWorkerTags,
|
||||
}
|
||||
return NewWorker(scopeId, opt...)
|
||||
}
|
||||
|
||||
// allocWorker will allocate a Worker
|
||||
@@ -100,6 +118,12 @@ func (w *Worker) clone() *Worker {
|
||||
cWorker.configTags = append(cWorker.configTags, &Tag{Key: t.Key, Value: t.Value})
|
||||
}
|
||||
}
|
||||
if w.inputTags != nil {
|
||||
cWorker.inputTags = make([]*Tag, 0, len(w.inputTags))
|
||||
for _, t := range w.inputTags {
|
||||
cWorker.inputTags = append(cWorker.inputTags, &Tag{Key: t.Key, Value: t.Value})
|
||||
}
|
||||
}
|
||||
return cWorker
|
||||
}
|
||||
|
||||
@@ -109,10 +133,7 @@ func (w *Worker) clone() *Worker {
|
||||
// in its connection status updates. If neither is available, an empty string
|
||||
// is returned.
|
||||
func (w *Worker) CanonicalAddress() string {
|
||||
if w.GetAddress() != "" {
|
||||
return w.GetAddress()
|
||||
}
|
||||
return w.GetWorkerReportedAddress()
|
||||
return w.GetAddress()
|
||||
}
|
||||
|
||||
// ActiveConnectionCount is the current number of sessions this worker is handling
|
||||
@@ -183,32 +204,28 @@ type workerAggregate struct {
|
||||
UpdateTime *timestamp.Timestamp
|
||||
Address string
|
||||
Version uint32
|
||||
Type string
|
||||
ApiTags string
|
||||
ActiveConnectionCount uint32
|
||||
// Config Fields
|
||||
WorkerReportedName string
|
||||
WorkerReportedAddress string
|
||||
LastStatusTime *timestamp.Timestamp
|
||||
WorkerReportedKeyId string
|
||||
WorkerConfigTags string
|
||||
LastStatusTime *timestamp.Timestamp
|
||||
WorkerConfigTags string
|
||||
}
|
||||
|
||||
func (a *workerAggregate) toWorker(ctx context.Context) (*Worker, error) {
|
||||
const op = "servers.(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,
|
||||
WorkerReportedAddress: a.WorkerReportedAddress,
|
||||
WorkerReportedName: a.WorkerReportedName,
|
||||
LastStatusTime: a.LastStatusTime,
|
||||
WorkerReportedKeyId: a.WorkerReportedKeyId,
|
||||
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,
|
||||
},
|
||||
activeConnectionCount: a.ActiveConnectionCount,
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user