helpers

package
v0.29.2-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 13, 2025 License: MPL-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolPtr

func BoolPtr(b bool) *bool

Utility function to convert a bool to *bool

func ByteStringToBase64

func ByteStringToBase64(data []byte) string

ByteStringToBase64 converts a byte slice to a base64-encoded string

func CalculateMd5

func CalculateMd5(filePath string) (string, error)

CalculateMd5 calculates the MD5 checksum of a file.

func DecodeBase64ToString

func DecodeBase64ToString(ctx context.Context, encoded string) types.String

DecodeBase64ToString decodes a base64-encoded string and returns a Terraform Framework string. If decoding fails, it logs a warning and returns the original string as fallback.

func ExtractGUIDFromString

func ExtractGUIDFromString(stringToExtractFrom string) (string, error)

ExtractGUIDFromString extracts a GUID from the beginning of a string.

func GetEnvBool

func GetEnvBool(k string, defaultValue bool) bool

GetEnvBool is a helper function that returns the boolean value of the given environment variable, if one exists, or the default value otherwise.

func GetEnvInt64

func GetEnvInt64(k string, defaultValue types.Int64) types.Int64

GetEnvInt64 is a helper function that returns the types.Int64Value of the given environment variable, if one exists, or the default value otherwise.

func GetEnvString

func GetEnvString(k string, defaultValue string) string

GetEnvString is a helper function that returns the value of the given environment variable, if one exists, or the default value otherwise.

func GetEnvStringSlice

func GetEnvStringSlice(k string, defaultValue []string) []string

GetEnvStringSlice is a helper function that returns a slice of strings based on the environment variable (if set) or the provided default value. The environment variable should be a comma-separated string.

func GetFirstEnvString

func GetFirstEnvString(ks []string, defaultValue string) string

GetFirstEnvString is a helper function that returns the value of the first environment variable in the given list that returns a non-empty value. If none of the environment variables return a value, the default value is returned.

func IsDebugMode

func IsDebugMode() bool

IsDebugMode checks if the M365_DEBUG_MODE environment variable is set to true

func JoinWithSeparator

func JoinWithSeparator(strs []string, sep string) string

JoinWithSeparator joins a slice of strings with the specified separator

func ParseCertificateData

func ParseCertificateData(ctx context.Context, certData []byte, password []byte) ([]*x509.Certificate, crypto.PrivateKey, error)

ParseCertificateData decodes and parses PKCS#12 data, extracting certificates and a private key.

This function attempts to decode PKCS#12 data using the provided password. It extracts the certificate chain (including the end-entity certificate and any CA certificates), as well as the private key associated with the end-entity certificate.

The function performs several validations: - It checks if any certificates are present in the decoded data. - It verifies the presence of a private key. - It ensures the private key is of RSA type.

The function logs debug, error, and info messages at various stages of the process.

Parameters:

  • ctx: A context.Context for logging and potential cancellation.
  • certData: A byte slice containing the PKCS#12 data to be parsed.
  • password: A byte slice containing the password to decrypt the PKCS#12 data.

Returns:

  • []*x509.Certificate: A slice of parsed X.509 certificates, with the end-entity certificate as the first element, followed by any CA certificates.
  • crypto.PrivateKey: The private key associated with the end-entity certificate.
  • error: An error if any step of the parsing or validation process fails. This will be nil if the function executes successfully.

Possible errors:

  • Failure to parse PKCS#12 data
  • No certificates found in the PKCS#12 data
  • No private key found in the PKCS#12 data
  • Private key is not of RSA type

Usage example:

certs, privKey, err := ParseCertificateData(ctx, pkcs12Data, []byte("password"))
if err != nil {
    // Handle error
}
// Use certs and privKey as needed

func ParseHCLFile

func ParseHCLFile(filePath string) (string, error)

ParseHCLFile securely loads a Terraform configuration file from the specified path. Security measures: - Validates file extensions (.tf, .hcl) - Prevents path traversal attacks - Restricts access to files within the project directory - Comprehensive error logging and validation

func ParseJSONFile

func ParseJSONFile(filePath string) (string, error)

ParseJSONFile securely loads a JSON file from the specified path. Security measures: - Validates file extensions (.json) - Prevents path traversal attacks - Restricts access to files within the project directory - Comprehensive error logging and validation

func SplitCommaSeparatedString

func SplitCommaSeparatedString(s string) []string

SplitCommaSeparatedString splits a comma-separated string into a slice of strings

func StringPtr

func StringPtr(s string) *string

Utility function to convert a string to *string

func StringToBase64

func StringToBase64(input string) (string, error)

StringToBase64 encodes the input string to base64.

func StringToInt

func StringToInt(str string, mapping map[string]int) (int, error)

StringToInt converts a string to an integer based on a provided map

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL