From 2da7e29357b0bf4ec72fc703b4e10327c6b77ce3 Mon Sep 17 00:00:00 2001 From: Victor Getz Date: Fri, 5 May 2023 13:48:10 +0200 Subject: [PATCH] #31 Openstack create config does not create auto folders - Bugfix --- openstack/openstack.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/openstack/openstack.go b/openstack/openstack.go index a8a08338..14e12958 100644 --- a/openstack/openstack.go +++ b/openstack/openstack.go @@ -3,10 +3,12 @@ package openstack import ( "github.com/gophercloud/utils/openstack/clientconfig" "gopkg.in/yaml.v2" + "os" "otc-auth/common" "otc-auth/common/endpoints" "otc-auth/config" "path" + "path/filepath" ) func WriteOpenStackCloudsYaml(openStackConfigFileLocation string) { @@ -48,11 +50,13 @@ func createOpenstackCloudsYAML(clouds clientconfig.Clouds, openStackConfigFileLo } if openStackConfigFileLocation == "" { - configFilePath := path.Join(config.GetHomeFolder(), ".config", "openstack", "clouds.yaml") - config.WriteConfigFile(string(contentAsBytes), configFilePath) - } else { - config.WriteConfigFile(string(contentAsBytes), openStackConfigFileLocation) + openStackConfigFileLocation = path.Join(config.GetHomeFolder(), ".config", "openstack", "clouds.yaml") } + mkDirError := os.MkdirAll(filepath.Dir(openStackConfigFileLocation), os.ModePerm) + if mkDirError != nil { + common.OutputErrorMessageToConsoleAndExit(err.Error()) + } + config.WriteConfigFile(string(contentAsBytes), openStackConfigFileLocation) println("info: openstack clouds.yaml was updated") }