-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate inline_values to path_to_inline_values for package install
Signed-off-by: Ishan Gupta <gishan@vmware.com>
- Loading branch information
1 parent
6878b5c
commit 5da45c9
Showing
11 changed files
with
139 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
Copyright © 2024 VMware, Inc. All Rights Reserved. | ||
SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
|
||
package helper | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io" | ||
"log" | ||
"os" | ||
|
||
"github.com/pkg/errors" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
// ReadYamlFile reads a yaml file from a given path. | ||
func ReadYamlFile(filePath string) (string, error) { | ||
inputFile, err := os.Open(filePath) | ||
if err != nil { | ||
return "", errors.WithMessage(err, fmt.Sprintf("Error opening the %s file.", filePath)) | ||
} | ||
|
||
defer func(inputFile *os.File) { | ||
err := inputFile.Close() | ||
if err != nil { | ||
log.Println("[ERROR] could not close file object.") | ||
} | ||
}(inputFile) | ||
|
||
buf := bytes.NewBuffer(nil) | ||
_, err = io.Copy(buf, inputFile) | ||
|
||
if err != nil { | ||
return "", err | ||
} | ||
|
||
_, err = yaml.Marshal(buf.String()) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return buf.String(), nil | ||
} | ||
|
||
// FileExists checks if a file exists in a given path. | ||
func FileExists(filePath string) bool { | ||
fileInfo, err := os.Stat(filePath) | ||
|
||
if os.IsNotExist(err) { | ||
log.Println("[ERROR] file does not exists.") | ||
return false | ||
} | ||
|
||
return !fileInfo.IsDir() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters