Skip to content

Commit d5955e3

Browse files
committed
chore: move proto to sdk conversion to agentsdk
1 parent 6fcd156 commit d5955e3

File tree

8 files changed

+423
-174
lines changed

8 files changed

+423
-174
lines changed

agent/agent.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,7 @@ func (a *agent) fetchServiceBannerLoop(ctx context.Context, aAPI proto.DRPCAgent
677677
a.logger.Error(ctx, "failed to update service banner", slog.Error(err))
678678
return err
679679
}
680-
serviceBanner := proto.SDKServiceBannerFromProto(sbp)
680+
serviceBanner := agentsdk.ServiceBannerFromProto(sbp)
681681
a.serviceBanner.Store(&serviceBanner)
682682
}
683683
}
@@ -710,7 +710,7 @@ func (a *agent) run(ctx context.Context) error {
710710
if err != nil {
711711
return xerrors.Errorf("fetch service banner: %w", err)
712712
}
713-
serviceBanner := proto.SDKServiceBannerFromProto(sbp)
713+
serviceBanner := agentsdk.ServiceBannerFromProto(sbp)
714714
a.serviceBanner.Store(&serviceBanner)
715715

716716
manifest, err := a.client.Manifest(ctx)

agent/agenttest/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ func (f *FakeAgentAPI) GetServiceBanner(context.Context, *agentproto.GetServiceB
277277
if err != nil {
278278
return nil, err
279279
}
280-
return agentproto.ServiceBannerFromSDK(sb), nil
280+
return agentsdk.ProtoFromServiceBanner(sb), nil
281281
}
282282

283283
func (*FakeAgentAPI) UpdateStats(context.Context, *agentproto.UpdateStatsRequest) (*agentproto.UpdateStatsResponse, error) {

agent/proto/convert.go

Lines changed: 0 additions & 122 deletions
This file was deleted.

coderd/agentapi/servicebanner.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/coder/coder/v2/agent/proto"
1010
"github.com/coder/coder/v2/coderd/appearance"
11+
"github.com/coder/coder/v2/codersdk/agentsdk"
1112
)
1213

1314
type ServiceBannerAPI struct {
@@ -19,5 +20,5 @@ func (a *ServiceBannerAPI) GetServiceBanner(ctx context.Context, _ *proto.GetSer
1920
if err != nil {
2021
return nil, xerrors.Errorf("fetch appearance: %w", err)
2122
}
22-
return proto.ServiceBannerFromSDK(cfg.ServiceBanner), nil
23+
return agentsdk.ProtoFromServiceBanner(cfg.ServiceBanner), nil
2324
}

coderd/workspaceagents.go

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -179,60 +179,16 @@ func (api *API) workspaceAgentManifest(rw http.ResponseWriter, r *http.Request)
179179
})
180180
return
181181
}
182-
183-
apps, err := agentproto.SDKAppsFromProto(manifest.Apps)
184-
if err != nil {
185-
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
186-
Message: "Internal error converting workspace agent apps.",
187-
Detail: err.Error(),
188-
})
189-
return
190-
}
191-
192-
scripts, err := agentproto.SDKAgentScriptsFromProto(manifest.Scripts)
193-
if err != nil {
194-
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
195-
Message: "Internal error converting workspace agent scripts.",
196-
Detail: err.Error(),
197-
})
198-
return
199-
}
200-
201-
agentID, err := uuid.FromBytes(manifest.AgentId)
182+
sdkManifest, err := agentsdk.ManifestFromProto(manifest)
202183
if err != nil {
203184
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
204-
Message: "Internal error converting workspace agent ID.",
205-
Detail: err.Error(),
206-
})
207-
return
208-
}
209-
workspaceID, err := uuid.FromBytes(manifest.WorkspaceId)
210-
if err != nil {
211-
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
212-
Message: "Internal error converting workspace ID.",
185+
Message: "Internal error converting manifest.",
213186
Detail: err.Error(),
214187
})
215188
return
216189
}
217190

218-
httpapi.Write(ctx, rw, http.StatusOK, agentsdk.Manifest{
219-
AgentID: agentID,
220-
AgentName: manifest.AgentName,
221-
OwnerName: manifest.OwnerUsername,
222-
WorkspaceID: workspaceID,
223-
WorkspaceName: manifest.WorkspaceName,
224-
Apps: apps,
225-
Scripts: scripts,
226-
DERPMap: tailnet.DERPMapFromProto(manifest.DerpMap),
227-
DERPForceWebSockets: manifest.DerpForceWebsockets,
228-
GitAuthConfigs: int(manifest.GitAuthConfigs),
229-
EnvironmentVariables: manifest.EnvironmentVariables,
230-
Directory: manifest.Directory,
231-
VSCodePortProxyURI: manifest.VsCodePortProxyUri,
232-
MOTDFile: manifest.MotdPath,
233-
DisableDirectConnections: manifest.DisableDirectConnections,
234-
Metadata: agentproto.SDKAgentMetadataDescriptionsFromProto(manifest.Metadata),
235-
})
191+
httpapi.Write(ctx, rw, http.StatusOK, sdkManifest)
236192
}
237193

238194
const AgentAPIVersionREST = "1.0"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy