Skip to content

Commit b3be947

Browse files
authored
Merge pull request #21 from gruntwork-io/open-runbooks-from-dirs
Allow Runbooks to be opened by specifying directories, not just full paths
2 parents 3bde965 + 600c0d4 commit b3be947

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

api/server.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ func StartServer(runbookPath string, port int, outputPath string) error {
9191
r.SetTrustedProxies(nil)
9292

9393
// API endpoint to serve the runbook file contents
94-
r.GET("/api/runbook", HandleRunbookRequest(runbookPath, false, true))
94+
r.GET("/api/runbook", HandleRunbookRequest(resolvedPath, false, true))
9595

9696
// Set up common routes
97-
setupCommonRoutes(r, runbookPath, outputPath, registry, true)
97+
setupCommonRoutes(r, resolvedPath, outputPath, registry, true)
9898

9999
// listen and serve on localhost:$port only (security: prevent remote access)
100100
return r.Run("127.0.0.1:" + fmt.Sprintf("%d", port))
@@ -131,10 +131,10 @@ func StartBackendServer(runbookPath string, port int, outputPath string) error {
131131
}))
132132

133133
// API endpoint to serve the runbook file contents
134-
r.GET("/api/runbook", HandleRunbookRequest(runbookPath, false, true))
134+
r.GET("/api/runbook", HandleRunbookRequest(resolvedPath, false, true))
135135

136136
// Set up common routes (includes all other endpoints)
137-
setupCommonRoutes(r, runbookPath, outputPath, registry, true)
137+
setupCommonRoutes(r, resolvedPath, outputPath, registry, true)
138138

139139
// listen and serve on localhost:$port only (security: prevent remote access)
140140
return r.Run("127.0.0.1:" + fmt.Sprintf("%d", port))
@@ -173,13 +173,13 @@ func StartServerWithWatch(runbookPath string, port int, outputPath string, useEx
173173
r.SetTrustedProxies(nil)
174174

175175
// API endpoint to serve the runbook file contents
176-
r.GET("/api/runbook", HandleRunbookRequest(runbookPath, true, useExecutableRegistry))
176+
r.GET("/api/runbook", HandleRunbookRequest(resolvedPath, true, useExecutableRegistry))
177177

178178
// SSE endpoint for file change notifications
179179
r.GET("/api/watch", HandleWatchSSE(fileWatcher))
180180

181181
// Set up common routes
182-
setupCommonRoutes(r, runbookPath, outputPath, registry, useExecutableRegistry)
182+
setupCommonRoutes(r, resolvedPath, outputPath, registry, useExecutableRegistry)
183183

184184
// listen and serve on localhost:$port only (security: prevent remote access)
185185
return r.Run("127.0.0.1:" + fmt.Sprintf("%d", port))

api/watcher.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,15 @@ func resolveRunbookPath(path string) (string, error) {
165165
candidates := []string{"runbook.mdx", "runbook.md"}
166166
for _, candidate := range candidates {
167167
fullPath := filepath.Join(path, candidate)
168+
slog.Info("Looking for runbook", "path", fullPath)
168169
if _, err := os.Stat(fullPath); err == nil {
169170
return fullPath, nil
170171
} else if !os.IsNotExist(err) {
171172
// An unexpected error occurred (e.g., permissions). Propagate it.
172173
return "", fmt.Errorf("error checking for runbook %q: %w", fullPath, err)
173174
}
174175
}
175-
return "", os.ErrNotExist
176+
return "", fmt.Errorf("no runbook found in directory %s", path)
176177
}
177178

178179
return path, nil

0 commit comments

Comments
 (0)