Files
threshold/internal/servers/worker.go
T
Todd 2ecd550e27 Add fields to server_worker to be a boundary resource (#2083)
* Remove the server_id from session table, change it to worker_id on session_connection

This is step 1 in updating the worker table.  The worker is becoming a public resource so it must have
a public id.  We drop the server_id column on the session_connection table and add the worker_id column
so we can use the wt_public_key type.  Since db migrations are applied while the controller is offline,
it should be safe to assume all session connections are not in a running state, thus allowing us to null
out all the worker ids in the session_connection table.

For now we don't have very good enforcement of the wt_public_id contraints, since the id is currently
defined in the worker config, but this will soon change and the worker's id will be generated by the
controller.

* Updating server_id references to controller_id.

* Adding worker tag db writing test.

* Move the server table back to the top.

* Update comment for the worker object.

* Update comment for the worker table.

* Update the newWorkerId call to take a context and fix its error.

* Correct comment for the wt_network_address domain.
2022-05-18 17:03:24 -07:00

56 lines
1.5 KiB
Go

package servers
import (
"github.com/hashicorp/boundary/internal/servers/store"
"google.golang.org/protobuf/proto"
)
// A Worker is a server that provides an address which can be used to proxy
// session connections. It can be tagged with custom tags and is used when
// authorizing and establishing a session. It is owned by a scope.
type Worker struct {
*store.Worker
Tags []*Tag `gorm:"-"`
}
// A Tag is a custom key/value pair which can be attached to a Worker.
// Multiple Tags may contain the same key and different values in which
// case both key/value pairs are valid.
type Tag struct {
Key string
Value string
}
// NewWorker returns a new Worker. Valid options are WithName, WithDescription
// WithAddress, and WithWorkerTags. All other options are ignored.
func NewWorker(scopeId string, opt ...Option) *Worker {
opts := getOpts(opt...)
return &Worker{
Worker: &store.Worker{
ScopeId: scopeId,
PublicId: opts.withPublicId,
Name: opts.withName,
Description: opts.withDescription,
Address: opts.withAddress,
},
Tags: opts.withWorkerTags,
}
}
func (w *Worker) clone() *Worker {
tags := make([]*Tag, 0, len(w.Tags))
for _, t := range w.Tags {
tags = append(tags, &Tag{Key: t.Key, Value: t.Value})
}
cw := proto.Clone(w.Worker)
return &Worker{
Worker: cw.(*store.Worker),
Tags: tags,
}
}
// TableName overrides the table name used by Worker to `server_worker`
func (Worker) TableName() string {
return "server_worker"
}