( ctx context.Context, conn workspacesdk.AgentConn, planPath string, )
| 13 | ) |
| 14 | |
| 15 | func ensurePlanPathResolvesToItself( |
| 16 | ctx context.Context, |
| 17 | conn workspacesdk.AgentConn, |
| 18 | planPath string, |
| 19 | ) error { |
| 20 | if conn == nil { |
| 21 | return xerrors.New("workspace connection is required") |
| 22 | } |
| 23 | |
| 24 | normalizedPlanPath := normalizeWorkspacePath(planPath) |
| 25 | resolvedPath, err := conn.ResolvePath(ctx, planPath) |
| 26 | if err != nil { |
| 27 | if resolvePathUnsupported(err) { |
| 28 | // Older workspace agents do not expose /resolve-path yet. Keep |
| 29 | // plan turns working during rolling upgrades, even though they |
| 30 | // cannot enforce the symlink guard until the agent is upgraded. |
| 31 | return nil |
| 32 | } |
| 33 | return xerrors.Errorf("resolve plan path: %w", err) |
| 34 | } |
| 35 | resolvedPath = normalizeWorkspacePath(resolvedPath) |
| 36 | if resolvedPath != normalizedPlanPath { |
| 37 | return xerrors.New(symlinkedPlanPathMessage(normalizedPlanPath, resolvedPath)) |
| 38 | } |
| 39 | |
| 40 | return nil |
| 41 | } |
| 42 | |
| 43 | func resolvePathUnsupported(err error) bool { |
| 44 | var statusErr interface{ StatusCode() int } |
no test coverage detected