Skip to content

Commit

Permalink
Merge pull request #37447 from hashicorp/t-literal-content-type-log-g…
Browse files Browse the repository at this point in the history
…roup-name-string-constant

ci: Prefer constants for string literals
  • Loading branch information
YakDriver authored May 11, 2024
2 parents 84589e8 + 0cf7674 commit e71921f
Show file tree
Hide file tree
Showing 305 changed files with 1,327 additions and 1,169 deletions.
110 changes: 110 additions & 0 deletions .ci/.semgrep-constants.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,16 @@ rules:
- pattern: '"catalog_id"'
severity: ERROR
fix: "names.AttrCatalogID"
- id: literal-certificate-string-constant
languages: [go]
message: Use the constant `names.AttrCertificate` for the string literal "certificate"
paths:
include:
- "internal/service/**/*.go"
patterns:
- pattern: '"certificate"'
severity: ERROR
fix: "names.AttrCertificate"
- id: literal-certificate_arn-string-constant
languages: [go]
message: Use the constant `names.AttrCertificateARN` for the string literal "certificate_arn"
Expand Down Expand Up @@ -170,6 +180,16 @@ rules:
- pattern: '"configuration"'
severity: ERROR
fix: "names.AttrConfiguration"
- id: literal-content_type-string-constant
languages: [go]
message: Use the constant `names.AttrContentType` for the string literal "content_type"
paths:
include:
- "internal/service/**/*.go"
patterns:
- pattern: '"content_type"'
severity: ERROR
fix: "names.AttrContentType"
- id: literal-created_at-string-constant
languages: [go]
message: Use the constant `names.AttrCreatedAt` for the string literal "created_at"
Expand Down Expand Up @@ -330,6 +350,16 @@ rules:
- pattern: '"endpoint"'
severity: ERROR
fix: "names.AttrEndpoint"
- id: literal-endpoint_type-string-constant
languages: [go]
message: Use the constant `names.AttrEndpointType` for the string literal "endpoint_type"
paths:
include:
- "internal/service/**/*.go"
patterns:
- pattern: '"endpoint_type"'
severity: ERROR
fix: "names.AttrEndpointType"
- id: literal-endpoints-string-constant
languages: [go]
message: Use the constant `names.AttrEndpoints` for the string literal "endpoints"
Expand Down Expand Up @@ -420,6 +450,16 @@ rules:
- pattern: '"id"'
severity: ERROR
fix: "names.AttrID"
- id: literal-identifier-string-constant
languages: [go]
message: Use the constant `names.AttrIdentifier` for the string literal "identifier"
paths:
include:
- "internal/service/**/*.go"
patterns:
- pattern: '"identifier"'
severity: ERROR
fix: "names.AttrIdentifier"
- id: literal-instance_id-string-constant
languages: [go]
message: Use the constant `names.AttrInstanceID` for the string literal "instance_id"
Expand Down Expand Up @@ -480,6 +520,16 @@ rules:
- pattern: '"last_updated_date"'
severity: ERROR
fix: "names.AttrLastUpdatedDate"
- id: literal-log_group_name-string-constant
languages: [go]
message: Use the constant `names.AttrLogGroupName` for the string literal "log_group_name"
paths:
include:
- "internal/service/**/*.go"
patterns:
- pattern: '"log_group_name"'
severity: ERROR
fix: "names.AttrLogGroupName"
- id: literal-max-string-constant
languages: [go]
message: Use the constant `names.AttrMax` for the string literal "max"
Expand Down Expand Up @@ -530,6 +580,16 @@ rules:
- pattern: '"name_prefix"'
severity: ERROR
fix: "names.AttrNamePrefix"
- id: literal-namespace-string-constant
languages: [go]
message: Use the constant `names.AttrNamespace` for the string literal "namespace"
paths:
include:
- "internal/service/**/*.go"
patterns:
- pattern: '"namespace"'
severity: ERROR
fix: "names.AttrNamespace"
- id: literal-network_configuration-string-constant
languages: [go]
message: Use the constant `names.AttrNetworkConfiguration` for the string literal "network_configuration"
Expand Down Expand Up @@ -720,6 +780,26 @@ rules:
- pattern: '"role_arn"'
severity: ERROR
fix: "names.AttrRoleARN"
- id: literal-s3_bucket_name-string-constant
languages: [go]
message: Use the constant `names.AttrS3BucketName` for the string literal "s3_bucket_name"
paths:
include:
- "internal/service/**/*.go"
patterns:
- pattern: '"s3_bucket_name"'
severity: ERROR
fix: "names.AttrS3BucketName"
- id: literal-sns_topic_arn-string-constant
languages: [go]
message: Use the constant `names.AttrSNSTopicARN` for the string literal "sns_topic_arn"
paths:
include:
- "internal/service/**/*.go"
patterns:
- pattern: '"sns_topic_arn"'
severity: ERROR
fix: "names.AttrSNSTopicARN"
- id: literal-schedule_expression-string-constant
languages: [go]
message: Use the constant `names.AttrScheduleExpression` for the string literal "schedule_expression"
Expand Down Expand Up @@ -760,6 +840,16 @@ rules:
- pattern: '"security_groups"'
severity: ERROR
fix: "names.AttrSecurityGroups"
- id: literal-service_name-string-constant
languages: [go]
message: Use the constant `names.AttrServiceName` for the string literal "service_name"
paths:
include:
- "internal/service/**/*.go"
patterns:
- pattern: '"service_name"'
severity: ERROR
fix: "names.AttrServiceName"
- id: literal-session-string-constant
languages: [go]
message: Use the constant `names.AttrSession` for the string literal "session"
Expand Down Expand Up @@ -850,6 +940,16 @@ rules:
- pattern: '"subnet_ids"'
severity: ERROR
fix: "names.AttrSubnetIDs"
- id: literal-table_name-string-constant
languages: [go]
message: Use the constant `names.AttrTableName` for the string literal "table_name"
paths:
include:
- "internal/service/**/*.go"
patterns:
- pattern: '"table_name"'
severity: ERROR
fix: "names.AttrTableName"
- id: literal-tags-string-constant
languages: [go]
message: Use the constant `names.AttrTags` for the string literal "tags"
Expand Down Expand Up @@ -940,6 +1040,16 @@ rules:
- pattern: '"unit"'
severity: ERROR
fix: "names.AttrUnit"
- id: literal-user_name-string-constant
languages: [go]
message: Use the constant `names.AttrUserName` for the string literal "user_name"
paths:
include:
- "internal/service/**/*.go"
patterns:
- pattern: '"user_name"'
severity: ERROR
fix: "names.AttrUserName"
- id: literal-username-string-constant
languages: [go]
message: Use the constant `names.AttrUsername` for the string literal "username"
Expand Down
6 changes: 3 additions & 3 deletions internal/service/acm/certificate_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func dataSourceCertificate() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"certificate": {
names.AttrCertificate: {
Type: schema.TypeString,
Computed: true,
},
Expand Down Expand Up @@ -207,10 +207,10 @@ func dataSourceCertificateRead(ctx context.Context, d *schema.ResourceData, meta
}
}
if output != nil {
d.Set("certificate", output.Certificate)
d.Set(names.AttrCertificate, output.Certificate)
d.Set("certificate_chain", output.CertificateChain)
} else {
d.Set("certificate", nil)
d.Set(names.AttrCertificate, nil)
d.Set("certificate_chain", nil)
}

Expand Down
12 changes: 6 additions & 6 deletions internal/service/acm/certificate_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestAccACMCertificateDataSource_singleIssued(t *testing.T) {
//lintignore:AWSAT001
resource.TestMatchResourceAttr(resourceName, names.AttrARN, arnRe),
resource.TestCheckResourceAttr(resourceName, names.AttrStatus, string(awstypes.CertificateStatusIssued)),
resource.TestCheckResourceAttrSet(resourceName, "certificate"),
resource.TestCheckResourceAttrSet(resourceName, names.AttrCertificate),
resource.TestCheckResourceAttrSet(resourceName, "certificate_chain"),
),
},
Expand All @@ -63,7 +63,7 @@ func TestAccACMCertificateDataSource_singleIssued(t *testing.T) {
//lintignore:AWSAT001
resource.TestMatchResourceAttr(resourceName, names.AttrARN, arnRe),
resource.TestCheckResourceAttr(resourceName, names.AttrStatus, string(awstypes.CertificateStatusIssued)),
resource.TestCheckResourceAttrSet(resourceName, "certificate"),
resource.TestCheckResourceAttrSet(resourceName, names.AttrCertificate),
resource.TestCheckResourceAttrSet(resourceName, "certificate_chain"),
),
},
Expand All @@ -72,7 +72,7 @@ func TestAccACMCertificateDataSource_singleIssued(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
//lintignore:AWSAT001
resource.TestMatchResourceAttr(resourceName, names.AttrARN, arnRe),
resource.TestCheckResourceAttrSet(resourceName, "certificate"),
resource.TestCheckResourceAttrSet(resourceName, names.AttrCertificate),
resource.TestCheckResourceAttrSet(resourceName, "certificate_chain"),
),
},
Expand All @@ -81,7 +81,7 @@ func TestAccACMCertificateDataSource_singleIssued(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
//lintignore:AWSAT001
resource.TestMatchResourceAttr(resourceName, names.AttrARN, arnRe),
resource.TestCheckResourceAttrSet(resourceName, "certificate"),
resource.TestCheckResourceAttrSet(resourceName, names.AttrCertificate),
resource.TestCheckResourceAttrSet(resourceName, "certificate_chain"),
),
},
Expand All @@ -90,7 +90,7 @@ func TestAccACMCertificateDataSource_singleIssued(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
//lintignore:AWSAT001
resource.TestMatchResourceAttr(resourceName, names.AttrARN, arnRe),
resource.TestCheckResourceAttrSet(resourceName, "certificate"),
resource.TestCheckResourceAttrSet(resourceName, names.AttrCertificate),
resource.TestCheckResourceAttrSet(resourceName, "certificate_chain"),
),
},
Expand All @@ -99,7 +99,7 @@ func TestAccACMCertificateDataSource_singleIssued(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
//lintignore:AWSAT001
resource.TestMatchResourceAttr(resourceName, names.AttrARN, arnRe),
resource.TestCheckResourceAttrSet(resourceName, "certificate"),
resource.TestCheckResourceAttrSet(resourceName, names.AttrCertificate),
resource.TestCheckResourceAttrSet(resourceName, "certificate_chain"),
),
},
Expand Down
6 changes: 3 additions & 3 deletions internal/service/acmpca/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func resourceCertificate() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"certificate": {
names.AttrCertificate: {
Type: schema.TypeString,
Computed: true,
},
Expand Down Expand Up @@ -206,7 +206,7 @@ func resourceCertificateRead(ctx context.Context, d *schema.ResourceData, meta i
}

d.Set(names.AttrARN, d.Id())
d.Set("certificate", output.Certificate)
d.Set(names.AttrCertificate, output.Certificate)
d.Set("certificate_authority_arn", d.Get("certificate_authority_arn").(string))
d.Set("certificate_chain", output.CertificateChain)

Expand All @@ -217,7 +217,7 @@ func resourceCertificateRevoke(ctx context.Context, d *schema.ResourceData, meta
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).ACMPCAClient(ctx)

block, _ := pem.Decode([]byte(d.Get("certificate").(string)))
block, _ := pem.Decode([]byte(d.Get(names.AttrCertificate).(string)))
if block == nil {
log.Printf("[WARN] Failed to parse ACM PCA Certificate (%s)", d.Id())
return diags
Expand Down
20 changes: 10 additions & 10 deletions internal/service/acmpca/certificate_authority.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func resourceCertificateAuthority() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
"certificate": {
names.AttrCertificate: {
Type: schema.TypeString,
Computed: true,
},
Expand Down Expand Up @@ -260,7 +260,7 @@ func resourceCertificateAuthority() *schema.Resource {
return true
},
},
"s3_bucket_name": {
names.AttrS3BucketName: {
Type: schema.TypeString,
Optional: true,
ValidateFunc: validation.StringLenBetween(3, 255),
Expand Down Expand Up @@ -421,10 +421,10 @@ func resourceCertificateAuthorityRead(ctx context.Context, d *schema.ResourceDat
return sdkdiag.AppendErrorf(diags, "reading ACM PCA Certificate Authority (%s) Certificate: %s", d.Id(), err)
}

d.Set("certificate", "")
d.Set(names.AttrCertificate, "")
d.Set("certificate_chain", "")
if outputGCACert != nil {
d.Set("certificate", outputGCACert.Certificate)
d.Set(names.AttrCertificate, outputGCACert.Certificate)
d.Set("certificate_chain", outputGCACert.CertificateChain)
}

Expand Down Expand Up @@ -701,7 +701,7 @@ func expandCrlConfiguration(l []interface{}) *types.CrlConfiguration {
if v, ok := m["expiration_in_days"]; ok && v.(int) > 0 {
config.ExpirationInDays = aws.Int32(int32(v.(int)))
}
if v, ok := m["s3_bucket_name"]; ok && v.(string) != "" {
if v, ok := m[names.AttrS3BucketName]; ok && v.(string) != "" {
config.S3BucketName = aws.String(v.(string))
}
if v, ok := m["s3_object_acl"]; ok && v.(string) != "" {
Expand Down Expand Up @@ -789,11 +789,11 @@ func flattenCrlConfiguration(config *types.CrlConfiguration) []interface{} {
}

m := map[string]interface{}{
"custom_cname": aws.ToString(config.CustomCname),
names.AttrEnabled: aws.ToBool(config.Enabled),
"expiration_in_days": int(aws.ToInt32(config.ExpirationInDays)),
"s3_bucket_name": aws.ToString(config.S3BucketName),
"s3_object_acl": string(config.S3ObjectAcl),
"custom_cname": aws.ToString(config.CustomCname),
names.AttrEnabled: aws.ToBool(config.Enabled),
"expiration_in_days": int(aws.ToInt32(config.ExpirationInDays)),
names.AttrS3BucketName: aws.ToString(config.S3BucketName),
"s3_object_acl": string(config.S3ObjectAcl),
}

return []interface{}{m}
Expand Down
7 changes: 4 additions & 3 deletions internal/service/acmpca/certificate_authority_certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/internal/verify"
"github.com/hashicorp/terraform-provider-aws/names"
)

// @SDKResource("aws_acmpca_certificate_authority_certificate", name="Certificate Authority Certificate")
Expand All @@ -33,7 +34,7 @@ func resourceCertificateAuthorityCertificate() *schema.Resource {
},

Schema: map[string]*schema.Schema{
"certificate": {
names.AttrCertificate: {
Type: schema.TypeString,
Required: true,
ForceNew: true,
Expand Down Expand Up @@ -61,7 +62,7 @@ func resourceCertificateAuthorityCertificateCreate(ctx context.Context, d *schem

certificateAuthorityARN := d.Get("certificate_authority_arn").(string)
input := &acmpca.ImportCertificateAuthorityCertificateInput{
Certificate: []byte(d.Get("certificate").(string)),
Certificate: []byte(d.Get(names.AttrCertificate).(string)),
CertificateAuthorityArn: aws.String(certificateAuthorityARN),
}

Expand Down Expand Up @@ -96,7 +97,7 @@ func resourceCertificateAuthorityCertificateRead(ctx context.Context, d *schema.
}

d.Set("certificate_authority_arn", d.Id())
d.Set("certificate", output.Certificate)
d.Set(names.AttrCertificate, output.Certificate)
d.Set("certificate_chain", output.CertificateChain)

return diags
Expand Down
Loading

0 comments on commit e71921f

Please sign in to comment.