Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: Prefer constants for string literals #37516

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
5bf7869
ci: Prefer constant for string literals
YakDriver May 14, 2024
e50b002
names: Add constant for string literals
YakDriver May 14, 2024
4269ca6
apigateway: Use constants for strings
YakDriver May 14, 2024
80d3807
apigatewayv2: Use constants for strings
YakDriver May 14, 2024
998bf83
appautoscaling: Use constants for strings
YakDriver May 14, 2024
fd98d5e
appsync: Use constants for strings
YakDriver May 14, 2024
96dd449
autoscaling: Use constants for strings
YakDriver May 14, 2024
b0376e5
autoscalingplans: Use constants for strings
YakDriver May 14, 2024
b0cf048
batch: Use constants for strings
YakDriver May 14, 2024
d0c895d
bedrock: Use constants for strings
YakDriver May 14, 2024
4da15d7
chimesdkmediapipelines: Use constants for strings
YakDriver May 14, 2024
3933ee6
codebuild: Use constants for strings
YakDriver May 14, 2024
d89a67b
codecatalyst: Use constants for strings
YakDriver May 14, 2024
0fde379
codepipeline: Use constants for strings
YakDriver May 14, 2024
841fca2
cognitoidentity: Use constants for strings
YakDriver May 14, 2024
35cac1a
cognitoidp: Use constants for strings
YakDriver May 14, 2024
37a6bcd
comprehend: Use constants for strings
YakDriver May 14, 2024
9f7920c
connect: Use constants for strings
YakDriver May 14, 2024
b2728fc
directconnect: Use constants for strings
YakDriver May 14, 2024
183ffb7
dms: Use constants for strings
YakDriver May 14, 2024
61624bb
dynamodb: Use constants for strings
YakDriver May 14, 2024
659df2b
ec2: Use constants for strings
YakDriver May 14, 2024
5f8cd85
ecr: Use constants for strings
YakDriver May 14, 2024
e27e244
ecs: Use constants for strings
YakDriver May 14, 2024
f6804e8
elasticbeanstalk: Use constants for strings
YakDriver May 14, 2024
c9f2c83
elbv2: Use constants for strings
YakDriver May 14, 2024
3a69263
emr: Use constants for strings
YakDriver May 14, 2024
a58fa75
events: Use constants for strings
YakDriver May 14, 2024
b295a29
evidently: Use constants for strings
YakDriver May 14, 2024
163886a
finspace: Use constants for strings
YakDriver May 14, 2024
c5ea048
fsx: Use constants for strings
YakDriver May 14, 2024
ed7e9cd
glue: Use constants for strings
YakDriver May 14, 2024
7a7f669
identitystore: Use constants for strings
YakDriver May 14, 2024
56d24cd
imagebuilder: Use constants for strings
YakDriver May 14, 2024
10ea4a4
kendra: Use constants for strings
YakDriver May 14, 2024
73ea6f3
lightsail: Use constants for strings
YakDriver May 14, 2024
019ae79
macie2: Use constants for strings
YakDriver May 14, 2024
c0a4ea3
medialive: Use constants for strings
YakDriver May 14, 2024
302dc12
neptune: Use constants for strings
YakDriver May 14, 2024
bfdab8e
networkmanager: Use constants for strings
YakDriver May 14, 2024
cdb0b40
opsworks: Use constants for strings
YakDriver May 14, 2024
5d0d6fe
pipes: Use constants for strings
YakDriver May 14, 2024
73c9562
polly: Use constants for strings
YakDriver May 14, 2024
d89a63e
rds: Use constants for strings
YakDriver May 14, 2024
04a9949
redshift: Use constants for strings
YakDriver May 14, 2024
3dd7f23
redshiftserverless: Use constants for strings
YakDriver May 14, 2024
9a5ef2d
scheduler: Use constants for strings
YakDriver May 14, 2024
2ad862a
securitylake: Use constants for strings
YakDriver May 14, 2024
c47976f
servicecatalog: Use constants for strings
YakDriver May 14, 2024
55bed3a
ses: Use constants for strings
YakDriver May 14, 2024
9ce3ea9
signer: Use constants for strings
YakDriver May 14, 2024
4d8c884
ssoadmin: Use constants for strings
YakDriver May 14, 2024
184a41a
storagegateway: Use constants for strings
YakDriver May 14, 2024
dc0fca8
transcribe: Use constants for strings
YakDriver May 14, 2024
59bc88a
transfer: Use constants for strings
YakDriver May 14, 2024
eea9237
vpclattice: Use constants for strings
YakDriver May 14, 2024
f235205
waf: Use constants for strings
YakDriver May 14, 2024
e1d6b4f
wafregional: Use constants for strings
YakDriver May 14, 2024
ce4912c
wafv2: Use constants for strings
YakDriver May 14, 2024
841a431
names: Use constants for strings
YakDriver May 14, 2024
d862d1f
Fix format
YakDriver May 14, 2024
01d910b
Fix imports
YakDriver May 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions .ci/.semgrep-constants.yml
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,16 @@ rules:
- pattern: '"database_name"'
severity: ERROR
fix: "names.AttrDatabaseName"
- id: literal-default_action-string-constant
languages: [go]
message: Use the constant `names.AttrDefaultAction` for the string literal "default_action"
paths:
include:
- "internal/service/**/*.go"
patterns:
- pattern: '"default_action"'
severity: ERROR
fix: "names.AttrDefaultAction"
- id: literal-default_value-string-constant
languages: [go]
message: Use the constant `names.AttrDefaultValue` for the string literal "default_value"
Expand Down Expand Up @@ -580,6 +590,16 @@ rules:
- pattern: '"expression"'
severity: ERROR
fix: "names.AttrExpression"
- id: literal-external_id-string-constant
languages: [go]
message: Use the constant `names.AttrExternalID` for the string literal "external_id"
paths:
include:
- "internal/service/**/*.go"
patterns:
- pattern: '"external_id"'
severity: ERROR
fix: "names.AttrExternalID"
- id: literal-family-string-constant
languages: [go]
message: Use the constant `names.AttrFamily` for the string literal "family"
Expand Down Expand Up @@ -620,6 +640,16 @@ rules:
- pattern: '"filter"'
severity: ERROR
fix: "names.AttrFilter"
- id: literal-force_delete-string-constant
languages: [go]
message: Use the constant `names.AttrForceDelete` for the string literal "force_delete"
paths:
include:
- "internal/service/**/*.go"
patterns:
- pattern: '"force_delete"'
severity: ERROR
fix: "names.AttrForceDelete"
- id: literal-force_destroy-string-constant
languages: [go]
message: Use the constant `names.AttrForceDestroy` for the string literal "force_destroy"
Expand Down Expand Up @@ -870,6 +900,16 @@ rules:
- pattern: '"key_id"'
severity: ERROR
fix: "names.AttrKeyID"
- id: literal-language_code-string-constant
languages: [go]
message: Use the constant `names.AttrLanguageCode` for the string literal "language_code"
paths:
include:
- "internal/service/**/*.go"
patterns:
- pattern: '"language_code"'
severity: ERROR
fix: "names.AttrLanguageCode"
- id: literal-last_updated_date-string-constant
languages: [go]
message: Use the constant `names.AttrLastUpdatedDate` for the string literal "last_updated_date"
Expand Down Expand Up @@ -920,6 +960,16 @@ rules:
- pattern: '"max"'
severity: ERROR
fix: "names.AttrMax"
- id: literal-max_capacity-string-constant
languages: [go]
message: Use the constant `names.AttrMaxCapacity` for the string literal "max_capacity"
paths:
include:
- "internal/service/**/*.go"
patterns:
- pattern: '"max_capacity"'
severity: ERROR
fix: "names.AttrMaxCapacity"
- id: literal-message-string-constant
languages: [go]
message: Use the constant `names.AttrMessage` for the string literal "message"
Expand Down Expand Up @@ -1180,6 +1230,16 @@ rules:
- pattern: '"profile"'
severity: ERROR
fix: "names.AttrProfile"
- id: literal-propagate_tags-string-constant
languages: [go]
message: Use the constant `names.AttrPropagateTags` for the string literal "propagate_tags"
paths:
include:
- "internal/service/**/*.go"
patterns:
- pattern: '"propagate_tags"'
severity: ERROR
fix: "names.AttrPropagateTags"
- id: literal-properties-string-constant
languages: [go]
message: Use the constant `names.AttrProperties` for the string literal "properties"
Expand All @@ -1200,6 +1260,16 @@ rules:
- pattern: '"protocol"'
severity: ERROR
fix: "names.AttrProtocol"
- id: literal-provider_name-string-constant
languages: [go]
message: Use the constant `names.AttrProviderName` for the string literal "provider_name"
paths:
include:
- "internal/service/**/*.go"
patterns:
- pattern: '"provider_name"'
severity: ERROR
fix: "names.AttrProviderName"
- id: literal-public_key-string-constant
languages: [go]
message: Use the constant `names.AttrPublicKey` for the string literal "public_key"
Expand Down Expand Up @@ -1450,6 +1520,16 @@ rules:
- pattern: '"service_name"'
severity: ERROR
fix: "names.AttrServiceName"
- id: literal-service_role-string-constant
languages: [go]
message: Use the constant `names.AttrServiceRole` for the string literal "service_role"
paths:
include:
- "internal/service/**/*.go"
patterns:
- pattern: '"service_role"'
severity: ERROR
fix: "names.AttrServiceRole"
- id: literal-service_role_arn-string-constant
languages: [go]
message: Use the constant `names.AttrServiceRoleARN` for the string literal "service_role_arn"
Expand Down Expand Up @@ -1520,6 +1600,16 @@ rules:
- pattern: '"skip_requesting_account_id"'
severity: ERROR
fix: "names.AttrSkipRequestingAccountID"
- id: literal-snapshot_id-string-constant
languages: [go]
message: Use the constant `names.AttrSnapshotID` for the string literal "snapshot_id"
paths:
include:
- "internal/service/**/*.go"
patterns:
- pattern: '"snapshot_id"'
severity: ERROR
fix: "names.AttrSnapshotID"
- id: literal-source-string-constant
languages: [go]
message: Use the constant `names.AttrSource` for the string literal "source"
Expand Down Expand Up @@ -1580,6 +1670,16 @@ rules:
- pattern: '"status"'
severity: ERROR
fix: "names.AttrStatus"
- id: literal-status_code-string-constant
languages: [go]
message: Use the constant `names.AttrStatusCode` for the string literal "status_code"
paths:
include:
- "internal/service/**/*.go"
patterns:
- pattern: '"status_code"'
severity: ERROR
fix: "names.AttrStatusCode"
- id: literal-status_message-string-constant
languages: [go]
message: Use the constant `names.AttrStatusMessage` for the string literal "status_message"
Expand All @@ -1590,6 +1690,16 @@ rules:
- pattern: '"status_message"'
severity: ERROR
fix: "names.AttrStatusMessage"
- id: literal-status_reason-string-constant
languages: [go]
message: Use the constant `names.AttrStatusReason` for the string literal "status_reason"
paths:
include:
- "internal/service/**/*.go"
patterns:
- pattern: '"status_reason"'
severity: ERROR
fix: "names.AttrStatusReason"
- id: literal-storage_type-string-constant
languages: [go]
message: Use the constant `names.AttrStorageType` for the string literal "storage_type"
Expand Down
6 changes: 3 additions & 3 deletions internal/service/apigateway/documentation_part.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func resourceDocumentationPart() *schema.Resource {
Optional: true,
ForceNew: true,
},
"status_code": {
names.AttrStatusCode: {
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Expand Down Expand Up @@ -260,7 +260,7 @@ func expandDocumentationPartLocation(l []interface{}) *types.DocumentationPartLo
if v, ok := loc[names.AttrPath]; ok {
out.Path = aws.String(v.(string))
}
if v, ok := loc["status_code"]; ok {
if v, ok := loc[names.AttrStatusCode]; ok {
out.StatusCode = aws.String(v.(string))
}
return out
Expand All @@ -286,7 +286,7 @@ func flattenDocumentationPartLocation(l *types.DocumentationPartLocation) []inte
}

if v := l.StatusCode; v != nil {
m["status_code"] = aws.ToString(v)
m[names.AttrStatusCode] = aws.ToString(v)
}

m[names.AttrType] = string(l.Type)
Expand Down
7 changes: 4 additions & 3 deletions internal/service/apigateway/gateway_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
"github.com/hashicorp/terraform-provider-aws/internal/flex"
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
"github.com/hashicorp/terraform-provider-aws/names"
)

// @SDKResource("aws_api_gateway_gateway_response", name="Gateway Response")
Expand Down Expand Up @@ -66,7 +67,7 @@ func resourceGatewayResponse() *schema.Resource {
Required: true,
ForceNew: true,
},
"status_code": {
names.AttrStatusCode: {
Type: schema.TypeString,
Optional: true,
},
Expand All @@ -91,7 +92,7 @@ func resourceGatewayResponsePut(ctx context.Context, d *schema.ResourceData, met
input.ResponseTemplates = flex.ExpandStringValueMap(v.(map[string]interface{}))
}

if v, ok := d.GetOk("status_code"); ok {
if v, ok := d.GetOk(names.AttrStatusCode); ok {
input.StatusCode = aws.String(v.(string))
}

Expand Down Expand Up @@ -127,7 +128,7 @@ func resourceGatewayResponseRead(ctx context.Context, d *schema.ResourceData, me
d.Set("response_parameters", gatewayResponse.ResponseParameters)
d.Set("response_templates", gatewayResponse.ResponseTemplates)
d.Set("response_type", gatewayResponse.ResponseType)
d.Set("status_code", gatewayResponse.StatusCode)
d.Set(names.AttrStatusCode, gatewayResponse.StatusCode)

return diags
}
Expand Down
4 changes: 2 additions & 2 deletions internal/service/apigateway/gateway_response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestAccAPIGatewayGatewayResponse_basic(t *testing.T) {
Config: testAccGatewayResponseConfig_basic(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckGatewayResponseExists(ctx, resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "status_code", "401"),
resource.TestCheckResourceAttr(resourceName, names.AttrStatusCode, "401"),
resource.TestCheckResourceAttr(resourceName, "response_parameters.gatewayresponse.header.Authorization", "'Basic'"),
resource.TestCheckResourceAttr(resourceName, "response_templates.application/xml", "#set($inputRoot = $input.path('$'))\n{ }"),
resource.TestCheckNoResourceAttr(resourceName, "response_templates.application/json"),
Expand All @@ -51,7 +51,7 @@ func TestAccAPIGatewayGatewayResponse_basic(t *testing.T) {
Config: testAccGatewayResponseConfig_update(rName),
Check: resource.ComposeTestCheckFunc(
testAccCheckGatewayResponseExists(ctx, resourceName, &conf),
resource.TestCheckResourceAttr(resourceName, "status_code", "477"),
resource.TestCheckResourceAttr(resourceName, names.AttrStatusCode, "477"),
resource.TestCheckResourceAttr(resourceName, "response_templates.application/json", "{'message':$context.error.messageString}"),
resource.TestCheckNoResourceAttr(resourceName, "response_templates.application/xml"),
resource.TestCheckNoResourceAttr(resourceName, "response_parameters.gatewayresponse.header.Authorization"),
Expand Down
12 changes: 6 additions & 6 deletions internal/service/apigateway/integration_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func resourceIntegrationResponse() *schema.Resource {
httpMethod := idParts[2]
statusCode := idParts[3]
d.Set("http_method", httpMethod)
d.Set("status_code", statusCode)
d.Set(names.AttrStatusCode, statusCode)
d.Set(names.AttrResourceID, resourceID)
d.Set("rest_api_id", restApiID)
d.SetId(fmt.Sprintf("agir-%s-%s-%s-%s", restApiID, resourceID, httpMethod, statusCode))
Expand Down Expand Up @@ -86,7 +86,7 @@ func resourceIntegrationResponse() *schema.Resource {
Type: schema.TypeString,
Optional: true,
},
"status_code": {
names.AttrStatusCode: {
Type: schema.TypeString,
Required: true,
},
Expand All @@ -102,7 +102,7 @@ func resourceIntegrationResponsePut(ctx context.Context, d *schema.ResourceData,
HttpMethod: aws.String(d.Get("http_method").(string)),
ResourceId: aws.String(d.Get(names.AttrResourceID).(string)),
RestApiId: aws.String(d.Get("rest_api_id").(string)),
StatusCode: aws.String(d.Get("status_code").(string)),
StatusCode: aws.String(d.Get(names.AttrStatusCode).(string)),
}

if v, ok := d.GetOk("content_handling"); ok {
Expand All @@ -128,7 +128,7 @@ func resourceIntegrationResponsePut(ctx context.Context, d *schema.ResourceData,
}

if d.IsNewResource() {
d.SetId(fmt.Sprintf("agir-%s-%s-%s-%s", d.Get("rest_api_id").(string), d.Get(names.AttrResourceID).(string), d.Get("http_method").(string), d.Get("status_code").(string)))
d.SetId(fmt.Sprintf("agir-%s-%s-%s-%s", d.Get("rest_api_id").(string), d.Get(names.AttrResourceID).(string), d.Get("http_method").(string), d.Get(names.AttrStatusCode).(string)))
}

return append(diags, resourceIntegrationResponseRead(ctx, d, meta)...)
Expand All @@ -138,7 +138,7 @@ func resourceIntegrationResponseRead(ctx context.Context, d *schema.ResourceData
var diags diag.Diagnostics
conn := meta.(*conns.AWSClient).APIGatewayClient(ctx)

integrationResponse, err := findIntegrationResponseByFourPartKey(ctx, conn, d.Get("http_method").(string), d.Get(names.AttrResourceID).(string), d.Get("rest_api_id").(string), d.Get("status_code").(string))
integrationResponse, err := findIntegrationResponseByFourPartKey(ctx, conn, d.Get("http_method").(string), d.Get(names.AttrResourceID).(string), d.Get("rest_api_id").(string), d.Get(names.AttrStatusCode).(string))

if !d.IsNewResource() && tfresource.NotFound(err) {
log.Printf("[WARN] API Gateway Integration Response (%s) not found, removing from state", d.Id())
Expand Down Expand Up @@ -172,7 +172,7 @@ func resourceIntegrationResponseDelete(ctx context.Context, d *schema.ResourceDa
HttpMethod: aws.String(d.Get("http_method").(string)),
ResourceId: aws.String(d.Get(names.AttrResourceID).(string)),
RestApiId: aws.String(d.Get("rest_api_id").(string)),
StatusCode: aws.String(d.Get("status_code").(string)),
StatusCode: aws.String(d.Get(names.AttrStatusCode).(string)),
})

if errs.IsA[*types.NotFoundException](err) {
Expand Down
10 changes: 5 additions & 5 deletions internal/service/apigateway/integration_response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestAccAPIGatewayIntegrationResponse_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "response_templates.application/json", ""),
resource.TestCheckResourceAttr(resourceName, "response_templates.application/xml", "#set($inputRoot = $input.path('$'))\n{ }"),
resource.TestCheckResourceAttr(resourceName, "selection_pattern", ".*"),
resource.TestCheckResourceAttr(resourceName, "status_code", "400"),
resource.TestCheckResourceAttr(resourceName, names.AttrStatusCode, "400"),
),
},
{
Expand All @@ -61,7 +61,7 @@ func TestAccAPIGatewayIntegrationResponse_basic(t *testing.T) {
resource.TestCheckResourceAttr(resourceName, "response_templates.application/json", "$input.path('$')"),
resource.TestCheckResourceAttr(resourceName, "response_templates.application/xml", ""),
resource.TestCheckResourceAttr(resourceName, "selection_pattern", ""),
resource.TestCheckResourceAttr(resourceName, "status_code", "400"),
resource.TestCheckResourceAttr(resourceName, names.AttrStatusCode, "400"),
),
},
},
Expand Down Expand Up @@ -101,7 +101,7 @@ func testAccCheckIntegrationResponseExists(ctx context.Context, n string, v *api

conn := acctest.Provider.Meta().(*conns.AWSClient).APIGatewayClient(ctx)

output, err := tfapigateway.FindIntegrationResponseByFourPartKey(ctx, conn, rs.Primary.Attributes["http_method"], rs.Primary.Attributes[names.AttrResourceID], rs.Primary.Attributes["rest_api_id"], rs.Primary.Attributes["status_code"])
output, err := tfapigateway.FindIntegrationResponseByFourPartKey(ctx, conn, rs.Primary.Attributes["http_method"], rs.Primary.Attributes[names.AttrResourceID], rs.Primary.Attributes["rest_api_id"], rs.Primary.Attributes[names.AttrStatusCode])

if err != nil {
return err
Expand All @@ -122,7 +122,7 @@ func testAccCheckIntegrationResponseDestroy(ctx context.Context) resource.TestCh
continue
}

_, err := tfapigateway.FindIntegrationResponseByFourPartKey(ctx, conn, rs.Primary.Attributes["http_method"], rs.Primary.Attributes[names.AttrResourceID], rs.Primary.Attributes["rest_api_id"], rs.Primary.Attributes["status_code"])
_, err := tfapigateway.FindIntegrationResponseByFourPartKey(ctx, conn, rs.Primary.Attributes["http_method"], rs.Primary.Attributes[names.AttrResourceID], rs.Primary.Attributes["rest_api_id"], rs.Primary.Attributes[names.AttrStatusCode])

if tfresource.NotFound(err) {
continue
Expand All @@ -146,7 +146,7 @@ func testAccIntegrationResponseImportStateIdFunc(resourceName string) resource.I
return "", fmt.Errorf("Not found: %s", resourceName)
}

return fmt.Sprintf("%s/%s/%s/%s", rs.Primary.Attributes["rest_api_id"], rs.Primary.Attributes[names.AttrResourceID], rs.Primary.Attributes["http_method"], rs.Primary.Attributes["status_code"]), nil
return fmt.Sprintf("%s/%s/%s/%s", rs.Primary.Attributes["rest_api_id"], rs.Primary.Attributes[names.AttrResourceID], rs.Primary.Attributes["http_method"], rs.Primary.Attributes[names.AttrStatusCode]), nil
}
}

Expand Down
Loading
Loading