Skip to content

Commit

Permalink
Restores prefer-aws-go-sdk-pointer-conversion-assignment rule
Browse files Browse the repository at this point in the history
  • Loading branch information
gdavison committed Nov 16, 2021
1 parent 182339f commit b9bd5b2
Show file tree
Hide file tree
Showing 55 changed files with 213 additions and 697 deletions.
37 changes: 17 additions & 20 deletions .semgrep.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,24 @@ rules:
languages: [go]
message: Prefer AWS Go SDK pointer conversion functions for dereferencing during assignment, e.g. aws.StringValue()
paths:
exclude:
- aws/cloudfront_distribution_configuration_structure.go
- aws/data_source_aws_route_table.go
- aws/opsworks_layers.go
- aws/resource_aws_d*
- aws/resource_aws_e*
- aws/resource_aws_g*
- aws/resource_aws_i*
- aws/resource_aws_k*
- aws/resource_aws_l*
- aws/resource_aws_mq_broker.go
- aws/resource_aws_o*
- aws/resource_aws_r*
- aws/resource_aws_s*
- aws/structure.go
- aws/waf_helpers.go
- aws/internal/generators/
- aws/internal/keyvaluetags/
- providerlint/vendor/
include:
- aws/
- internal/service
exclude:
- internal/service/ec2
- internal/service/elasticbeanstalk
- internal/service/elasticsearch
- internal/service/elb
- internal/service/emr
- internal/service/gamelift
- internal/service/iam
- internal/service/lambda
- internal/service/opsworks
- internal/service/rds
- internal/service/redshift
- internal/service/route53
- internal/service/s3
- internal/service/servicediscovery
- internal/service/ssm
patterns:
- pattern: '$LHS = *$RHS'
- pattern-not: '*$LHS2 = *$RHS'
Expand Down
4 changes: 2 additions & 2 deletions internal/service/apigateway/flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ func FlattenThrottleSettings(settings *apigateway.ThrottleSettings) []map[string
if settings != nil {
r := make(map[string]interface{})
if settings.BurstLimit != nil {
r["burst_limit"] = *settings.BurstLimit
r["burst_limit"] = aws.Int64Value(settings.BurstLimit)
}

if settings.RateLimit != nil {
r["rate_limit"] = *settings.RateLimit
r["rate_limit"] = aws.Float64Value(settings.RateLimit)
}

result = append(result, r)
Expand Down
30 changes: 13 additions & 17 deletions internal/service/autoscaling/launch_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -744,15 +744,11 @@ func readBlockDevicesFromLaunchConfiguration(d *schema.ResourceData, lc *autosca
if len(lc.BlockDeviceMappings) == 0 {
return nil, nil
}
rootDeviceName, err := fetchRootDeviceName(d.Get("image_id").(string), ec2conn)
v, err := fetchRootDeviceName(d.Get("image_id").(string), ec2conn)
if err != nil {
return nil, err
}
if rootDeviceName == nil {
// We do this so the value is empty so we don't have to do nil checks later
var blank string
rootDeviceName = &blank
}
rootDeviceName := aws.StringValue(v)

// Collect existing configured devices, so we can check
// existing value of delete_on_termination below
Expand All @@ -777,41 +773,41 @@ func readBlockDevicesFromLaunchConfiguration(d *schema.ResourceData, lc *autosca
}
bd["delete_on_termination"] = deleteOnTermination
} else if bdm.Ebs != nil && bdm.Ebs.DeleteOnTermination != nil {
bd["delete_on_termination"] = *bdm.Ebs.DeleteOnTermination
bd["delete_on_termination"] = aws.BoolValue(bdm.Ebs.DeleteOnTermination)
}

if bdm.Ebs != nil && bdm.Ebs.VolumeSize != nil {
bd["volume_size"] = *bdm.Ebs.VolumeSize
bd["volume_size"] = aws.Int64Value(bdm.Ebs.VolumeSize)
}
if bdm.Ebs != nil && bdm.Ebs.VolumeType != nil {
bd["volume_type"] = *bdm.Ebs.VolumeType
bd["volume_type"] = aws.StringValue(bdm.Ebs.VolumeType)
}
if bdm.Ebs != nil && bdm.Ebs.Iops != nil {
bd["iops"] = *bdm.Ebs.Iops
bd["iops"] = aws.Int64Value(bdm.Ebs.Iops)
}
if bdm.Ebs != nil && bdm.Ebs.Throughput != nil {
bd["throughput"] = *bdm.Ebs.Throughput
bd["throughput"] = aws.Int64Value(bdm.Ebs.Throughput)
}
if bdm.Ebs != nil && bdm.Ebs.Encrypted != nil {
bd["encrypted"] = *bdm.Ebs.Encrypted
bd["encrypted"] = aws.BoolValue(bdm.Ebs.Encrypted)
}

if bdm.DeviceName != nil && *bdm.DeviceName == *rootDeviceName {
if bdm.DeviceName != nil && aws.StringValue(bdm.DeviceName) == rootDeviceName {
blockDevices["root"] = bd
} else {
if bdm.DeviceName != nil {
bd["device_name"] = *bdm.DeviceName
bd["device_name"] = aws.StringValue(bdm.DeviceName)
}

if bdm.VirtualName != nil {
bd["virtual_name"] = *bdm.VirtualName
bd["virtual_name"] = aws.StringValue(bdm.VirtualName)
blockDevices["ephemeral"] = append(blockDevices["ephemeral"].([]map[string]interface{}), bd)
} else {
if bdm.Ebs != nil && bdm.Ebs.SnapshotId != nil {
bd["snapshot_id"] = *bdm.Ebs.SnapshotId
bd["snapshot_id"] = aws.StringValue(bdm.Ebs.SnapshotId)
}
if bdm.NoDevice != nil {
bd["no_device"] = *bdm.NoDevice
bd["no_device"] = aws.BoolValue(bdm.NoDevice)
}
blockDevices["ebs"] = append(blockDevices["ebs"].([]map[string]interface{}), bd)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/service/autoscaling/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func sweepLaunchConfigurations(region string) error {
}

for _, lc := range resp.LaunchConfigurations {
name := *lc.LaunchConfigurationName
name := aws.StringValue(lc.LaunchConfigurationName)

log.Printf("[INFO] Deleting Launch Configuration: %s", name)
_, err := conn.DeleteLaunchConfiguration(
Expand Down
8 changes: 4 additions & 4 deletions internal/service/cloudformation/flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ func expandParameters(params map[string]interface{}) []*cloudformation.Parameter
func flattenAllCloudFormationParameters(cfParams []*cloudformation.Parameter) map[string]interface{} {
params := make(map[string]interface{}, len(cfParams))
for _, p := range cfParams {
params[*p.ParameterKey] = *p.ParameterValue
params[aws.StringValue(p.ParameterKey)] = aws.StringValue(p.ParameterValue)
}
return params
}

func flattenOutputs(cfOutputs []*cloudformation.Output) map[string]string {
outputs := make(map[string]string, len(cfOutputs))
for _, o := range cfOutputs {
outputs[*o.OutputKey] = *o.OutputValue
outputs[aws.StringValue(o.OutputKey)] = aws.StringValue(o.OutputValue)
}
return outputs
}
Expand All @@ -40,9 +40,9 @@ func flattenParameters(cfParams []*cloudformation.Parameter,
originalParams map[string]interface{}) map[string]interface{} {
params := make(map[string]interface{}, len(cfParams))
for _, p := range cfParams {
_, isConfigured := originalParams[*p.ParameterKey]
_, isConfigured := originalParams[aws.StringValue(p.ParameterKey)]
if isConfigured {
params[*p.ParameterKey] = *p.ParameterValue
params[aws.StringValue(p.ParameterKey)] = aws.StringValue(p.ParameterValue)
}
}
return params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ func flattenCacheBehavior(cb *cloudfront.CacheBehavior) map[string]interface{} {
m["max_ttl"] = int(*cb.MaxTTL)
}
if cb.SmoothStreaming != nil {
m["smooth_streaming"] = *cb.SmoothStreaming
m["smooth_streaming"] = aws.BoolValue(cb.SmoothStreaming)
}
if cb.DefaultTTL != nil {
m["default_ttl"] = int(*cb.DefaultTTL)
Expand All @@ -398,7 +398,7 @@ func flattenCacheBehavior(cb *cloudfront.CacheBehavior) map[string]interface{} {
m["cached_methods"] = FlattenCachedMethods(cb.AllowedMethods.CachedMethods)
}
if cb.PathPattern != nil {
m["path_pattern"] = *cb.PathPattern
m["path_pattern"] = aws.StringValue(cb.PathPattern)
}
return m
}
Expand Down Expand Up @@ -1154,7 +1154,7 @@ func FlattenCustomErrorResponse(er *cloudfront.CustomErrorResponse) map[string]i
m["response_code"], _ = strconv.Atoi(*er.ResponseCode)
}
if er.ResponsePagePath != nil {
m["response_page_path"] = *er.ResponsePagePath
m["response_page_path"] = aws.StringValue(er.ResponsePagePath)
}
return m
}
Expand Down Expand Up @@ -1285,18 +1285,18 @@ func flattenViewerCertificate(vc *cloudfront.ViewerCertificate) []interface{} {
m := make(map[string]interface{})

if vc.IAMCertificateId != nil {
m["iam_certificate_id"] = *vc.IAMCertificateId
m["ssl_support_method"] = *vc.SSLSupportMethod
m["iam_certificate_id"] = aws.StringValue(vc.IAMCertificateId)
m["ssl_support_method"] = aws.StringValue(vc.SSLSupportMethod)
}
if vc.ACMCertificateArn != nil {
m["acm_certificate_arn"] = *vc.ACMCertificateArn
m["ssl_support_method"] = *vc.SSLSupportMethod
m["acm_certificate_arn"] = aws.StringValue(vc.ACMCertificateArn)
m["ssl_support_method"] = aws.StringValue(vc.SSLSupportMethod)
}
if vc.CloudFrontDefaultCertificate != nil {
m["cloudfront_default_certificate"] = *vc.CloudFrontDefaultCertificate
m["cloudfront_default_certificate"] = aws.BoolValue(vc.CloudFrontDefaultCertificate)
}
if vc.MinimumProtocolVersion != nil {
m["minimum_protocol_version"] = *vc.MinimumProtocolVersion
m["minimum_protocol_version"] = aws.StringValue(vc.MinimumProtocolVersion)
}
return []interface{}{m}
}
Expand Down
34 changes: 9 additions & 25 deletions internal/service/cognitoidentity/flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ func flattenIdentityPoolRoleMappingsAttachment(rms map[string]*cognitoidentity.R
}

if v.Type != nil {
m["type"] = *v.Type
m["type"] = aws.StringValue(v.Type)
}

if v.AmbiguousRoleResolution != nil {
m["ambiguous_role_resolution"] = *v.AmbiguousRoleResolution
m["ambiguous_role_resolution"] = aws.StringValue(v.AmbiguousRoleResolution)
}

if v.RulesConfiguration != nil && v.RulesConfiguration.Rules != nil {
Expand All @@ -128,23 +128,15 @@ func flattenIdentityPoolRoleMappingsAttachment(rms map[string]*cognitoidentity.R
return roleMappings
}

func flattenIdentityPoolRoles(config map[string]*string) map[string]string {
m := map[string]string{}
for k, v := range config {
m[k] = *v
}
return m
}

func flattenIdentityPoolRolesAttachmentMappingRules(d []*cognitoidentity.MappingRule) []interface{} {
rules := make([]interface{}, 0)

for _, rule := range d {
r := make(map[string]interface{})
r["claim"] = *rule.Claim
r["match_type"] = *rule.MatchType
r["role_arn"] = *rule.RoleARN
r["value"] = *rule.Value
r["claim"] = aws.StringValue(rule.Claim)
r["match_type"] = aws.StringValue(rule.MatchType)
r["role_arn"] = aws.StringValue(rule.RoleARN)
r["value"] = aws.StringValue(rule.Value)

rules = append(rules, r)
}
Expand All @@ -163,27 +155,19 @@ func flattenIdentityProviders(ips []*cognitoidentity.Provider) []map[string]inte
}

if v.ClientId != nil {
ip["client_id"] = *v.ClientId
ip["client_id"] = aws.StringValue(v.ClientId)
}

if v.ProviderName != nil {
ip["provider_name"] = *v.ProviderName
ip["provider_name"] = aws.StringValue(v.ProviderName)
}

if v.ServerSideTokenCheck != nil {
ip["server_side_token_check"] = *v.ServerSideTokenCheck
ip["server_side_token_check"] = aws.BoolValue(v.ServerSideTokenCheck)
}

values = append(values, ip)
}

return values
}

func flattenSupportedLoginProviders(config map[string]*string) map[string]string {
m := map[string]string{}
for k, v := range config {
m[k] = *v
}
return m
}
10 changes: 5 additions & 5 deletions internal/service/cognitoidentity/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,19 +204,19 @@ func resourcePoolRead(d *schema.ResourceData, meta interface{}) error {
}

if err := d.Set("cognito_identity_providers", flattenIdentityProviders(ip.CognitoIdentityProviders)); err != nil {
return fmt.Errorf("Error setting cognito_identity_providers error: %#v", err)
return fmt.Errorf("Error setting cognito_identity_providers error: %w", err)
}

if err := d.Set("openid_connect_provider_arns", flex.FlattenStringList(ip.OpenIdConnectProviderARNs)); err != nil {
return fmt.Errorf("Error setting openid_connect_provider_arns error: %#v", err)
return fmt.Errorf("Error setting openid_connect_provider_arns error: %w", err)
}

if err := d.Set("saml_provider_arns", flex.FlattenStringList(ip.SamlProviderARNs)); err != nil {
return fmt.Errorf("Error setting saml_provider_arns error: %#v", err)
return fmt.Errorf("Error setting saml_provider_arns error: %w", err)
}

if err := d.Set("supported_login_providers", flattenSupportedLoginProviders(ip.SupportedLoginProviders)); err != nil {
return fmt.Errorf("Error setting supported_login_providers error: %#v", err)
if err := d.Set("supported_login_providers", aws.StringValueMap(ip.SupportedLoginProviders)); err != nil {
return fmt.Errorf("Error setting supported_login_providers error: %w", err)
}

return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/service/cognitoidentity/pool_roles_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func resourcePoolRolesAttachmentRead(d *schema.ResourceData, meta interface{}) e

d.Set("identity_pool_id", ip.IdentityPoolId)

if err := d.Set("roles", flattenIdentityPoolRoles(ip.Roles)); err != nil {
if err := d.Set("roles", aws.StringValueMap(ip.Roles)); err != nil {
return fmt.Errorf("Error setting roles error: %#v", err)
}

Expand Down
22 changes: 11 additions & 11 deletions internal/service/configservice/flex.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ func flattenRecordingGroup(g *configservice.RecordingGroup) []map[string]interfa
m := make(map[string]interface{}, 1)

if g.AllSupported != nil {
m["all_supported"] = *g.AllSupported
m["all_supported"] = aws.BoolValue(g.AllSupported)
}

if g.IncludeGlobalResourceTypes != nil {
m["include_global_resource_types"] = *g.IncludeGlobalResourceTypes
m["include_global_resource_types"] = aws.BoolValue(g.IncludeGlobalResourceTypes)
}

if g.ResourceTypes != nil && len(g.ResourceTypes) > 0 {
Expand All @@ -183,16 +183,16 @@ func flattenRuleScope(scope *configservice.Scope) []interface{} {

m := make(map[string]interface{})
if scope.ComplianceResourceId != nil {
m["compliance_resource_id"] = *scope.ComplianceResourceId
m["compliance_resource_id"] = aws.StringValue(scope.ComplianceResourceId)
}
if scope.ComplianceResourceTypes != nil {
m["compliance_resource_types"] = flex.FlattenStringSet(scope.ComplianceResourceTypes)
}
if scope.TagKey != nil {
m["tag_key"] = *scope.TagKey
m["tag_key"] = aws.StringValue(scope.TagKey)
}
if scope.TagValue != nil {
m["tag_value"] = *scope.TagValue
m["tag_value"] = aws.StringValue(scope.TagValue)
}

items = append(items, m)
Expand All @@ -202,8 +202,8 @@ func flattenRuleScope(scope *configservice.Scope) []interface{} {
func flattenRuleSource(source *configservice.Source) []interface{} {
var result []interface{}
m := make(map[string]interface{})
m["owner"] = *source.Owner
m["source_identifier"] = *source.SourceIdentifier
m["owner"] = aws.StringValue(source.Owner)
m["source_identifier"] = aws.StringValue(source.SourceIdentifier)
if len(source.SourceDetails) > 0 {
m["source_detail"] = schema.NewSet(ruleSourceDetailsHash, flattenRuleSourceDetails(source.SourceDetails))
}
Expand All @@ -216,13 +216,13 @@ func flattenRuleSourceDetails(details []*configservice.SourceDetail) []interface
for _, d := range details {
m := make(map[string]interface{})
if d.MessageType != nil {
m["message_type"] = *d.MessageType
m["message_type"] = aws.StringValue(d.MessageType)
}
if d.EventSource != nil {
m["event_source"] = *d.EventSource
m["event_source"] = aws.StringValue(d.EventSource)
}
if d.MaximumExecutionFrequency != nil {
m["maximum_execution_frequency"] = *d.MaximumExecutionFrequency
m["maximum_execution_frequency"] = aws.StringValue(d.MaximumExecutionFrequency)
}

items = append(items, m)
Expand All @@ -235,7 +235,7 @@ func flattenSnapshotDeliveryProperties(p *configservice.ConfigSnapshotDeliveryPr
m := make(map[string]interface{})

if p.DeliveryFrequency != nil {
m["delivery_frequency"] = *p.DeliveryFrequency
m["delivery_frequency"] = aws.StringValue(p.DeliveryFrequency)
}

return []map[string]interface{}{m}
Expand Down
Loading

0 comments on commit b9bd5b2

Please sign in to comment.