mirror of
https://github.com/coder/coder.git
synced 2025-07-13 21:36:50 +00:00
WIP: very basic manifest stream from server to agent
Signed-off-by: Danny Kopping <danny@coder.com>
This commit is contained in:
@ -96,6 +96,7 @@ func New(opts Options) *API {
|
||||
Database: opts.Database,
|
||||
DerpMapFn: opts.DerpMapFn,
|
||||
WorkspaceID: opts.WorkspaceID,
|
||||
Log: opts.Log.Named("manifests"),
|
||||
}
|
||||
|
||||
api.AnnouncementBannerAPI = &AnnouncementBannerAPI{
|
||||
|
@ -1,6 +1,7 @@
|
||||
package agentapi
|
||||
|
||||
import (
|
||||
"cdr.dev/slog"
|
||||
"context"
|
||||
"database/sql"
|
||||
"net/url"
|
||||
@ -34,6 +35,31 @@ type ManifestAPI struct {
|
||||
AgentFn func(context.Context) (database.WorkspaceAgent, error)
|
||||
Database database.Store
|
||||
DerpMapFn func() *tailcfg.DERPMap
|
||||
Log slog.Logger
|
||||
}
|
||||
|
||||
func (a *ManifestAPI) StreamManifests(in *agentproto.GetManifestRequest, stream agentproto.DRPCAgent_StreamManifestsStream) error {
|
||||
streamCtx := dbauthz.AsSystemRestricted(stream.Context()) // TODO:
|
||||
|
||||
defer func() {
|
||||
if err := stream.CloseSend(); err != nil {
|
||||
a.Log.Error(streamCtx, "error closing stream: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
for {
|
||||
resp, err := a.GetManifest(streamCtx, in)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("receive manifest: %w", err)
|
||||
}
|
||||
|
||||
err = stream.Send(resp)
|
||||
if err != nil {
|
||||
return xerrors.Errorf("send manifest: %w", err)
|
||||
}
|
||||
|
||||
time.Sleep(time.Second * 5)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *ManifestAPI) GetManifest(ctx context.Context, _ *agentproto.GetManifestRequest) (*agentproto.Manifest, error) {
|
||||
|
Reference in New Issue
Block a user