@@ -12,6 +12,7 @@ import (
12
12
"github.com/google/uuid"
13
13
"golang.org/x/sync/errgroup"
14
14
"golang.org/x/xerrors"
15
+ "google.golang.org/protobuf/types/known/durationpb"
15
16
"tailscale.com/tailcfg"
16
17
17
18
agentproto "github.com/coder/coder/v2/agent/proto"
@@ -128,7 +129,7 @@ func (a *ManifestAPI) GetManifest(ctx context.Context, _ *agentproto.GetManifest
128
129
}
129
130
}
130
131
131
- apps , err := agentproto . DBAppsToProto (dbApps , workspaceAgent , owner .Username , workspace )
132
+ apps , err := dbAppsToProto (dbApps , workspaceAgent , owner .Username , workspace )
132
133
if err != nil {
133
134
return nil , xerrors .Errorf ("converting workspace apps: %w" , err )
134
135
}
@@ -146,8 +147,90 @@ func (a *ManifestAPI) GetManifest(ctx context.Context, _ *agentproto.GetManifest
146
147
DerpForceWebsockets : a .DerpForceWebSockets ,
147
148
148
149
DerpMap : tailnet .DERPMapToProto (a .DerpMapFn ()),
149
- Scripts : agentproto . DBAgentScriptsToProto (scripts ),
150
+ Scripts : dbAgentScriptsToProto (scripts ),
150
151
Apps : apps ,
151
- Metadata : agentproto .DBAgentMetadataToProtoDescription (metadata ),
152
+ Metadata : dbAgentMetadataToProtoDescription (metadata ),
153
+ }, nil
154
+ }
155
+
156
+ func dbAgentMetadataToProtoDescription (metadata []database.WorkspaceAgentMetadatum ) []* agentproto.WorkspaceAgentMetadata_Description {
157
+ ret := make ([]* agentproto.WorkspaceAgentMetadata_Description , len (metadata ))
158
+ for i , metadatum := range metadata {
159
+ ret [i ] = dbAgentMetadatumToProtoDescription (metadatum )
160
+ }
161
+ return ret
162
+ }
163
+
164
+ func dbAgentMetadatumToProtoDescription (metadatum database.WorkspaceAgentMetadatum ) * agentproto.WorkspaceAgentMetadata_Description {
165
+ return & agentproto.WorkspaceAgentMetadata_Description {
166
+ DisplayName : metadatum .DisplayName ,
167
+ Key : metadatum .Key ,
168
+ Script : metadatum .Script ,
169
+ Interval : durationpb .New (time .Duration (metadatum .Interval )),
170
+ Timeout : durationpb .New (time .Duration (metadatum .Timeout )),
171
+ }
172
+ }
173
+
174
+ func dbAgentScriptsToProto (scripts []database.WorkspaceAgentScript ) []* agentproto.WorkspaceAgentScript {
175
+ ret := make ([]* agentproto.WorkspaceAgentScript , len (scripts ))
176
+ for i , script := range scripts {
177
+ ret [i ] = dbAgentScriptToProto (script )
178
+ }
179
+ return ret
180
+ }
181
+
182
+ func dbAgentScriptToProto (script database.WorkspaceAgentScript ) * agentproto.WorkspaceAgentScript {
183
+ return & agentproto.WorkspaceAgentScript {
184
+ LogSourceId : script .LogSourceID [:],
185
+ LogPath : script .LogPath ,
186
+ Script : script .Script ,
187
+ Cron : script .Cron ,
188
+ RunOnStart : script .RunOnStart ,
189
+ RunOnStop : script .RunOnStop ,
190
+ StartBlocksLogin : script .StartBlocksLogin ,
191
+ Timeout : durationpb .New (time .Duration (script .TimeoutSeconds ) * time .Second ),
192
+ }
193
+ }
194
+
195
+ func dbAppsToProto (dbApps []database.WorkspaceApp , agent database.WorkspaceAgent , ownerName string , workspace database.Workspace ) ([]* agentproto.WorkspaceApp , error ) {
196
+ ret := make ([]* agentproto.WorkspaceApp , len (dbApps ))
197
+ for i , dbApp := range dbApps {
198
+ var err error
199
+ ret [i ], err = dbAppToProto (dbApp , agent , ownerName , workspace )
200
+ if err != nil {
201
+ return nil , xerrors .Errorf ("parse app %v (%q): %w" , i , dbApp .Slug , err )
202
+ }
203
+ }
204
+ return ret , nil
205
+ }
206
+
207
+ func dbAppToProto (dbApp database.WorkspaceApp , agent database.WorkspaceAgent , ownerName string , workspace database.Workspace ) (* agentproto.WorkspaceApp , error ) {
208
+ sharingLevelRaw , ok := agentproto .WorkspaceApp_SharingLevel_value [strings .ToUpper (string (dbApp .SharingLevel ))]
209
+ if ! ok {
210
+ return nil , xerrors .Errorf ("unknown app sharing level: %q" , dbApp .SharingLevel )
211
+ }
212
+
213
+ healthRaw , ok := agentproto .WorkspaceApp_Health_value [strings .ToUpper (string (dbApp .Health ))]
214
+ if ! ok {
215
+ return nil , xerrors .Errorf ("unknown app health: %q" , dbApp .SharingLevel )
216
+ }
217
+
218
+ return & agentproto.WorkspaceApp {
219
+ Id : dbApp .ID [:],
220
+ Url : dbApp .Url .String ,
221
+ External : dbApp .External ,
222
+ Slug : dbApp .Slug ,
223
+ DisplayName : dbApp .DisplayName ,
224
+ Command : dbApp .Command .String ,
225
+ Icon : dbApp .Icon ,
226
+ Subdomain : dbApp .Subdomain ,
227
+ SubdomainName : db2sdk .AppSubdomain (dbApp , agent .Name , workspace .Name , ownerName ),
228
+ SharingLevel : agentproto .WorkspaceApp_SharingLevel (sharingLevelRaw ),
229
+ Healthcheck : & agentproto.WorkspaceApp_Healthcheck {
230
+ Url : dbApp .HealthcheckUrl ,
231
+ Interval : durationpb .New (time .Duration (dbApp .HealthcheckInterval ) * time .Second ),
232
+ Threshold : dbApp .HealthcheckThreshold ,
233
+ },
234
+ Health : agentproto .WorkspaceApp_Health (healthRaw ),
152
235
}, nil
153
236
}
0 commit comments