github.com/myhau/pulumi/pkg/v3@v3.70.2-0.20221116134521-f2775972e587/codegen/python/gen_program_utils.go (about)

     1  package python
     2  
     3  // Provides code for a method which will be placed in the program preamble if deemed
     4  // necessary. Because many tasks in Go such as reading a file require extensive error
     5  // handling, it is much prettier to encapsulate that error handling boilerplate as its
     6  // own function in the preamble.
     7  func getHelperMethodIfNeeded(functionName string) (string, bool) {
     8  	switch functionName {
     9  	case "filebase64sha256":
    10  		return `def computeFilebase64sha256(path):
    11  	fileData = open(path).read().encode()
    12  	hashedData = hashlib.sha256(fileData.encode()).digest()
    13  	return base64.b64encode(hashedData).decode()`, true
    14  	default:
    15  		return "", false
    16  	}
    17  }