Skip to content

Commit

Permalink
Merge pull request #1449 from seblaz/master
Browse files Browse the repository at this point in the history
fix: replace the deprecated logger.Logf and logger.Log for the new Logger
  • Loading branch information
james03160927 authored Oct 15, 2024
2 parents cf38360 + bce67fe commit 6fd2ca3
Show file tree
Hide file tree
Showing 48 changed files with 154 additions and 167 deletions.
2 changes: 1 addition & 1 deletion modules/aws/ami.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func GetEbsSnapshotsForAmi(t testing.TestingT, region string, ami string) []stri

// GetEbsSnapshotsForAmi retrieves the EBS snapshots which back the given AMI
func GetEbsSnapshotsForAmiE(t testing.TestingT, region string, ami string) ([]string, error) {
logger.Logf(t, "Retrieving EBS snapshots backing AMI %s", ami)
logger.Default.Logf(t, "Retrieving EBS snapshots backing AMI %s", ami)
ec2Client, err := NewEc2ClientE(t, region)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion modules/aws/asg.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func WaitForCapacityE(
return fmt.Sprintf("ASG %s is now at desired capacity %d", asgName, capacityInfo.DesiredCapacity), nil
},
)
logger.Log(t, msg)
logger.Default.Logf(t, "%s", msg)
return err
}

Expand Down
2 changes: 1 addition & 1 deletion modules/aws/ebs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func DeleteEbsSnapshot(t testing.TestingT, region string, snapshot string) {

// DeleteEbsSnapshot deletes the given EBS snapshot
func DeleteEbsSnapshotE(t testing.TestingT, region string, snapshot string) error {
logger.Logf(t, "Deleting EBS snapshot %s", snapshot)
logger.Default.Logf(t, "Deleting EBS snapshot %s", snapshot)
ec2Client, err := NewEc2ClientE(t, region)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions modules/aws/ec2-syslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func GetSyslogForInstanceE(t testing.TestingT, instanceID string, region string)
maxRetries := 120
timeBetweenRetries := 5 * time.Second

logger.Log(t, description)
logger.Default.Logf(t, "%s", description)

client, err := NewEc2ClientE(t, region)
if err != nil {
Expand Down Expand Up @@ -89,7 +89,7 @@ func GetSyslogForInstancesInAsg(t testing.TestingT, asgName string, awsRegion st
// minute after the Instance boots and are very useful for debugging boot-time issues, such as an error in User Data.
// Returns a map of Instance Id -> Syslog for that Instance.
func GetSyslogForInstancesInAsgE(t testing.TestingT, asgName string, awsRegion string) (map[string]string, error) {
logger.Logf(t, "Fetching syslog for each Instance in ASG %s in %s", asgName, awsRegion)
logger.Default.Logf(t, "Fetching syslog for each Instance in ASG %s in %s", asgName, awsRegion)

instanceIDs, err := GetEc2InstanceIdsByTagE(t, awsRegion, "aws:autoscaling:groupName", asgName)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions modules/aws/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func DeleteAmi(t testing.TestingT, region string, imageID string) {

// DeleteAmiE deletes the given AMI in the given region.
func DeleteAmiE(t testing.TestingT, region string, imageID string) error {
logger.Logf(t, "Deregistering AMI %s", imageID)
logger.Default.Logf(t, "Deregistering AMI %s", imageID)

client, err := NewEc2ClientE(t, region)
if err != nil {
Expand Down Expand Up @@ -314,7 +314,7 @@ func TerminateInstance(t testing.TestingT, region string, instanceID string) {

// TerminateInstanceE terminates the EC2 instance with the given ID in the given region.
func TerminateInstanceE(t testing.TestingT, region string, instanceID string) error {
logger.Logf(t, "Terminating Instance %s", instanceID)
logger.Default.Logf(t, "Terminating Instance %s", instanceID)

client, err := NewEc2ClientE(t, region)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion modules/aws/ecr.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func PutECRRepoLifecyclePolicy(t testing.TestingT, region string, repo *ecr.Repo

// PutEcrRepoLifecyclePolicy puts the given policy for the given ECR repository.
func PutECRRepoLifecyclePolicyE(t testing.TestingT, region string, repo *ecr.Repository, policy string) error {
logger.Logf(t, "Applying policy for repository %s in %s", *repo.RepositoryName, region)
logger.Default.Logf(t, "Applying policy for repository %s in %s", *repo.RepositoryName, region)

client, err := NewECRClientE(t, region)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions modules/aws/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func CreateMfaDevice(t testing.TestingT, iamClient *iam.IAM, deviceName string)

// CreateMfaDeviceE creates an MFA device using the given IAM client.
func CreateMfaDeviceE(t testing.TestingT, iamClient *iam.IAM, deviceName string) (*iam.VirtualMFADevice, error) {
logger.Logf(t, "Creating an MFA device called %s", deviceName)
logger.Default.Logf(t, "Creating an MFA device called %s", deviceName)

output, err := iamClient.CreateVirtualMFADevice(&iam.CreateVirtualMFADeviceInput{
VirtualMFADeviceName: aws.String(deviceName),
Expand Down Expand Up @@ -96,7 +96,7 @@ func EnableMfaDevice(t testing.TestingT, iamClient *iam.IAM, mfaDevice *iam.Virt
// EnableMfaDeviceE enables a newly created MFA Device by supplying the first two one-time passwords, so that it can be used for future
// logins by the given IAM User.
func EnableMfaDeviceE(t testing.TestingT, iamClient *iam.IAM, mfaDevice *iam.VirtualMFADevice) error {
logger.Logf(t, "Enabling MFA device %s", aws.StringValue(mfaDevice.SerialNumber))
logger.Default.Logf(t, "Enabling MFA device %s", aws.StringValue(mfaDevice.SerialNumber))

iamUserName, err := GetIamCurrentUserArnE(t)
if err != nil {
Expand All @@ -108,7 +108,7 @@ func EnableMfaDeviceE(t testing.TestingT, iamClient *iam.IAM, mfaDevice *iam.Vir
return err
}

logger.Logf(t, "Waiting 30 seconds for a new MFA Token to be generated...")
logger.Default.Logf(t, "Waiting 30 seconds for a new MFA Token to be generated...")
time.Sleep(30 * time.Second)

authCode2, err := GetTimeBasedOneTimePassword(mfaDevice)
Expand All @@ -127,7 +127,7 @@ func EnableMfaDeviceE(t testing.TestingT, iamClient *iam.IAM, mfaDevice *iam.Vir
return err
}

logger.Log(t, "Waiting for MFA Device enablement to propagate.")
logger.Default.Logf(t, "Waiting for MFA Device enablement to propagate.")
time.Sleep(10 * time.Second)

return nil
Expand Down
4 changes: 2 additions & 2 deletions modules/aws/keypair.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func ImportEC2KeyPair(t testing.TestingT, region string, name string, keyPair *s

// ImportEC2KeyPairE creates a Key Pair in EC2 by importing an existing public key.
func ImportEC2KeyPairE(t testing.TestingT, region string, name string, keyPair *ssh.KeyPair) (*Ec2Keypair, error) {
logger.Logf(t, "Creating new Key Pair in EC2 region %s named %s", region, name)
logger.Default.Logf(t, "Creating new Key Pair in EC2 region %s named %s", region, name)

client, err := NewEc2ClientE(t, region)
if err != nil {
Expand Down Expand Up @@ -75,7 +75,7 @@ func DeleteEC2KeyPair(t testing.TestingT, keyPair *Ec2Keypair) {

// DeleteEC2KeyPairE deletes an EC2 key pair.
func DeleteEC2KeyPairE(t testing.TestingT, keyPair *Ec2Keypair) error {
logger.Logf(t, "Deleting Key Pair in EC2 region %s named %s", keyPair.Region, keyPair.Name)
logger.Default.Logf(t, "Deleting Key Pair in EC2 region %s named %s", keyPair.Region, keyPair.Name)

client, err := NewEc2ClientE(t, keyPair.Region)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions modules/aws/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func GetRandomRegion(t testing.TestingT, approvedRegions []string, forbiddenRegi
func GetRandomRegionE(t testing.TestingT, approvedRegions []string, forbiddenRegions []string) (string, error) {
regionFromEnvVar := os.Getenv(regionOverrideEnvVarName)
if regionFromEnvVar != "" {
logger.Logf(t, "Using AWS region %s from environment variable %s", regionFromEnvVar, regionOverrideEnvVarName)
logger.Default.Logf(t, "Using AWS region %s from environment variable %s", regionFromEnvVar, regionOverrideEnvVarName)
return regionFromEnvVar, nil
}

Expand All @@ -91,7 +91,7 @@ func GetRandomRegionE(t testing.TestingT, approvedRegions []string, forbiddenReg
regionsToPickFrom = collections.ListSubtract(regionsToPickFrom, forbiddenRegions)
region := random.RandomString(regionsToPickFrom)

logger.Logf(t, "Using region %s", region)
logger.Default.Logf(t, "Using region %s", region)
return region, nil
}

Expand All @@ -106,7 +106,7 @@ func GetAllAwsRegions(t testing.TestingT) []string {

// GetAllAwsRegionsE gets the list of AWS regions available in this account.
func GetAllAwsRegionsE(t testing.TestingT) ([]string, error) {
logger.Log(t, "Looking up all AWS regions available in this account")
logger.Default.Logf(t, "Looking up all AWS regions available in this account")

ec2Client, err := NewEc2ClientE(t, defaultRegion)
if err != nil {
Expand Down Expand Up @@ -139,7 +139,7 @@ func GetAvailabilityZones(t testing.TestingT, region string) []string {
// GetAvailabilityZonesE gets the Availability Zones for a given AWS region. Note that for certain regions (e.g. us-east-1), different AWS
// accounts have access to different availability zones.
func GetAvailabilityZonesE(t testing.TestingT, region string) ([]string, error) {
logger.Logf(t, "Looking up all availability zones available in this account for region %s", region)
logger.Default.Logf(t, "Looking up all availability zones available in this account for region %s", region)

ec2Client, err := NewEc2ClientE(t, region)
if err != nil {
Expand Down
20 changes: 10 additions & 10 deletions modules/aws/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func FindS3BucketWithTagE(t testing.TestingT, awsRegion string, key string, valu

for _, tag := range tagResponse.TagSet {
if *tag.Key == key && *tag.Value == value {
logger.Logf(t, "Found S3 bucket %s with tag %s=%s", *bucket.Name, key, value)
logger.Default.Logf(t, "Found S3 bucket %s with tag %s=%s", *bucket.Name, key, value)
return *bucket.Name, nil
}
}
Expand Down Expand Up @@ -123,7 +123,7 @@ func GetS3ObjectContentsE(t testing.TestingT, awsRegion string, bucket string, k
}

contents := buf.String()
logger.Logf(t, "Read contents from s3://%s/%s", bucket, key)
logger.Default.Logf(t, "Read contents from s3://%s/%s", bucket, key)

return contents, nil
}
Expand All @@ -136,7 +136,7 @@ func CreateS3Bucket(t testing.TestingT, region string, name string) {

// CreateS3BucketE creates an S3 bucket in the given region with the given name. Note that S3 bucket names must be globally unique.
func CreateS3BucketE(t testing.TestingT, region string, name string) error {
logger.Logf(t, "Creating bucket %s in %s", name, region)
logger.Default.Logf(t, "Creating bucket %s in %s", name, region)

s3Client, err := NewS3ClientE(t, region)
if err != nil {
Expand All @@ -160,7 +160,7 @@ func PutS3BucketPolicy(t testing.TestingT, region string, bucketName string, pol

// PutS3BucketPolicyE applies an IAM resource policy to a given S3 bucket to create it's bucket policy
func PutS3BucketPolicyE(t testing.TestingT, region string, bucketName string, policyJSONString string) error {
logger.Logf(t, "Applying bucket policy for bucket %s in %s", bucketName, region)
logger.Default.Logf(t, "Applying bucket policy for bucket %s in %s", bucketName, region)

s3Client, err := NewS3ClientE(t, region)
if err != nil {
Expand All @@ -184,7 +184,7 @@ func PutS3BucketVersioning(t testing.TestingT, region string, bucketName string)

// PutS3BucketVersioningE creates an S3 bucket versioning configuration in the given region against the given bucket name, WITHOUT requiring MFA to remove versioning.
func PutS3BucketVersioningE(t testing.TestingT, region string, bucketName string) error {
logger.Logf(t, "Creating bucket versioning configuration for bucket %s in %s", bucketName, region)
logger.Default.Logf(t, "Creating bucket versioning configuration for bucket %s in %s", bucketName, region)

s3Client, err := NewS3ClientE(t, region)
if err != nil {
Expand All @@ -211,7 +211,7 @@ func DeleteS3Bucket(t testing.TestingT, region string, name string) {

// DeleteS3BucketE destroys the S3 bucket in the given region with the given name.
func DeleteS3BucketE(t testing.TestingT, region string, name string) error {
logger.Logf(t, "Deleting bucket %s in %s", region, name)
logger.Default.Logf(t, "Deleting bucket %s in %s", region, name)

s3Client, err := NewS3ClientE(t, region)
if err != nil {
Expand All @@ -233,7 +233,7 @@ func EmptyS3Bucket(t testing.TestingT, region string, name string) {

// EmptyS3BucketE removes the contents of an S3 bucket in the given region with the given name.
func EmptyS3BucketE(t testing.TestingT, region string, name string) error {
logger.Logf(t, "Emptying bucket %s in %s", name, region)
logger.Default.Logf(t, "Emptying bucket %s in %s", name, region)

s3Client, err := NewS3ClientE(t, region)
if err != nil {
Expand All @@ -253,7 +253,7 @@ func EmptyS3BucketE(t testing.TestingT, region string, name string) error {

//Checks if the bucket is already empty
if len((*bucketObjects).Versions) == 0 {
logger.Logf(t, "Bucket %s is already empty", name)
logger.Default.Logf(t, "Bucket %s is already empty", name)
return nil
}

Expand Down Expand Up @@ -291,12 +291,12 @@ func EmptyS3BucketE(t testing.TestingT, region string, name string) error {
if *(*bucketObjects).IsTruncated { //if there are more objects in the bucket, IsTruncated = true
// params.Marker = (*deleteParams).Delete.Objects[len((*deleteParams).Delete.Objects)-1].Key
params.KeyMarker = bucketObjects.NextKeyMarker
logger.Logf(t, "Requesting next batch | %s", *(params.KeyMarker))
logger.Default.Logf(t, "Requesting next batch | %s", *(params.KeyMarker))
} else { //if all objects in the bucket have been cleaned up.
break
}
}
logger.Logf(t, "Bucket %s is now empty", name)
logger.Default.Logf(t, "Bucket %s is now empty", name)
return err
}

Expand Down
6 changes: 3 additions & 3 deletions modules/aws/secretsmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func CreateSecretStringWithDefaultKey(t testing.TestingT, awsRegion, description

// CreateSecretStringWithDefaultKeyE creates a new secret in Secrets Manager using the default "aws/secretsmanager" KMS key and returns the secret ARN
func CreateSecretStringWithDefaultKeyE(t testing.TestingT, awsRegion, description, name, secretString string) (string, error) {
logger.Logf(t, "Creating new secret in secrets manager named %s", name)
logger.Default.Logf(t, "Creating new secret in secrets manager named %s", name)

client := NewSecretsManagerClient(t, awsRegion)

Expand All @@ -43,7 +43,7 @@ func GetSecretValue(t testing.TestingT, awsRegion, id string) string {

// GetSecretValueE takes the friendly name or ARN of a secret and returns the plaintext value
func GetSecretValueE(t testing.TestingT, awsRegion, id string) (string, error) {
logger.Logf(t, "Getting value of secret with ID %s", id)
logger.Default.Logf(t, "Getting value of secret with ID %s", id)

client := NewSecretsManagerClient(t, awsRegion)

Expand All @@ -65,7 +65,7 @@ func DeleteSecret(t testing.TestingT, awsRegion, id string, forceDelete bool) {

// DeleteSecretE deletes a secret. If forceDelete is true, the secret will be deleted after a short delay. If forceDelete is false, the secret will be deleted after a 30 day recovery window.
func DeleteSecretE(t testing.TestingT, awsRegion, id string, forceDelete bool) error {
logger.Logf(t, "Deleting secret with ID %s", id)
logger.Default.Logf(t, "Deleting secret with ID %s", id)

client := NewSecretsManagerClient(t, awsRegion)

Expand Down
4 changes: 2 additions & 2 deletions modules/aws/sns.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func CreateSnsTopic(t testing.TestingT, region string, snsTopicName string) stri

// CreateSnsTopicE creates an SNS Topic and return the ARN.
func CreateSnsTopicE(t testing.TestingT, region string, snsTopicName string) (string, error) {
logger.Logf(t, "Creating SNS topic %s in %s", snsTopicName, region)
logger.Default.Logf(t, "Creating SNS topic %s in %s", snsTopicName, region)

snsClient, err := NewSnsClientE(t, region)
if err != nil {
Expand Down Expand Up @@ -47,7 +47,7 @@ func DeleteSNSTopic(t testing.TestingT, region string, snsTopicArn string) {

// DeleteSNSTopicE deletes an SNS Topic.
func DeleteSNSTopicE(t testing.TestingT, region string, snsTopicArn string) error {
logger.Logf(t, "Deleting SNS topic %s in %s", snsTopicArn, region)
logger.Default.Logf(t, "Deleting SNS topic %s in %s", snsTopicArn, region)

snsClient, err := NewSnsClientE(t, region)
if err != nil {
Expand Down
Loading

0 comments on commit 6fd2ca3

Please sign in to comment.