From f3e19fc4fb8536f80b217456369e9d1190027a32 Mon Sep 17 00:00:00 2001 From: Rohan Sharma <117426013+RS-labhub@users.noreply.github.com> Date: Fri, 28 Jun 2024 17:20:31 +0530 Subject: [PATCH] fix: devcontainer config file name validation (#714) Signed-off-by: Rohan Sharma --- pkg/views/workspace/create/configuration.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pkg/views/workspace/create/configuration.go b/pkg/views/workspace/create/configuration.go index 6169be937f..00317e9db6 100644 --- a/pkg/views/workspace/create/configuration.go +++ b/pkg/views/workspace/create/configuration.go @@ -6,6 +6,7 @@ package create import ( "errors" "log" + "path/filepath" "github.com/charmbracelet/bubbles/key" "github.com/charmbracelet/huh" @@ -145,6 +146,14 @@ func ConfigureProjects(projectList *[]apiclient.CreateWorkspaceRequestProject, d return ConfigureProjects(projectList, defaults) } +func validateDevcontainerFilename(filename string) error { + baseName := filepath.Base(filename) + if baseName != "devcontainer.json" && baseName != ".devcontainer.json" { + return errors.New("filename must be devcontainer.json or .devcontainer.json") + } + return nil +} + func GetProjectConfigurationForm(projectConfiguration *ProjectConfigurationData) *huh.Form { buildOptions := []huh.Option[string]{ {Key: "Automatic", Value: string(AUTOMATIC)}, @@ -175,12 +184,7 @@ func GetProjectConfigurationForm(projectConfiguration *ProjectConfigurationData) huh.NewGroup( huh.NewInput(). Title("Devcontainer file path"). - Value(&projectConfiguration.DevcontainerFilePath).Validate(func(s string) error { - if s == "" { - return errors.New("devcontainer file path is required") - } - return nil - }), + Value(&projectConfiguration.DevcontainerFilePath).Validate(validateDevcontainerFilename), ).WithHideFunc(func() bool { return projectConfiguration.BuildChoice != string(DEVCONTAINER) }),