LoadEncryptedFileEx loads an encrypted SOPS file from a file or stdin, returning a SOPS tree
(loader sops.EncryptedFileLoader, inputPath string, readFromStdin bool)
| 133 | |
| 134 | // LoadEncryptedFileEx loads an encrypted SOPS file from a file or stdin, returning a SOPS tree |
| 135 | func LoadEncryptedFileEx(loader sops.EncryptedFileLoader, inputPath string, readFromStdin bool) (*sops.Tree, error) { |
| 136 | var fileBytes []byte |
| 137 | var err error |
| 138 | if readFromStdin { |
| 139 | fileBytes, err = io.ReadAll(os.Stdin) |
| 140 | if err != nil { |
| 141 | return nil, NewExitError(fmt.Sprintf("Error reading from stdin: %s", err), codes.CouldNotReadInputFile) |
| 142 | } |
| 143 | } else { |
| 144 | fileBytes, err = os.ReadFile(inputPath) |
| 145 | if err != nil { |
| 146 | return nil, NewExitError(fmt.Sprintf("Error reading file: %s", err), codes.CouldNotReadInputFile) |
| 147 | } |
| 148 | } |
| 149 | path, err := filepath.Abs(inputPath) |
| 150 | if err != nil { |
| 151 | return nil, err |
| 152 | } |
| 153 | tree, err := loader.LoadEncryptedFile(fileBytes) |
| 154 | tree.FilePath = path |
| 155 | return &tree, err |
| 156 | } |
| 157 | |
| 158 | // LoadEncryptedFile loads an encrypted SOPS file, returning a SOPS tree |
| 159 | func LoadEncryptedFile(loader sops.EncryptedFileLoader, inputPath string) (*sops.Tree, error) { |
no test coverage detected