From e3d74b814b0e8ab8513098c0ca323713aaa301a0 Mon Sep 17 00:00:00 2001 From: Yash Mehrotra Date: Sun, 2 Jun 2024 19:25:11 +0530 Subject: [PATCH] fix: nil pointer error due to missing aws connection --- api/v1/aws.go | 14 +++++++------- api/v1/zz_generated.deepcopy.go | 6 +----- scrapers/aws/aws.go | 2 +- scrapers/aws/cost.go | 4 ++-- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/api/v1/aws.go b/api/v1/aws.go index 561525ae..2e466a06 100644 --- a/api/v1/aws.go +++ b/api/v1/aws.go @@ -9,13 +9,13 @@ import ( // AWS ... type AWS struct { - BaseScraper `json:",inline"` - *AWSConnection `json:",inline"` - Compliance bool `json:"compliance,omitempty"` - CloudTrail CloudTrail `json:"cloudtrail,omitempty"` - Include []string `json:"include,omitempty"` - Exclude []string `json:"exclude,omitempty"` - CostReporting CostReporting `json:"costReporting,omitempty"` + BaseScraper `json:",inline"` + AWSConnection `json:",inline"` + Compliance bool `json:"compliance,omitempty"` + CloudTrail CloudTrail `json:"cloudtrail,omitempty"` + Include []string `json:"include,omitempty"` + Exclude []string `json:"exclude,omitempty"` + CostReporting CostReporting `json:"costReporting,omitempty"` } type CloudTrail struct { diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index 08ba56d0..b1e281fe 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -30,11 +30,7 @@ import ( func (in *AWS) DeepCopyInto(out *AWS) { *out = *in in.BaseScraper.DeepCopyInto(&out.BaseScraper) - if in.AWSConnection != nil { - in, out := &in.AWSConnection, &out.AWSConnection - *out = new(AWSConnection) - (*in).DeepCopyInto(*out) - } + in.AWSConnection.DeepCopyInto(&out.AWSConnection) in.CloudTrail.DeepCopyInto(&out.CloudTrail) if in.Include != nil { in, out := &in.Include, &out.Include diff --git a/scrapers/aws/aws.go b/scrapers/aws/aws.go index fb6b4e40..95295863 100644 --- a/scrapers/aws/aws.go +++ b/scrapers/aws/aws.go @@ -64,7 +64,7 @@ func (ctx AWSContext) String() string { } func (aws Scraper) getContext(ctx api.ScrapeContext, awsConfig v1.AWS, region string) (*AWSContext, error) { - session, err := NewSession(ctx, *awsConfig.AWSConnection, region) + session, err := NewSession(ctx, awsConfig.AWSConnection, region) if err != nil { return nil, fmt.Errorf("failed to create AWS session for region=%q: %w", region, err) } diff --git a/scrapers/aws/cost.go b/scrapers/aws/cost.go index c9bc6721..6006c47c 100644 --- a/scrapers/aws/cost.go +++ b/scrapers/aws/cost.go @@ -57,7 +57,7 @@ func getAWSAthenaConfig(ctx api.ScrapeContext, awsConfig v1.AWS) (*athena.Config return nil, err } - accessKey, secretKey, err := getAccessAndSecretKey(ctx, *awsConfig.AWSConnection) + accessKey, secretKey, err := getAccessAndSecretKey(ctx, awsConfig.AWSConnection) if err != nil { return nil, err } @@ -144,7 +144,7 @@ func (awsCost CostScraper) Scrape(ctx api.ScrapeContext) v1.ScrapeResults { var results v1.ScrapeResults for _, awsConfig := range ctx.ScrapeConfig().Spec.AWS { - session, err := NewSession(ctx, *awsConfig.AWSConnection, awsConfig.Region[0]) + session, err := NewSession(ctx, awsConfig.AWSConnection, awsConfig.Region[0]) if err != nil { return results.Errorf(err, "failed to create AWS session") }