mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-08 19:28:16 +00:00
create config dir if it doesn't exist
This commit is contained in:
@@ -42,7 +42,7 @@ var vaultSetCmd = &cobra.Command{
|
|||||||
|
|
||||||
err = util.WriteConfigFile(&configFile)
|
err = util.WriteConfigFile(&configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("Unable to set vault to [%s] because an error occurred when saving the config file [err=%s]")
|
log.Errorf("Unable to set vault to [%s] because an error occurred when saving the config file [err=%s]", wantedVaultTypeName, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ func GetHomeDir() (string, error) {
|
|||||||
return directory, err
|
return directory, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// write file to given path. If path does not exist throw error
|
||||||
func WriteToFile(fileName string, dataToWrite []byte, filePerm os.FileMode) error {
|
func WriteToFile(fileName string, dataToWrite []byte, filePerm os.FileMode) error {
|
||||||
err := os.WriteFile(fileName, dataToWrite, filePerm)
|
err := os.WriteFile(fileName, dataToWrite, filePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ func GetConfigFile() (models.ConfigFile, error) {
|
|||||||
|
|
||||||
// Write a ConfigFile to disk. Raise error if unable to save the model to ask
|
// Write a ConfigFile to disk. Raise error if unable to save the model to ask
|
||||||
func WriteConfigFile(configFile *models.ConfigFile) error {
|
func WriteConfigFile(configFile *models.ConfigFile) error {
|
||||||
fullConfigFilePath, _, err := GetFullConfigFilePath()
|
fullConfigFilePath, fullConfigFileDirPath, err := GetFullConfigFilePath()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("writeConfigFile: unable to write config file because an error occurred when getting config file path [err=%s]", err)
|
return fmt.Errorf("writeConfigFile: unable to write config file because an error occurred when getting config file path [err=%s]", err)
|
||||||
}
|
}
|
||||||
@@ -197,8 +197,20 @@ func WriteConfigFile(configFile *models.ConfigFile) error {
|
|||||||
return fmt.Errorf("writeConfigFile: unable to write config file because an error occurred when marshalling the config file [err=%s]", err)
|
return fmt.Errorf("writeConfigFile: unable to write config file because an error occurred when marshalling the config file [err=%s]", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if config folder exists and if not create it
|
||||||
|
if _, err := os.Stat(fullConfigFileDirPath); errors.Is(err, os.ErrNotExist) {
|
||||||
|
err := os.Mkdir(fullConfigFileDirPath, os.ModePerm)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Create file in directory
|
// Create file in directory
|
||||||
err = WriteToFile(fullConfigFilePath, configFileMarshalled, os.ModePerm)
|
err = os.WriteFile(fullConfigFilePath, configFileMarshalled, os.ModePerm)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("writeConfigFile: Unable to write to file [err=%s]", err)
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("writeConfigFile: unable to write config file because an error occurred when write the config to file [err=%s]", err)
|
return fmt.Errorf("writeConfigFile: unable to write config file because an error occurred when write the config to file [err=%s]", err)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user