From ae88e621db6244cf6db7c0f7ef15dd9bc569f449 Mon Sep 17 00:00:00 2001 From: Dominik Richter Date: Mon, 18 Mar 2024 18:53:54 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix=20unset=20fromPort/toPort=20?= =?UTF-8?q?and=20port=20on=20aws=20resources=20(#3594)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the fromPort and toPort on security groups are not set, they are not internally treated as 0, but rather -1 (which is similar to unset). Technically we could even expose the unset state, but we should reserve that for the future. I also updated a few other occurances of port to make it show up as -1. The code for number handling in AWS responses has been further simplified. Signed-off-by: Dominik Richter --- llx/rawdata.go | 14 ++++++++--- llx/rawdata_test.go | 2 +- providers-sdk/v1/util/convert/pointers.go | 21 ---------------- .../resources/aws_applicationautoscaling.go | 4 ++-- providers/aws/resources/aws_autoscaling.go | 8 +++---- providers/aws/resources/aws_cloudfront.go | 4 ++-- providers/aws/resources/aws_cloudwatch.go | 2 +- providers/aws/resources/aws_ec2.go | 22 ++++++++--------- providers/aws/resources/aws_elasticache.go | 4 ++-- providers/aws/resources/aws_emr.go | 2 +- providers/aws/resources/aws_iam.go | 6 ++--- providers/aws/resources/aws_lambda.go | 7 +++--- providers/aws/resources/aws_rds.go | 24 +++++++++---------- providers/aws/resources/aws_redshift.go | 4 ++-- providers/aws/resources/aws_s3.go | 2 +- providers/aws/resources/aws_vpc.go | 2 +- providers/azure/resources/network.go | 6 ++--- providers/azure/resources/sql.go | 2 +- providers/azure/resources/storage.go | 18 +++++++------- providers/github/resources/github_org.go | 12 +++++----- providers/ms365/resources/devicemanagement.go | 4 ++-- providers/ms365/resources/domains.go | 7 +++--- providers/ms365/resources/securescores.go | 4 ++-- 23 files changed, 83 insertions(+), 98 deletions(-) diff --git a/llx/rawdata.go b/llx/rawdata.go index 9b5f4cedf1..a454985b8b 100644 --- a/llx/rawdata.go +++ b/llx/rawdata.go @@ -438,21 +438,29 @@ var BoolFalse = BoolData(false) var BoolTrue = BoolData(true) // IntData creates a rawdata struct from a go int -func IntData(v int64) *RawData { +func IntData[T int64 | int32 | int](v T) *RawData { return &RawData{ Type: types.Int, - Value: v, + Value: int64(v), } } // IntDataPtr creates a rawdata struct from a go int pointer -func IntDataPtr(v *int64) *RawData { +func IntDataPtr[T int64 | int32 | int](v *T) *RawData { if v == nil { return NilData } return IntData(*v) } +// IntDataDefault creates a rawdata struct from a go int pointer with a fallback default value +func IntDataDefault[T int64 | int32 | int](v *T, dflt int64) *RawData { + if v == nil { + return IntData(dflt) + } + return IntData(*v) +} + // FloatData creates a rawdata struct from a go float func FloatData(v float64) *RawData { return &RawData{ diff --git a/llx/rawdata_test.go b/llx/rawdata_test.go index c19ed74648..fd57764ab1 100644 --- a/llx/rawdata_test.go +++ b/llx/rawdata_test.go @@ -31,7 +31,7 @@ func TestRawData_String(t *testing.T) { {BoolDataPtr(nil), ""}, {IntData(0), "0"}, {IntDataPtr(&intVal), "1"}, - {IntDataPtr(nil), ""}, + {IntDataPtr[int](nil), ""}, {FloatData(123), "123"}, {StringData("yo"), "\"yo\""}, {StringDataPtr(nil), ""}, diff --git a/providers-sdk/v1/util/convert/pointers.go b/providers-sdk/v1/util/convert/pointers.go index 20d99bb904..89ca96b607 100644 --- a/providers-sdk/v1/util/convert/pointers.go +++ b/providers-sdk/v1/util/convert/pointers.go @@ -24,27 +24,6 @@ func ToString(ptr *string) string { return *ptr } -func ToInt64(ptr *int64) int64 { - if ptr == nil { - return 0 - } - return *ptr -} - -func ToInt64From32(ptr *int32) int64 { - if ptr == nil { - return 0 - } - return int64(*ptr) -} - -func ToInt64FromInt(ptr *int) int64 { - if ptr == nil { - return 0 - } - return int64(*ptr) -} - func ToFloat64(ptr *float64) float64 { if ptr == nil { return 0 diff --git a/providers/aws/resources/aws_applicationautoscaling.go b/providers/aws/resources/aws_applicationautoscaling.go index ed65a96f2c..00603ba120 100644 --- a/providers/aws/resources/aws_applicationautoscaling.go +++ b/providers/aws/resources/aws_applicationautoscaling.go @@ -89,8 +89,8 @@ func (a *mqlAwsApplicationAutoscaling) getTargets(conn *connection.AwsConnection "arn": llx.StringData(fmt.Sprintf("arn:aws:application-autoscaling:%s:%s:%s/%s", regionVal, conn.AccountId(), namespace, convert.ToString(target.ResourceId))), "namespace": llx.StringData(string(target.ServiceNamespace)), "scalableDimension": llx.StringData(string(target.ScalableDimension)), - "minCapacity": llx.IntData(convert.ToInt64From32(target.MinCapacity)), - "maxCapacity": llx.IntData(convert.ToInt64From32(target.MaxCapacity)), + "minCapacity": llx.IntDataDefault(target.MinCapacity, 0), + "maxCapacity": llx.IntDataDefault(target.MaxCapacity, 0), "suspendedState": llx.MapData(targetState, types.Any), }) if err != nil { diff --git a/providers/aws/resources/aws_autoscaling.go b/providers/aws/resources/aws_autoscaling.go index de57f828f4..f4e33772dc 100644 --- a/providers/aws/resources/aws_autoscaling.go +++ b/providers/aws/resources/aws_autoscaling.go @@ -82,11 +82,11 @@ func (a *mqlAwsAutoscaling) getGroups(conn *connection.AwsConnection) []*jobpool "healthCheckType": llx.StringDataPtr(group.HealthCheckType), "tags": llx.MapData(autoscalingTagsToMap(group.Tags), types.String), "region": llx.StringData(regionVal), - "minSize": llx.IntData(convert.ToInt64From32(group.MinSize)), - "maxSize": llx.IntData(convert.ToInt64From32(group.MaxSize)), - "defaultCooldown": llx.IntData(convert.ToInt64From32(group.DefaultCooldown)), + "minSize": llx.IntDataDefault(group.MinSize, 0), + "maxSize": llx.IntDataDefault(group.MaxSize, 0), + "defaultCooldown": llx.IntDataDefault(group.DefaultCooldown, 0), "launchConfigurationName": llx.StringDataPtr(group.LaunchConfigurationName), - "healthCheckGracePeriod": llx.IntData(convert.ToInt64From32(group.HealthCheckGracePeriod)), + "healthCheckGracePeriod": llx.IntDataDefault(group.HealthCheckGracePeriod, 0), "createdAt": llx.TimeDataPtr(group.CreatedTime), }) if err != nil { diff --git a/providers/aws/resources/aws_cloudfront.go b/providers/aws/resources/aws_cloudfront.go index 4e2b4721d5..0c41ab8e1c 100644 --- a/providers/aws/resources/aws_cloudfront.go +++ b/providers/aws/resources/aws_cloudfront.go @@ -54,8 +54,8 @@ func (a *mqlAwsCloudfront) distributions() ([]interface{}, error) { map[string]*llx.RawData{ "domainName": llx.StringDataPtr(o.DomainName), "id": llx.StringDataPtr(o.Id), - "connectionAttempts": llx.IntData(convert.ToInt64From32(o.ConnectionAttempts)), - "connectionTimeout": llx.IntData(convert.ToInt64From32(o.ConnectionTimeout)), + "connectionAttempts": llx.IntDataDefault(o.ConnectionAttempts, 0), + "connectionTimeout": llx.IntDataDefault(o.ConnectionTimeout, 0), "originPath": llx.StringDataPtr(o.OriginPath), "account": llx.StringData(conn.AccountId()), }) diff --git a/providers/aws/resources/aws_cloudwatch.go b/providers/aws/resources/aws_cloudwatch.go index ecfa5506fa..a1be27ad68 100644 --- a/providers/aws/resources/aws_cloudwatch.go +++ b/providers/aws/resources/aws_cloudwatch.go @@ -608,7 +608,7 @@ func (a *mqlAwsCloudwatch) getLogGroups(conn *connection.AwsConnection) []*jobpo args["arn"] = llx.StringDataPtr(loggroup.Arn) args["name"] = llx.StringDataPtr(loggroup.LogGroupName) args["region"] = llx.StringData(regionVal) - args["retentionInDays"] = llx.IntData(convert.ToInt64From32(loggroup.RetentionInDays)) + args["retentionInDays"] = llx.IntDataDefault(loggroup.RetentionInDays, 0) // add kms key if there is one if loggroup.KmsKeyId != nil { diff --git a/providers/aws/resources/aws_ec2.go b/providers/aws/resources/aws_ec2.go index 23e2a6840d..04f108bf21 100644 --- a/providers/aws/resources/aws_ec2.go +++ b/providers/aws/resources/aws_ec2.go @@ -158,7 +158,7 @@ func (a *mqlAwsEc2Networkacl) entries() ([]interface{}, error) { args := map[string]*llx.RawData{ "egress": llx.BoolData(egress), "ruleAction": llx.StringData(string(entry.RuleAction)), - "ruleNumber": llx.IntData(convert.ToInt64From32(entry.RuleNumber)), + "ruleNumber": llx.IntDataDefault(entry.RuleNumber, 0), "cidrBlock": llx.StringDataPtr(entry.CidrBlock), "ipv6CidrBlock": llx.StringDataPtr(entry.Ipv6CidrBlock), "id": llx.StringData(entryId), @@ -166,8 +166,8 @@ func (a *mqlAwsEc2Networkacl) entries() ([]interface{}, error) { if entry.PortRange != nil { mqlPortRange, err := CreateResource(a.MqlRuntime, "aws.ec2.networkacl.entry.portrange", map[string]*llx.RawData{ - "from": llx.IntData(convert.ToInt64From32(entry.PortRange.From)), - "to": llx.IntData(convert.ToInt64From32(entry.PortRange.To)), + "from": llx.IntDataDefault(entry.PortRange.From, -1), + "to": llx.IntDataDefault(entry.PortRange.To, -1), "id": llx.StringData(entryId + "-" + strconv.Itoa(convert.ToIntFrom32(entry.PortRange.From))), }) if err != nil { @@ -269,8 +269,8 @@ func (a *mqlAwsEc2) getSecurityGroups(conn *connection.AwsConnection) []*jobpool mqlSecurityGroupIpPermission, err := CreateResource(a.MqlRuntime, "aws.ec2.securitygroup.ippermission", map[string]*llx.RawData{ "id": llx.StringData(convert.ToString(group.GroupId) + "-" + strconv.Itoa(p)), - "fromPort": llx.IntData(convert.ToInt64From32(permission.FromPort)), - "toPort": llx.IntData(convert.ToInt64From32(permission.ToPort)), + "fromPort": llx.IntDataDefault(permission.FromPort, -1), + "toPort": llx.IntDataDefault(permission.ToPort, -1), "ipProtocol": llx.StringDataPtr(permission.IpProtocol), "ipRanges": llx.ArrayData(ipRanges, types.Any), "ipv6Ranges": llx.ArrayData(ipv6Ranges, types.Any), @@ -304,8 +304,8 @@ func (a *mqlAwsEc2) getSecurityGroups(conn *connection.AwsConnection) []*jobpool mqlSecurityGroupIpPermission, err := CreateResource(a.MqlRuntime, "aws.ec2.securitygroup.ippermission", map[string]*llx.RawData{ "id": llx.StringData(convert.ToString(group.GroupId) + "-" + strconv.Itoa(p) + "-egress"), - "fromPort": llx.IntData(convert.ToInt64From32(permission.FromPort)), - "toPort": llx.IntData(convert.ToInt64From32(permission.ToPort)), + "fromPort": llx.IntDataDefault(permission.FromPort, -1), + "toPort": llx.IntDataDefault(permission.ToPort, -1), "ipProtocol": llx.StringDataPtr(permission.IpProtocol), "ipRanges": llx.ArrayData(ipRanges, types.Any), "ipv6Ranges": llx.ArrayData(ipv6Ranges, types.Any), @@ -1062,13 +1062,13 @@ func (a *mqlAwsEc2) getVolumes(conn *connection.AwsConnection) []*jobpool.Job { "createTime": llx.TimeDataPtr(vol.CreateTime), "encrypted": llx.BoolDataPtr(vol.Encrypted), "id": llx.StringDataPtr(vol.VolumeId), - "iops": llx.IntData(convert.ToInt64From32(vol.Iops)), + "iops": llx.IntDataDefault(vol.Iops, 0), "multiAttachEnabled": llx.BoolDataPtr(vol.MultiAttachEnabled), "region": llx.StringData(regionVal), - "size": llx.IntData(convert.ToInt64From32(vol.Size)), + "size": llx.IntDataDefault(vol.Size, 0), "state": llx.StringData(string(vol.State)), "tags": llx.MapData(Ec2TagsToMap(vol.Tags), types.String), - "throughput": llx.IntData(convert.ToInt64From32(vol.Throughput)), + "throughput": llx.IntDataDefault(vol.Throughput, 0), "volumeType": llx.StringData(string(vol.VolumeType)), }) if err != nil { @@ -1358,7 +1358,7 @@ func (a *mqlAwsEc2) getSnapshots(conn *connection.AwsConnection) []*jobpool.Job "state": llx.StringData(string(snapshot.State)), "tags": llx.MapData(Ec2TagsToMap(snapshot.Tags), types.String), "volumeId": llx.StringDataPtr(snapshot.VolumeId), - "volumeSize": llx.IntData(convert.ToInt64From32(snapshot.VolumeSize)), + "volumeSize": llx.IntDataDefault(snapshot.VolumeSize, 0), }) if err != nil { return nil, err diff --git a/providers/aws/resources/aws_elasticache.go b/providers/aws/resources/aws_elasticache.go index 815770b4a1..efff4acfae 100644 --- a/providers/aws/resources/aws_elasticache.go +++ b/providers/aws/resources/aws_elasticache.go @@ -195,11 +195,11 @@ func (a *mqlAwsElasticache) getCacheClusters(conn *connection.AwsConnection) []* "logDeliveryConfigurations": llx.ArrayData(logDeliveryConfigurations, types.Any), "networkType": llx.StringData(string(cluster.NetworkType)), "notificationConfiguration": llx.StringData(notificationConfiguration), - "numCacheNodes": llx.IntData(convert.ToInt64From32(cluster.NumCacheNodes)), + "numCacheNodes": llx.IntDataDefault(cluster.NumCacheNodes, 0), "preferredAvailabilityZone": llx.StringDataPtr(cluster.PreferredAvailabilityZone), "region": llx.StringData(regionVal), "securityGroups": llx.ArrayData(sgs, types.Resource("aws.ec2.securitygroup")), - "snapshotRetentionLimit": llx.IntData(convert.ToInt64From32(cluster.SnapshotRetentionLimit)), + "snapshotRetentionLimit": llx.IntDataDefault(cluster.SnapshotRetentionLimit, 0), "transitEncryptionEnabled": llx.BoolData(convert.ToBool(cluster.TransitEncryptionEnabled)), "transitEncryptionMode": llx.StringData(string(cluster.TransitEncryptionMode)), }) diff --git a/providers/aws/resources/aws_emr.go b/providers/aws/resources/aws_emr.go index c7300ed468..5ca725b7c3 100644 --- a/providers/aws/resources/aws_emr.go +++ b/providers/aws/resources/aws_emr.go @@ -77,7 +77,7 @@ func (a *mqlAwsEmr) getClusters(conn *connection.AwsConnection) []*jobpool.Job { map[string]*llx.RawData{ "arn": llx.StringDataPtr(cluster.ClusterArn), "name": llx.StringDataPtr(cluster.Name), - "normalizedInstanceHours": llx.IntData(convert.ToInt64From32(cluster.NormalizedInstanceHours)), + "normalizedInstanceHours": llx.IntDataDefault(cluster.NormalizedInstanceHours, 0), "outpostArn": llx.StringDataPtr(cluster.OutpostArn), "status": llx.MapData(jsonStatus, types.String), "id": llx.StringDataPtr(cluster.Id), diff --git a/providers/aws/resources/aws_iam.go b/providers/aws/resources/aws_iam.go index 6eac0578cd..83b0e46405 100644 --- a/providers/aws/resources/aws_iam.go +++ b/providers/aws/resources/aws_iam.go @@ -343,7 +343,7 @@ func (a *mqlAwsIam) mqlPolicies(policies []iamtypes.Policy) ([]interface{}, erro "name": llx.StringDataPtr(policy.PolicyName), "description": llx.StringDataPtr(policy.Description), "isAttachable": llx.BoolData(policy.IsAttachable), - "attachmentCount": llx.IntData(convert.ToInt64From32(policy.AttachmentCount)), + "attachmentCount": llx.IntDataDefault(policy.AttachmentCount, 0), "createDate": llx.TimeDataPtr(policy.CreateDate), "updateDate": llx.TimeDataPtr(policy.UpdateDate), }) @@ -930,10 +930,10 @@ func (a *mqlAwsIamPolicy) attachmentCount() (int64, error) { arn := a.Arn.Data policy, err := a.loadPolicy(arn) - if err != nil { + if err != nil || policy.AttachmentCount == nil { return int64(0), err } - return convert.ToInt64From32(policy.AttachmentCount), nil + return int64(*policy.AttachmentCount), nil } func (a *mqlAwsIamPolicy) createDate() (*time.Time, error) { diff --git a/providers/aws/resources/aws_lambda.go b/providers/aws/resources/aws_lambda.go index 9811110939..0aa1d00c7e 100644 --- a/providers/aws/resources/aws_lambda.go +++ b/providers/aws/resources/aws_lambda.go @@ -164,11 +164,10 @@ func (a *mqlAwsLambdaFunction) concurrency() (int64, error) { if err != nil { return 0, errors.Wrap(err, "could not gather aws lambda function concurrency") } - if functionConcurrency.ReservedConcurrentExecutions != nil { - return convert.ToInt64From32(functionConcurrency.ReservedConcurrentExecutions), nil + if functionConcurrency.ReservedConcurrentExecutions == nil { + return 0, nil } - - return 0, nil + return int64(*functionConcurrency.ReservedConcurrentExecutions), nil } func (a *mqlAwsLambdaFunction) policy() (interface{}, error) { diff --git a/providers/aws/resources/aws_rds.go b/providers/aws/resources/aws_rds.go index 4d4b4a4485..17445393c1 100644 --- a/providers/aws/resources/aws_rds.go +++ b/providers/aws/resources/aws_rds.go @@ -92,7 +92,7 @@ func (a *mqlAwsRds) getDbInstances(conn *connection.AwsConnection) []*jobpool.Jo "arn": llx.StringDataPtr(dbInstance.DBInstanceArn), "autoMinorVersionUpgrade": llx.BoolDataPtr(dbInstance.AutoMinorVersionUpgrade), "availabilityZone": llx.StringDataPtr(dbInstance.AvailabilityZone), - "backupRetentionPeriod": llx.IntData(convert.ToInt64From32(dbInstance.BackupRetentionPeriod)), + "backupRetentionPeriod": llx.IntDataDefault(dbInstance.BackupRetentionPeriod, 0), "createdTime": llx.TimeDataPtr(dbInstance.InstanceCreateTime), "dbInstanceClass": llx.StringDataPtr(dbInstance.DBInstanceClass), "dbInstanceIdentifier": llx.StringDataPtr(dbInstance.DBInstanceIdentifier), @@ -104,14 +104,14 @@ func (a *mqlAwsRds) getDbInstances(conn *connection.AwsConnection) []*jobpool.Jo "id": llx.StringDataPtr(dbInstance.DBInstanceIdentifier), "multiAZ": llx.BoolDataPtr(dbInstance.MultiAZ), "name": llx.StringDataPtr(dbInstance.DBName), - "port": llx.IntData(convert.ToInt64From32(dbInstance.DbInstancePort)), + "port": llx.IntDataDefault(dbInstance.DbInstancePort, 0), "publiclyAccessible": llx.BoolDataPtr(dbInstance.PubliclyAccessible), "region": llx.StringData(regionVal), "securityGroups": llx.ArrayData(sgs, types.Resource("aws.ec2.securitygroup")), "status": llx.StringDataPtr(dbInstance.DBInstanceStatus), - "storageAllocated": llx.IntData(convert.ToInt64From32(dbInstance.AllocatedStorage)), + "storageAllocated": llx.IntDataDefault(dbInstance.AllocatedStorage, 0), "storageEncrypted": llx.BoolDataPtr(dbInstance.StorageEncrypted), - "storageIops": llx.IntData(convert.ToInt64From32(dbInstance.Iops)), + "storageIops": llx.IntDataDefault(dbInstance.Iops, 0), "storageType": llx.StringDataPtr(dbInstance.StorageType), "tags": llx.MapData(rdsTagsToMap(dbInstance.TagList), types.String), "endpoint": llx.StringDataPtr(dbInstance.Endpoint.Address), @@ -261,7 +261,7 @@ func (a *mqlAwsRds) getDbClusters(conn *connection.AwsConnection) []*jobpool.Job "arn": llx.StringDataPtr(cluster.DBClusterArn), "autoMinorVersionUpgrade": llx.BoolDataPtr(cluster.AutoMinorVersionUpgrade), "availabilityZones": llx.ArrayData(stringSliceAZs, types.String), - "backupRetentionPeriod": llx.IntData(convert.ToInt64From32(cluster.BackupRetentionPeriod)), + "backupRetentionPeriod": llx.IntDataDefault(cluster.BackupRetentionPeriod, 0), "clusterDbInstanceClass": llx.StringDataPtr(cluster.DBClusterInstanceClass), "createdTime": llx.TimeDataPtr(cluster.ClusterCreateTime), "deletionProtection": llx.BoolDataPtr(cluster.DeletionProtection), @@ -271,14 +271,14 @@ func (a *mqlAwsRds) getDbClusters(conn *connection.AwsConnection) []*jobpool.Job "id": llx.StringDataPtr(cluster.DBClusterIdentifier), "members": llx.ArrayData(mqlRdsDbInstances, types.Resource("aws.rds.dbinstance")), "multiAZ": llx.BoolDataPtr(cluster.MultiAZ), - "port": llx.IntData(convert.ToInt64From32(cluster.Port)), + "port": llx.IntDataDefault(cluster.Port, -1), "publiclyAccessible": llx.BoolDataPtr(cluster.PubliclyAccessible), "region": llx.StringData(regionVal), "securityGroups": llx.ArrayData(sgs, types.Resource("aws.ec2.securitygroup")), "status": llx.StringDataPtr(cluster.Status), - "storageAllocated": llx.IntData(convert.ToInt64From32(cluster.AllocatedStorage)), + "storageAllocated": llx.IntDataDefault(cluster.AllocatedStorage, 0), "storageEncrypted": llx.BoolDataPtr(cluster.StorageEncrypted), - "storageIops": llx.IntData(convert.ToInt64From32(cluster.Iops)), + "storageIops": llx.IntDataDefault(cluster.Iops, 0), "storageType": llx.StringDataPtr(cluster.StorageType), "tags": llx.MapData(rdsTagsToMap(cluster.TagList), types.String), }) @@ -318,14 +318,14 @@ func (a *mqlAwsRdsDbcluster) snapshots() ([]interface{}, error) { for _, snapshot := range snapshots.DBClusterSnapshots { mqlDbSnapshot, err := CreateResource(a.MqlRuntime, "aws.rds.snapshot", map[string]*llx.RawData{ - "allocatedStorage": llx.IntData(convert.ToInt64From32(snapshot.AllocatedStorage)), + "allocatedStorage": llx.IntDataDefault(snapshot.AllocatedStorage, 0), "arn": llx.StringDataPtr(snapshot.DBClusterSnapshotArn), "createdAt": llx.TimeDataPtr(snapshot.SnapshotCreateTime), "encrypted": llx.BoolDataPtr(snapshot.StorageEncrypted), "engine": llx.StringDataPtr(snapshot.Engine), "engineVersion": llx.StringDataPtr(snapshot.EngineVersion), "id": llx.StringDataPtr(snapshot.DBClusterSnapshotIdentifier), - "port": llx.IntData(convert.ToInt64From32(snapshot.Port)), + "port": llx.IntDataDefault(snapshot.Port, -1), "isClusterSnapshot": llx.BoolData(true), "region": llx.StringData(region), "status": llx.StringDataPtr(snapshot.Status), @@ -363,14 +363,14 @@ func (a *mqlAwsRdsDbinstance) snapshots() ([]interface{}, error) { for _, snapshot := range snapshots.DBSnapshots { mqlDbSnapshot, err := CreateResource(a.MqlRuntime, "aws.rds.snapshot", map[string]*llx.RawData{ - "allocatedStorage": llx.IntData(convert.ToInt64From32(snapshot.AllocatedStorage)), + "allocatedStorage": llx.IntDataDefault(snapshot.AllocatedStorage, 0), "arn": llx.StringDataPtr(snapshot.DBSnapshotArn), "createdAt": llx.TimeDataPtr(snapshot.SnapshotCreateTime), "encrypted": llx.BoolDataPtr(snapshot.Encrypted), "engine": llx.StringDataPtr(snapshot.Engine), "engineVersion": llx.StringDataPtr(snapshot.EngineVersion), "id": llx.StringDataPtr(snapshot.DBSnapshotIdentifier), - "port": llx.IntData(convert.ToInt64From32(snapshot.Port)), + "port": llx.IntDataDefault(snapshot.Port, -1), "isClusterSnapshot": llx.BoolData(false), "region": llx.StringData(region), "status": llx.StringDataPtr(snapshot.Status), diff --git a/providers/aws/resources/aws_redshift.go b/providers/aws/resources/aws_redshift.go index eea5f583aa..b4ad1bda02 100644 --- a/providers/aws/resources/aws_redshift.go +++ b/providers/aws/resources/aws_redshift.go @@ -83,7 +83,7 @@ func (a *mqlAwsRedshift) getClusters(conn *connection.AwsConnection) []*jobpool. map[string]*llx.RawData{ "allowVersionUpgrade": llx.BoolDataPtr(cluster.AllowVersionUpgrade), "arn": llx.StringData(fmt.Sprintf(redshiftClusterArnPattern, regionVal, conn.AccountId(), convert.ToString(cluster.ClusterIdentifier))), - "automatedSnapshotRetentionPeriod": llx.IntData(convert.ToInt64From32(cluster.AutomatedSnapshotRetentionPeriod)), + "automatedSnapshotRetentionPeriod": llx.IntDataDefault(cluster.AutomatedSnapshotRetentionPeriod, 0), "availabilityZone": llx.StringDataPtr(cluster.AvailabilityZone), "clusterParameterGroupNames": llx.ArrayData(names, types.String), "clusterRevisionNumber": llx.StringDataPtr(cluster.ClusterRevisionNumber), @@ -98,7 +98,7 @@ func (a *mqlAwsRedshift) getClusters(conn *connection.AwsConnection) []*jobpool. "name": llx.StringDataPtr(cluster.ClusterIdentifier), "nextMaintenanceWindowStartTime": llx.TimeDataPtr(cluster.NextMaintenanceWindowStartTime), "nodeType": llx.StringDataPtr(cluster.NodeType), - "numberOfNodes": llx.IntData(convert.ToInt64From32(cluster.NumberOfNodes)), + "numberOfNodes": llx.IntDataDefault(cluster.NumberOfNodes, 0), "preferredMaintenanceWindow": llx.StringDataPtr(cluster.PreferredMaintenanceWindow), "publiclyAccessible": llx.BoolDataPtr(cluster.PubliclyAccessible), "region": llx.StringData(regionVal), diff --git a/providers/aws/resources/aws_s3.go b/providers/aws/resources/aws_s3.go index 2049b1c810..e09d88fa5c 100644 --- a/providers/aws/resources/aws_s3.go +++ b/providers/aws/resources/aws_s3.go @@ -434,7 +434,7 @@ func (a *mqlAwsS3Bucket) cors() ([]interface{}, error) { "allowedMethods": llx.ArrayData(toInterfaceArr(corsrule.AllowedMethods), types.String), "allowedOrigins": llx.ArrayData(toInterfaceArr(corsrule.AllowedOrigins), types.String), "exposeHeaders": llx.ArrayData(toInterfaceArr(corsrule.ExposeHeaders), types.String), - "maxAgeSeconds": llx.IntData(convert.ToInt64From32(corsrule.MaxAgeSeconds)), + "maxAgeSeconds": llx.IntDataDefault(corsrule.MaxAgeSeconds, 0), }) if err != nil { return nil, err diff --git a/providers/aws/resources/aws_vpc.go b/providers/aws/resources/aws_vpc.go index bdcf7761c0..98a4257ae5 100644 --- a/providers/aws/resources/aws_vpc.go +++ b/providers/aws/resources/aws_vpc.go @@ -182,7 +182,7 @@ func (a *mqlAwsVpc) flowLogs() ([]interface{}, error) { "destinationType": llx.StringData(string(flowLog.LogDestinationType)), "deliverLogsStatus": llx.StringDataPtr(flowLog.DeliverLogsStatus), "id": llx.StringDataPtr(flowLog.FlowLogId), - "maxAggregationInterval": llx.IntData(convert.ToInt64From32(flowLog.MaxAggregationInterval)), + "maxAggregationInterval": llx.IntDataDefault(flowLog.MaxAggregationInterval, 0), "region": llx.StringData(a.Region.Data), "status": llx.StringDataPtr(flowLog.FlowLogStatus), "tags": llx.MapData(Ec2TagsToMap(flowLog.Tags), types.String), diff --git a/providers/azure/resources/network.go b/providers/azure/resources/network.go index 16b3be874c..f393866a17 100644 --- a/providers/azure/resources/network.go +++ b/providers/azure/resources/network.go @@ -297,7 +297,7 @@ func (a *mqlAzureSubscriptionNetworkServiceWatcher) flowLogs() ([]interface{}, e "etag": llx.StringDataPtr(flowLog.Etag), "retentionPolicy": llx.DictData(retentionPolicyDict), "format": llx.StringDataPtr((*string)(flowLog.Properties.Format.Type)), - "version": llx.IntData(convert.ToInt64From32(flowLog.Properties.Format.Version)), + "version": llx.IntDataDefault(flowLog.Properties.Format.Version, 0), "enabled": llx.BoolDataPtr(flowLog.Properties.Enabled), "storageAccountId": llx.StringDataPtr(flowLog.Properties.StorageID), "targetResourceId": llx.StringDataPtr(flowLog.Properties.TargetResourceID), @@ -937,7 +937,7 @@ func (a *mqlAzureSubscriptionNetworkService) virtualNetworkGateways() ([]interfa "id": llx.StringData(bgpSettingsId), "asn": llx.IntDataPtr(vng.Properties.BgpSettings.Asn), "bgpPeeringAddress": llx.StringDataPtr(vng.Properties.BgpSettings.BgpPeeringAddress), - "peerWeight": llx.IntData(convert.ToInt64From32(vng.Properties.BgpSettings.PeerWeight)), + "peerWeight": llx.IntDataDefault(vng.Properties.BgpSettings.PeerWeight, 0), "bgpPeeringAddressesConfig": llx.ArrayData(bgpPeeringAddresses, types.ResourceLike), }) if err != nil { @@ -995,7 +995,7 @@ func (a *mqlAzureSubscriptionNetworkService) virtualNetworkGateways() ([]interfa "disableIPSecReplayProtection": llx.BoolDataPtr(vng.Properties.DisableIPSecReplayProtection), "inboundDNSForwardingEndpoint": llx.StringDataPtr(vng.Properties.InboundDNSForwardingEndpoint), "skuName": llx.StringDataPtr((*string)(vng.Properties.SKU.Name)), - "skuCapacity": llx.IntData(convert.ToInt64From32(vng.Properties.SKU.Capacity)), + "skuCapacity": llx.IntDataDefault(vng.Properties.SKU.Capacity, 0), "provisioningState": llx.StringDataPtr((*string)(vng.Properties.ProvisioningState)), "properties": llx.DictData(props), "vpnType": llx.StringDataPtr((*string)(vng.Properties.VPNType)), diff --git a/providers/azure/resources/sql.go b/providers/azure/resources/sql.go index 25195584bf..8a1ffcf07a 100644 --- a/providers/azure/resources/sql.go +++ b/providers/azure/resources/sql.go @@ -142,7 +142,7 @@ func (a *mqlAzureSubscriptionSqlServiceServer) databases() ([]interface{}, error "sourceDatabaseId": llx.StringDataPtr(entry.Properties.SourceDatabaseID), "recoveryServicesRecoveryPointResourceId": llx.StringDataPtr(entry.Properties.RecoveryServicesRecoveryPointID), "edition": llx.StringDataPtr(entry.SKU.Tier), - "maxSizeBytes": llx.IntData(convert.ToInt64(entry.Properties.MaxSizeBytes)), + "maxSizeBytes": llx.IntDataDefault(entry.Properties.MaxSizeBytes, 0), "requestedServiceObjectiveName": llx.StringDataPtr(entry.Properties.RequestedServiceObjectiveName), "serviceLevelObjective": llx.StringDataPtr(entry.Properties.CurrentServiceObjectiveName), "status": llx.StringDataPtr((*string)(entry.Properties.Status)), diff --git a/providers/azure/resources/storage.go b/providers/azure/resources/storage.go index 2cf41e4f29..4077896b5a 100644 --- a/providers/azure/resources/storage.go +++ b/providers/azure/resources/storage.go @@ -209,29 +209,29 @@ func (a *mqlAzureSubscriptionStorageServiceAccount) dataProtection() (*mqlAzureS } var blobSoftDeletionEnabled bool - var blobRetentionDays int64 + var blobRetentionDays *int32 var containerSoftDeletionEnabled bool - var containerRetentionDays int64 + var containerRetentionDays *int32 if properties.BlobServiceProperties.BlobServiceProperties.DeleteRetentionPolicy != nil { blobSoftDeletionEnabled = convert.ToBool(properties.BlobServiceProperties.BlobServiceProperties.DeleteRetentionPolicy.Enabled) } if properties.BlobServiceProperties.BlobServiceProperties.DeleteRetentionPolicy != nil { - blobRetentionDays = convert.ToInt64From32(properties.BlobServiceProperties.BlobServiceProperties.DeleteRetentionPolicy.Days) + blobRetentionDays = properties.BlobServiceProperties.BlobServiceProperties.DeleteRetentionPolicy.Days } if properties.BlobServiceProperties.BlobServiceProperties.ContainerDeleteRetentionPolicy != nil { containerSoftDeletionEnabled = convert.ToBool(properties.BlobServiceProperties.BlobServiceProperties.ContainerDeleteRetentionPolicy.Enabled) } if properties.BlobServiceProperties.BlobServiceProperties.ContainerDeleteRetentionPolicy != nil { - containerRetentionDays = convert.ToInt64From32(properties.BlobServiceProperties.BlobServiceProperties.ContainerDeleteRetentionPolicy.Days) + containerRetentionDays = properties.BlobServiceProperties.BlobServiceProperties.ContainerDeleteRetentionPolicy.Days } res, err := CreateResource(a.MqlRuntime, "azure.subscription.storageService.account.dataProtection", map[string]*llx.RawData{ "storageAccountId": llx.StringData(id), "blobSoftDeletionEnabled": llx.BoolData(blobSoftDeletionEnabled), - "blobRetentionDays": llx.IntData(blobRetentionDays), + "blobRetentionDays": llx.IntDataDefault(blobRetentionDays, 0), "containerSoftDeletionEnabled": llx.BoolData(containerSoftDeletionEnabled), - "containerRetentionDays": llx.IntData(containerRetentionDays), + "containerRetentionDays": llx.IntDataDefault(containerRetentionDays, 0), }) if err != nil { return nil, err @@ -274,7 +274,7 @@ func toMqlServiceStorageProperties(runtime *plugin.Runtime, props table.ServiceP loggingRetentionPolicy, err := CreateResource(runtime, "azure.subscription.storageService.account.service.properties.retentionPolicy", map[string]*llx.RawData{ "id": llx.StringData(fmt.Sprintf("%s/%s/properties/logging/retentionPolicy", parentId, serviceType)), - "retentionDays": llx.IntData(convert.ToInt64From32(props.Logging.RetentionPolicy.Days)), + "retentionDays": llx.IntDataDefault(props.Logging.RetentionPolicy.Days, 0), "enabled": llx.BoolDataPtr(props.Logging.RetentionPolicy.Enabled), }) if err != nil { @@ -295,7 +295,7 @@ func toMqlServiceStorageProperties(runtime *plugin.Runtime, props table.ServiceP minuteMetricsRetentionPolicy, err := CreateResource(runtime, "azure.subscription.storageService.account.service.properties.retentionPolicy", map[string]*llx.RawData{ "id": llx.StringData(fmt.Sprintf("%s/%s/properties/minuteMetrics/retentionPolicy", parentId, serviceType)), - "retentionDays": llx.IntData(convert.ToInt64From32(props.MinuteMetrics.RetentionPolicy.Days)), + "retentionDays": llx.IntDataDefault(props.MinuteMetrics.RetentionPolicy.Days, 0), "enabled": llx.BoolDataPtr(props.MinuteMetrics.RetentionPolicy.Enabled), }) if err != nil { @@ -315,7 +315,7 @@ func toMqlServiceStorageProperties(runtime *plugin.Runtime, props table.ServiceP hourMetricsRetentionPolicy, err := CreateResource(runtime, "azure.subscription.storageService.account.service.properties.retentionPolicy", map[string]*llx.RawData{ "id": llx.StringData(fmt.Sprintf("%s/%s/properties/hourMetrics/retentionPolicy", parentId, serviceType)), - "retentionDays": llx.IntData(convert.ToInt64From32(props.HourMetrics.RetentionPolicy.Days)), + "retentionDays": llx.IntDataDefault(props.HourMetrics.RetentionPolicy.Days, 0), "enabled": llx.BoolDataPtr(props.HourMetrics.RetentionPolicy.Enabled), }) if err != nil { diff --git a/providers/github/resources/github_org.go b/providers/github/resources/github_org.go index 7927a1a4cc..5e13197a6c 100644 --- a/providers/github/resources/github_org.go +++ b/providers/github/resources/github_org.go @@ -58,16 +58,16 @@ func initGithubOrganization(runtime *plugin.Runtime, args map[string]*llx.RawDat args["email"] = llx.StringDataPtr(org.Email) args["twitterUsername"] = llx.StringDataPtr(org.TwitterUsername) args["avatarUrl"] = llx.StringDataPtr(org.AvatarURL) - args["followers"] = llx.IntData(convert.ToInt64FromInt(org.Followers)) - args["following"] = llx.IntData(convert.ToInt64FromInt(org.Following)) + args["followers"] = llx.IntDataDefault(org.Followers, 0) + args["following"] = llx.IntDataDefault(org.Following, 0) args["description"] = llx.StringDataPtr(org.Description) args["createdAt"] = llx.TimeDataPtr(githubTimestamp(org.CreatedAt)) args["updatedAt"] = llx.TimeDataPtr(githubTimestamp(org.UpdatedAt)) args["totalPrivateRepos"] = llx.IntDataPtr(org.TotalPrivateRepos) args["ownedPrivateRepos"] = llx.IntDataPtr(org.OwnedPrivateRepos) - args["privateGists"] = llx.IntData(convert.ToInt64FromInt(org.PrivateGists)) - args["diskUsage"] = llx.IntData(convert.ToInt64FromInt(org.DiskUsage)) - args["collaborators"] = llx.IntData(convert.ToInt64FromInt(org.Collaborators)) + args["privateGists"] = llx.IntDataDefault(org.PrivateGists, 0) + args["diskUsage"] = llx.IntDataDefault(org.DiskUsage, 0) + args["collaborators"] = llx.IntDataDefault(org.Collaborators, 0) args["billingEmail"] = llx.StringDataPtr(org.BillingEmail) plan, _ := convert.JsonToDict(org.Plan) @@ -120,7 +120,7 @@ func (g *mqlGithubOrganization) members() ([]interface{}, error) { member := allMembers[i] r, err := NewResource(g.MqlRuntime, "github.user", map[string]*llx.RawData{ - "id": llx.IntData(convert.ToInt64(member.ID)), + "id": llx.IntDataDefault(member.ID, 0), "login": llx.StringDataPtr(member.Login), }) if err != nil { diff --git a/providers/ms365/resources/devicemanagement.go b/providers/ms365/resources/devicemanagement.go index 721bfe31a4..e8169743fc 100644 --- a/providers/ms365/resources/devicemanagement.go +++ b/providers/ms365/resources/devicemanagement.go @@ -46,7 +46,7 @@ func (a *mqlMicrosoftDevicemanagement) deviceConfigurations() ([]interface{}, er "createdDateTime": llx.TimeDataPtr(configuration.GetCreatedDateTime()), "description": llx.StringDataPtr(configuration.GetDescription()), "displayName": llx.StringDataPtr(configuration.GetDisplayName()), - "version": llx.IntData(convert.ToInt64From32(configuration.GetVersion())), + "version": llx.IntDataDefault(configuration.GetVersion(), 0), "properties": llx.DictData(properties), }) if err != nil { @@ -90,7 +90,7 @@ func (a *mqlMicrosoftDevicemanagement) deviceCompliancePolicies() ([]interface{} "description": llx.StringDataPtr(compliancePolicy.GetDescription()), "displayName": llx.StringDataPtr(compliancePolicy.GetDisplayName()), "lastModifiedDateTime": llx.TimeDataPtr(compliancePolicy.GetLastModifiedDateTime()), - "version": llx.IntData(convert.ToInt64From32(compliancePolicy.GetVersion())), + "version": llx.IntDataDefault(compliancePolicy.GetVersion(), 0), "assignments": llx.ArrayData(assignments, types.Any), "properties": llx.DictData(properties), }) diff --git a/providers/ms365/resources/domains.go b/providers/ms365/resources/domains.go index c02fb56451..7b7c00c075 100644 --- a/providers/ms365/resources/domains.go +++ b/providers/ms365/resources/domains.go @@ -9,7 +9,6 @@ import ( "github.com/microsoftgraph/msgraph-sdk-go/domains" "github.com/microsoftgraph/msgraph-sdk-go/models" "go.mondoo.com/cnquery/v10/llx" - "go.mondoo.com/cnquery/v10/providers-sdk/v1/util/convert" "go.mondoo.com/cnquery/v10/providers/ms365/connection" "go.mondoo.com/cnquery/v10/types" ) @@ -51,8 +50,8 @@ func (a *mqlMicrosoft) domains() ([]interface{}, error) { "isInitial": llx.BoolDataPtr(domain.GetIsInitial()), "isRoot": llx.BoolDataPtr(domain.GetIsRoot()), "isVerified": llx.BoolDataPtr(domain.GetIsVerified()), - "passwordNotificationWindowInDays": llx.IntData(convert.ToInt64From32(domain.GetPasswordNotificationWindowInDays())), - "passwordValidityPeriodInDays": llx.IntData(convert.ToInt64From32(domain.GetPasswordValidityPeriodInDays())), + "passwordNotificationWindowInDays": llx.IntDataDefault(domain.GetPasswordNotificationWindowInDays(), 0), + "passwordValidityPeriodInDays": llx.IntDataDefault(domain.GetPasswordValidityPeriodInDays(), 0), "supportedServices": llx.ArrayData(supportedServices, types.String), }) if err != nil { @@ -89,7 +88,7 @@ func (a *mqlMicrosoftDomain) serviceConfigurationRecords() ([]interface{}, error "label": llx.StringDataPtr(record.GetLabel()), "recordType": llx.StringDataPtr(record.GetRecordType()), "supportedService": llx.StringDataPtr(record.GetSupportedService()), - "ttl": llx.IntData(convert.ToInt64From32(record.GetTtl())), + "ttl": llx.IntDataDefault(record.GetTtl(), 0), "properties": llx.DictData(properties), }) if err != nil { diff --git a/providers/ms365/resources/securescores.go b/providers/ms365/resources/securescores.go index 7170478eb6..e0db485d94 100644 --- a/providers/ms365/resources/securescores.go +++ b/providers/ms365/resources/securescores.go @@ -56,14 +56,14 @@ func msSecureScoreToMql(runtime *plugin.Runtime, score models.SecureScoreable) ( mqlResource, err := CreateResource(runtime, "microsoft.security.securityscore", map[string]*llx.RawData{ "id": llx.StringDataPtr(score.GetId()), - "activeUserCount": llx.IntData(convert.ToInt64From32(score.GetActiveUserCount())), + "activeUserCount": llx.IntDataDefault(score.GetActiveUserCount(), 0), "averageComparativeScores": llx.ArrayData(averageComparativeScores, types.Any), "azureTenantId": llx.StringDataPtr(score.GetAzureTenantId()), "controlScores": llx.ArrayData(controlScores, types.Any), "createdDateTime": llx.TimeDataPtr(score.GetCreatedDateTime()), "currentScore": llx.FloatData(convert.ToFloat64(score.GetCurrentScore())), "enabledServices": llx.ArrayData(enabledServices, types.String), - "licensedUserCount": llx.IntData(convert.ToInt64From32(score.GetLicensedUserCount())), + "licensedUserCount": llx.IntDataDefault(score.GetLicensedUserCount(), 0), "maxScore": llx.FloatData(convert.ToFloat64(score.GetMaxScore())), "vendorInformation": llx.DictData(vendorInformation), })