pulumi/pkg/codegen/python/gen_program_utils.go

24 lines
816 B
Go

package python
import "fmt"
// Provides code for a method which will be placed in the program preamble if deemed
// necessary. Because many tasks in Go such as reading a file require extensive error
// handling, it is much prettier to encapsulate that error handling boilerplate as its
// own function in the preamble.
func getHelperMethodIfNeeded(functionName string, indent string) (string, bool) {
switch functionName {
case "filebase64sha256":
return `def computeFilebase64sha256(path):
fileData = open(path).read().encode()
hashedData = hashlib.sha256(fileData.encode()).digest()
return base64.b64encode(hashedData).decode()`, true
case "notImplemented":
return fmt.Sprintf(`
%sdef not_implemented(msg):
%s raise NotImplementedError(msg)`, indent, indent), true
default:
return "", false
}
}