Skip to content

Commit

Permalink
Add support for using stdin as a manifest
Browse files Browse the repository at this point in the history
This will help enable usage of this plugin as a transformer.

Signed-off-by: Justin Kulikauskas <[email protected]>
  • Loading branch information
JustinKuli committed Oct 21, 2022
1 parent 9688c83 commit 51d7b6c
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions internal/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,19 @@ func getManifests(policyConf *types.PolicyConfig) ([][]map[string]interface{}, e
manifestFiles := []map[string]interface{}{}
readErr := fmt.Errorf("failed to read the manifest path %s", manifest.Path)

manifestPathInfo, err := os.Stat(manifest.Path)
var manifestFD *os.File
var err error

if manifest.Path == "stdin" {
manifestFD = os.Stdin
} else {
manifestFD, err = os.Open(manifest.Path)
if err != nil {
return nil, readErr
}
}

manifestPathInfo, err := manifestFD.Stat()
if err != nil {
return nil, readErr
}
Expand Down Expand Up @@ -79,7 +91,12 @@ func getManifests(policyConf *types.PolicyConfig) ([][]map[string]interface{}, e
}
} else {
// Unmarshal the manifest in order to check for metadata patch replacement
manifestFiles, err = unmarshalManifestFile(manifest.Path)
manifestBytes, err := io.ReadAll(manifestFD)
if err != nil {
return nil, err
}

manifestFiles, err = unmarshalManifestBytes(manifestBytes)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 51d7b6c

Please sign in to comment.