Repository: opentofu/opentofu
File: internal/backend/remote-state/s3/client.go (Go)

Code before:
	}
	return nil
}

func (c *RemoteClient) lockPath() string {
	return fmt.Sprintf("%s/%s", c.bucketName, c.path)
}

func (c *RemoteClient) getSSECustomerKeyMD5() string {
	b := md5.Sum(c.customerEncryptionKey)
	return base64.StdEncoding.EncodeToString(b[:])
}

func (c *RemoteClient) IsLockingEnabled() bool {
	return c.ddbTable != "" || c.useLockfile
}

func (c *RemoteClient) lockFilePath() string {
	return fmt.Sprintf("%s%s", c.path, lockFileSuffix)
}

// According to the announcement done here (https://github.com/aws/aws-sdk-go-v2/discussions/2960), a recent version
// of the aws-sdk introduced default checksum calculations and validations for all s3 objects.
// This function is meant to disable this new default behavior when used against 3rd party S3 providers.
// More details about the feature: https://docs.aws.amazon.com/sdkref/latest/guide/feature-dataintegrity.html
func s3optDisableDefaultChecksum(include bool) func(*s3.Options) {
	if include {
		return func(o *s3.Options) {
			o.RequestChecksumCalculation = aws.RequestChecksumCalculationWhenRequired
			o.ResponseChecksumValidation = aws.ResponseChecksumValidationWhenRequired
		}
	}
	return func(o *s3.Options) {}
}

const errBadChecksumFmt = `state data in S3 does not have the expected content.

This may be caused by unusually long delays in S3 processing a previous state
update.  Please wait for a minute or two and try again. If this problem
persists, and neither S3 nor DynamoDB are experiencing an outage, you may need
to manually verify the remote state and update the Digest value stored in the
DynamoDB table to the following value: %x
`

const errS3NoSuchBucket = `S3 bucket does not exist.

The referenced S3 bucket must have been previously created. If the S3 bucket
was created within the last minute, please wait for a minute or two and try
again.

Error: %w

Review comment (suggestion):
Just a small nit, I think the argument should be named something like `skip` or `skipChecksum` instead of `include` based on the usage pattern.

Code after:
	}
	return nil
}

func (c *RemoteClient) lockPath() string {
	return fmt.Sprintf("%s/%s", c.bucketName, c.path)
}

func (c *RemoteClient) getSSECustomerKeyMD5() string {
	b := md5.Sum(c.customerEncryptionKey)
	return base64.StdEncoding.EncodeToString(b[:])
}

func (c *RemoteClient) IsLockingEnabled() bool {
	return c.ddbTable != "" || c.useLockfile
}

func (c *RemoteClient) lockFilePath() string {
	return fmt.Sprintf("%s%s", c.path, lockFileSuffix)
}

// According to the announcement done here (https://github.com/aws/aws-sdk-go-v2/discussions/2960), a recent version
// of the aws-sdk introduced default checksum calculations and validations for all s3 objects.
// This function is meant to disable this new default behavior when used against 3rd party S3 providers.
// More details about the feature: https://docs.aws.amazon.com/sdkref/latest/guide/feature-dataintegrity.html
func s3optDisableDefaultChecksum(skipS3Checksum bool) func(*s3.Options) {
	if skipS3Checksum {
		return func(o *s3.Options) {
			o.RequestChecksumCalculation = aws.RequestChecksumCalculationWhenRequired
			o.ResponseChecksumValidation = aws.ResponseChecksumValidationWhenRequired
		}
	}
	return func(o *s3.Options) {}
}

const errBadChecksumFmt = `state data in S3 does not have the expected content.

This may be caused by unusually long delays in S3 processing a previous state
update.  Please wait for a minute or two and try again. If this problem
persists, and neither S3 nor DynamoDB are experiencing an outage, you may need
to manually verify the remote state and update the Digest value stored in the
DynamoDB table to the following value: %x
`

const errS3NoSuchBucket = `S3 bucket does not exist.

The referenced S3 bucket must have been previously created. If the S3 bucket
was created within the last minute, please wait for a minute or two and try
again.

Error: %w