Skip to content

Commit 60b8ac5

Browse files
committed
chore: move proto to sdk conversion to agentsdk
1 parent 395f862 commit 60b8ac5

File tree

8 files changed

+423
-174
lines changed

8 files changed

+423
-174
lines changed

agent/agent.go

+2-2
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

+1-1
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

-122
This file was deleted.

coderd/agentapi/servicebanner.go

+2-1
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

+3-47
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)