github-vet / github-vet/rangeloop-pointer-findings

GoogleCloudPlatform/terraformer: providers/aws/api_gateway.go; 93 LoC

Open
#16,890 0 comments 0 reactions 0 assignees View on GitHub
fresh medium
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [GoogleCloudPlatform/terraformer](https://www.github.com/GoogleCloudPlatform/terraformer) at [providers/aws/api_gateway.go](https://github.com/GoogleCloudPlatform/terraformer/blob/344f6a3c6343adc91eeda555efa3a352f07f4a5e/providers/aws/api_gateway.go#L185-L277)

Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first issue it finds, so please do not limit your consideration to the contents of the below message.

> reference to httpMethod was used in a composite literal at line 208

[Click here to see the code in its original context.](https://github.com/GoogleCloudPlatform/terraformer/blob/344f6a3c6343adc91eeda555efa3a352f07f4a5e/providers/aws/api_gateway.go#L185-L277)

Click here to show the 93 line(s) of Go which triggered the analyzer.

```go
for httpMethod, method := range resource.ResourceMethods {
methodID := *restAPIID + "/" + *resource.Id + "/" + httpMethod
authorizationType := "NONE"
if method.AuthorizationType != nil {
authorizationType = *method.AuthorizationType
}

g.Resources = append(g.Resources, terraformutils.NewResource(
methodID,
methodID,
"aws_api_gateway_method",
"aws",
map[string]string{
"rest_api_id": *restAPIID,
"resource_id": *resource.Id,
"http_method": httpMethod,
"authorization": authorizationType,
},
apiGatewayAllowEmptyValues,
map[string]interface{}{},
))

methodDetails, err := svc.GetMethodRequest(&apigateway.GetMethodInput{
HttpMethod: &httpMethod,
ResourceId: resource.Id,
RestApiId: restAPIID,
}).Send(context.Background())
if err != nil {
return err
}

if methodDetails.MethodIntegration != nil {
typeString, _ := methodDetails.MethodIntegration.Type.MarshalValue()
g.Resources = append(g.Resources, terraformutils.NewResource(
methodID,
methodID,
"aws_api_gateway_integration",
"aws",
map[string]string{
"rest_api_id": *restAPIID,
"resource_id": *resource.Id,
"http_method": httpMethod,
"type": typeString,
},
apiGatewayAllowEmptyValues,
map[string]interface{}{},
))
integrationDetails, err := svc.GetIntegrationRequest(&apigateway.GetIntegrationInput{
HttpMethod: &httpMethod,
ResourceId: resource.Id,
RestApiId: restAPIID,
}).Send(context.Background())
if err != nil {
return err
}

for responseCode := range integrationDetails.IntegrationResponses {
integrationResponseID := *restAPIID + "/" + *resource.Id + "/" + httpMethod + "/" + responseCode
g.Resources = append(g.Resources, terraformutils.NewResource(
integrationResponseID,
integrationResponseID,
"aws_api_gateway_integration_response",
"aws",
map[string]string{
"rest_api_id": *restAPIID,
"resource_id": *resource.Id,
"http_method": httpMethod,
"status_code": responseCode,
},
apiGatewayAllowEmptyValues,
map[string]interface{}{},
))
}
}
for responseCode := range methodDetails.MethodResponses {
responseID := *restAPIID + "/" + *resource.Id + "/" + httpMethod + "/" + responseCode

g.Resources = append(g.Resources, terraformutils.NewResource(
responseID,
responseID,
"aws_api_gateway_method_response",
"aws",
map[string]string{
"rest_api_id": *restAPIID,
"resource_id": *resource.Id,
"http_method": httpMethod,
"status_code": responseCode,
},
apiGatewayAllowEmptyValues,
map[string]interface{}{},
))
}
}

```

Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.

commit ID: 344f6a3c6343adc91eeda555efa3a352f07f4a5e

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.