Merge pull request #1380 from snyk/fix/apigatewayv2_mapping_panic
Fix panic in apigatewayv2_api_mapping enumeratormain
commit
b0cda12d1c
|
@ -38,15 +38,21 @@ func (e *ApiGatewayV2MappingEnumerator) Enumerate() ([]*resource.Resource, error
|
|||
return nil, remoteerror.NewResourceListingError(err, string(e.SupportedType()))
|
||||
}
|
||||
for _, mapping := range mappings {
|
||||
attrs := make(map[string]interface{})
|
||||
|
||||
if mapping.ApiId != nil {
|
||||
attrs["api_id"] = *mapping.ApiId
|
||||
}
|
||||
if mapping.Stage != nil {
|
||||
attrs["stage"] = *mapping.Stage
|
||||
}
|
||||
|
||||
results = append(
|
||||
results,
|
||||
e.factory.CreateAbstractResource(
|
||||
string(e.SupportedType()),
|
||||
*mapping.ApiMappingId,
|
||||
map[string]interface{}{
|
||||
"stage": *mapping.Stage,
|
||||
"api_id": *mapping.ApiId,
|
||||
},
|
||||
attrs,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -961,6 +961,34 @@ func TestApiGatewayV2Mapping(t *testing.T) {
|
|||
},
|
||||
wantErr: remoteerr.NewResourceListingError(dummyError, resourceaws.AwsApiGatewayV2MappingResourceType),
|
||||
},
|
||||
{
|
||||
test: "returning mapping with invalid attributes",
|
||||
mocks: func(repositoryV1 *repository.MockApiGatewayRepository, repository *repository.MockApiGatewayV2Repository, alerter *mocks.AlerterInterface) {
|
||||
repositoryV1.On("ListAllDomainNames").Return([]*apigateway.DomainName{
|
||||
{DomainName: awssdk.String("example.com")},
|
||||
}, nil)
|
||||
repository.On("ListAllApiMappings", "example.com").
|
||||
Return([]*apigatewayv2.ApiMapping{
|
||||
{
|
||||
ApiMappingId: awssdk.String("barfoo"),
|
||||
},
|
||||
{
|
||||
Stage: awssdk.String("a-stage"),
|
||||
ApiId: awssdk.String("foobar"),
|
||||
ApiMappingId: awssdk.String("foobar"),
|
||||
},
|
||||
}, nil)
|
||||
},
|
||||
assertExpected: func(t *testing.T, got []*resource.Resource) {
|
||||
assert.Len(t, got, 2)
|
||||
|
||||
assert.Equal(t, "barfoo", got[0].ResourceId())
|
||||
assert.Equal(t, resourceaws.AwsApiGatewayV2MappingResourceType, got[0].ResourceType())
|
||||
|
||||
assert.Equal(t, "foobar", got[1].ResourceId())
|
||||
assert.Equal(t, resourceaws.AwsApiGatewayV2MappingResourceType, got[1].ResourceType())
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
providerVersion := "3.19.0"
|
||||
|
|
|
@ -8,10 +8,16 @@ func initAwsApiGatewayV2MappingMetaData(resourceSchemaRepository resource.Schema
|
|||
resourceSchemaRepository.SetHumanReadableAttributesFunc(
|
||||
AwsApiGatewayV2MappingResourceType,
|
||||
func(res *resource.Resource) map[string]string {
|
||||
return map[string]string{
|
||||
"Api": *res.Attributes().GetString("api_id"),
|
||||
"Stage": *res.Attributes().GetString("stage"),
|
||||
attrs := make(map[string]string)
|
||||
|
||||
if v := res.Attributes().GetString("api_id"); v != nil {
|
||||
attrs["Api"] = *v
|
||||
}
|
||||
if v := res.Attributes().GetString("stage"); v != nil {
|
||||
attrs["Stage"] = *v
|
||||
}
|
||||
|
||||
return attrs
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue