handleManifest returns a function that fetches and processes the manifest
(manifestOK *checkpoint)
| 1236 | |
| 1237 | // handleManifest returns a function that fetches and processes the manifest |
| 1238 | func (a *agent) handleManifest(manifestOK *checkpoint) func(ctx context.Context, aAPI proto.DRPCAgentClient28) error { |
| 1239 | return func(ctx context.Context, aAPI proto.DRPCAgentClient28) error { |
| 1240 | var ( |
| 1241 | sentResult = false |
| 1242 | err error |
| 1243 | ) |
| 1244 | defer func() { |
| 1245 | if !sentResult { |
| 1246 | manifestOK.complete(err) |
| 1247 | } |
| 1248 | }() |
| 1249 | mpRaw, err := aAPI.GetManifest(ctx, &proto.GetManifestRequest{}) |
| 1250 | if err != nil { |
| 1251 | return xerrors.Errorf("fetch metadata: %w", err) |
| 1252 | } |
| 1253 | a.logger.Info(ctx, "fetched manifest") |
| 1254 | |
| 1255 | // Strip secrets from the proto manifest immediately to avoid accidental leakage. |
| 1256 | secrets := agentsdk.SecretsFromProto(mpRaw.Secrets) |
| 1257 | mpRaw.Secrets = nil |
| 1258 | mp, ok := googleproto.Clone(mpRaw).(*proto.Manifest) |
| 1259 | if !ok { |
| 1260 | return xerrors.Errorf("clone manifest: type mismatch") |
| 1261 | } |
| 1262 | |
| 1263 | manifest, err := agentsdk.ManifestFromProto(mp) |
| 1264 | if err != nil { |
| 1265 | a.logger.Critical(ctx, "failed to convert manifest", slog.F("manifest", mp), slog.Error(err)) |
| 1266 | return xerrors.Errorf("convert manifest: %w", err) |
| 1267 | } |
| 1268 | if manifest.AgentID == uuid.Nil { |
| 1269 | return xerrors.New("nil agentID returned by manifest") |
| 1270 | } |
| 1271 | if manifest.ParentID != uuid.Nil { |
| 1272 | // This is a sub agent, disable all the features that should not |
| 1273 | // be used by sub agents. |
| 1274 | a.logger.Debug(ctx, "sub agent detected, disabling features", |
| 1275 | slog.F("parent_id", manifest.ParentID), |
| 1276 | slog.F("agent_id", manifest.AgentID), |
| 1277 | ) |
| 1278 | if a.devcontainers { |
| 1279 | a.logger.Info(ctx, "devcontainers are not supported on sub agents, disabling feature") |
| 1280 | a.devcontainers = false |
| 1281 | } |
| 1282 | } |
| 1283 | a.client.RewriteDERPMap(manifest.DERPMap) |
| 1284 | |
| 1285 | // Expand the directory and send it back to coderd so external |
| 1286 | // applications that rely on the directory can use it. |
| 1287 | // |
| 1288 | // An example is VS Code Remote, which must know the directory |
| 1289 | // before initializing a connection. |
| 1290 | manifest.Directory, err = expandPathToAbs(manifest.Directory) |
| 1291 | if err != nil { |
| 1292 | return xerrors.Errorf("expand directory: %w", err) |
| 1293 | } |
| 1294 | // Normalize all devcontainer paths by making them absolute. |
| 1295 | manifest.Devcontainers = agentcontainers.ExpandAllDevcontainerPaths(a.logger, expandPathToAbs, manifest.Devcontainers) |
no test coverage detected