Skip to content

Commit

Permalink
Fix accidental loop capture (#1252)
Browse files Browse the repository at this point in the history
* chore: remove dot import

Signed-off-by: Azanul <[email protected]>

* fix: capture of the loop variable

Signed-off-by: Azanul <[email protected]>

* chore: remove duplicate import

Signed-off-by: Azanul <[email protected]>

---------

Signed-off-by: Azanul <[email protected]>
  • Loading branch information
Azanul authored Nov 30, 2023
1 parent 04eb5fb commit 2bf9167
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions providers/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func FetchResources(ctx context.Context, client providers.ProviderClient, region
Name: client.Name,
}
for _, fetchResources := range listOfSupportedServices() {
fetchResources := fetchResources
wp.SubmitTask(func() {
resources, err := fetchResources(ctx, client)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions providers/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func listOfSupportedServices() []providers.FetchDataFunction {

func FetchResources(ctx context.Context, client providers.ProviderClient, db *bun.DB, telemetry bool, analytics utils.Analytics, wp *providers.WorkerPool) {
for _, fetchResources := range listOfSupportedServices() {
fetchResources := fetchResources
wp.SubmitTask(func() {
resources, err := fetchResources(ctx, client)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions providers/civo/civo.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func listOfSupportedServices() []providers.FetchDataFunction {

func FetchResources(ctx context.Context, client providers.ProviderClient, db *bun.DB, telemetry bool, analytics utils.Analytics, wp *providers.WorkerPool) {
for _, fetchResources := range listOfSupportedServices() {
fetchResources := fetchResources
regions, err := client.CivoClient.ListRegions()
if err != nil {
log.Printf("[%s][Civo] %s", client.Name, err)
Expand Down
1 change: 1 addition & 0 deletions providers/digitalocean/digitalocean.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func listOfSupportedServices() []providers.FetchDataFunction {

func FetchResources(ctx context.Context, client providers.ProviderClient, db *bun.DB, telemetry bool, analytics utils.Analytics, wp *providers.WorkerPool) {
for _, fetchResources := range listOfSupportedServices() {
fetchResources := fetchResources
wp.SubmitTask(func() {
resources, err := fetchResources(ctx, client)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions providers/gcp/gcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func listOfSupportedServices() []providers.FetchDataFunction {

func FetchResources(ctx context.Context, client providers.ProviderClient, db *bun.DB, telemetry bool, analytics utils.Analytics, wp *providers.WorkerPool) {
for _, fetchResources := range listOfSupportedServices() {
fetchResources := fetchResources
wp.SubmitTask(func() {
resources, err := fetchResources(ctx, client)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions providers/k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func listOfSupportedServices() []providers.FetchDataFunction {

func FetchResources(ctx context.Context, client providers.ProviderClient, db *bun.DB, telemetry bool, analytics utils.Analytics, wp *providers.WorkerPool) {
for _, fetchResources := range listOfSupportedServices() {
fetchResources := fetchResources
wp.SubmitTask(func() {
resources, err := fetchResources(ctx, client)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions providers/linode/linode.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func listOfSupportedServices() []providers.FetchDataFunction {

func FetchResources(ctx context.Context, client providers.ProviderClient, db *bun.DB, telemetry bool, analytics utils.Analytics, wp *providers.WorkerPool) {
for _, fetchResources := range listOfSupportedServices() {
fetchResources := fetchResources
wp.SubmitTask(func() {
resources, err := fetchResources(ctx, client)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions providers/mongodbatlas/mongodbatlas.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func listOfSupportedServices() []providers.FetchDataFunction {

func FetchResources(ctx context.Context, client providers.ProviderClient, db *bun.DB, telemetry bool, analytics utils.Analytics, wp *providers.WorkerPool) {
for _, fetchResources := range listOfSupportedServices() {
fetchResources := fetchResources
wp.SubmitTask(func() {
resources, err := fetchResources(ctx, client)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions providers/oci/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func listOfSupportedServices() []providers.FetchDataFunction {

func FetchResources(ctx context.Context, client providers.ProviderClient, db *bun.DB, telemetry bool, analytics utils.Analytics, wp *providers.WorkerPool) {
for _, fetchResources := range listOfSupportedServices() {
fetchResources := fetchResources
wp.SubmitTask(func() {
resources, err := fetchResources(ctx, client)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions providers/ovh/ovh.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func listOfSupportedServices() []providers.FetchDataFunction {
func FetchResources(ctx context.Context, client providers.ProviderClient, db *bun.DB, telemetry bool, analytics utils.Analytics, wp *providers.WorkerPool) {
wp.SubmitTask(func() {
for _, fetchResources := range listOfSupportedServices() {
fetchResources := fetchResources
resources, err := fetchResources(ctx, client)
if err != nil {
log.Printf("[%s][OVH] %s", client.Name, err)
Expand Down
4 changes: 2 additions & 2 deletions providers/providers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import (
"github.com/oracle/oci-go-sdk/common"
"github.com/ovh/go-ovh/ovh"
"github.com/scaleway/scaleway-sdk-go/scw"
. "github.com/tailwarden/komiser/models"
"github.com/tailwarden/komiser/models"
tccvm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312"
"go.mongodb.org/atlas/mongodbatlas"
"golang.org/x/oauth2/google"
"k8s.io/client-go/kubernetes"
)

type FetchDataFunction func(ctx context.Context, client ProviderClient) ([]Resource, error)
type FetchDataFunction func(ctx context.Context, client ProviderClient) ([]models.Resource, error)

type ProviderClient struct {
AWSClient *aws.Config
Expand Down
1 change: 1 addition & 0 deletions providers/scaleway/scaleway.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func listOfSupportedServices() []providers.FetchDataFunction {
func FetchResources(ctx context.Context, client providers.ProviderClient, db *bun.DB, telemetry bool, analytics utils.Analytics, wp *providers.WorkerPool) {
wp.SubmitTask(func() {
for _, fetchResources := range listOfSupportedServices() {
fetchResources := fetchResources
resources, err := fetchResources(ctx, client)
if err != nil {
log.Printf("[%s][Scaleway] %s", client.Name, err)
Expand Down
4 changes: 2 additions & 2 deletions providers/tencent/tencent.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package tencent
import (
"context"

"github.com/sirupsen/logrus"
log "github.com/sirupsen/logrus"

"github.com/tailwarden/komiser/providers"
Expand All @@ -22,6 +21,7 @@ func listOfSupportedServices() []providers.FetchDataFunction {

func FetchResources(ctx context.Context, client providers.ProviderClient, db *bun.DB, telemetry bool, analytics utils.Analytics, wp *providers.WorkerPool) {
for _, fetchResources := range listOfSupportedServices() {
fetchResources := fetchResources
regions, err := client.TencentClient.DescribeRegionsWithContext(ctx, tccvm.NewDescribeRegionsRequest())
if err != nil {
log.Errorf("[%s][Tencent] Couldn't fetch the list of regions: %s", client.Name, err)
Expand All @@ -45,7 +45,7 @@ func FetchResources(ctx context.Context, client providers.ProviderClient, db *bu
for _, resource := range resources {
_, err := db.NewInsert().Model(&resource).On("CONFLICT (resource_id) DO UPDATE").Set("cost = EXCLUDED.cost").Exec(context.Background())
if err != nil {
logrus.WithError(err).Error("db trigger failed")
log.WithError(err).Error("db trigger failed")
}
}
if telemetry {
Expand Down

0 comments on commit 2bf9167

Please sign in to comment.