From 2efd96fe95b32bdecd382330a8764374d5bbd4dd Mon Sep 17 00:00:00 2001 From: Adelina Mahu <33446703+adelinag08@users.noreply.github.com> Date: Thu, 7 Mar 2024 13:40:18 +0100 Subject: [PATCH] Remove k8s trim (#27) --- pkg/cmd/spark/configuration.go | 4 ---- pkg/cmd/util/file/file.go | 9 ++++++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/cmd/spark/configuration.go b/pkg/cmd/spark/configuration.go index 9055024..048e12c 100644 --- a/pkg/cmd/spark/configuration.go +++ b/pkg/cmd/spark/configuration.go @@ -5,7 +5,6 @@ import ( "github.com/SneaksAndData/esd-services-api-client-go/spark" "github.com/spf13/cobra" "snd-cli/pkg/cmdutil" - "strings" ) var name string @@ -15,9 +14,6 @@ func NewCmdConfiguration(authServiceFactory *cmdutil.AuthServiceFactory, service Use: "configuration", Short: "Get a deployed SparkJob configuration", RunE: func(cmd *cobra.Command, args []string) error { - if strings.HasPrefix(authProvider, "k8s") { - authProvider = strings.TrimPrefix("k8s-", authProvider) - } authService, err := cmdutil.InitializeAuthService(url, env, authProvider, *authServiceFactory) if err != nil { return err diff --git a/pkg/cmd/util/file/file.go b/pkg/cmd/util/file/file.go index 76ff16e..e8952d5 100644 --- a/pkg/cmd/util/file/file.go +++ b/pkg/cmd/util/file/file.go @@ -5,6 +5,7 @@ import ( "errors" "fmt" "os" + "path" "path/filepath" ) @@ -36,7 +37,7 @@ func (f File) IsValidPath() bool { // CreateDirectory creates a directory by using the specified path. func (f File) CreateDirectory() error { - err := os.MkdirAll(f.FilePath, 0755) // Use MkdirAll to simplify + err := os.MkdirAll(path.Dir(f.FilePath), 0755) // Use MkdirAll to simplify if err != nil { return fmt.Errorf("failed to create directory: %w", err) } @@ -45,6 +46,12 @@ func (f File) CreateDirectory() error { // WriteToFile writes data to the specified file path. func (f File) WriteToFile(data string) error { + if !f.IsValidPath() { + err := f.CreateDirectory() + if err != nil { + return err + } + } file, err := os.OpenFile(f.FilePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) if err != nil { return fmt.Errorf("failed to open file: %w", err)