diff --git a/internal/config/load.go b/internal/config/load.go index 05ae373b6..2d3fda3f4 100644 --- a/internal/config/load.go +++ b/internal/config/load.go @@ -12,6 +12,7 @@ import ( "github.com/Azure/azure-sdk-for-go/sdk/azidentity" "github.com/BurntSushi/toml" + "github.com/aws/aws-sdk-go-v2/aws" awsConfig "github.com/aws/aws-sdk-go-v2/config" "github.com/civo/civogo" "github.com/digitalocean/godo" @@ -104,10 +105,11 @@ func Load(configPath string, telemetry bool, analytics utils.Analytics) (*models Name: account.Name, }) } else { - cfg, err := awsConfig.LoadDefaultConfig(context.Background(), awsConfig.WithSharedConfigProfile(account.Profile)) + cfg, err := awsConfig.LoadDefaultConfig(context.Background(), awsConfig.WithSharedConfigProfile(account.Profile), awsConfig.WithRetryMode(aws.RetryModeAdaptive)) if err != nil { return nil, nil, nil, err } + clients = append(clients, providers.ProviderClient{ AWSClient: &cfg, Name: account.Name, diff --git a/providers/azure/compute/disks.go b/providers/azure/compute/disks.go index 9c4ecbee2..43af438ef 100644 --- a/providers/azure/compute/disks.go +++ b/providers/azure/compute/disks.go @@ -6,6 +6,7 @@ import ( "time" "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4" log "github.com/sirupsen/logrus" @@ -16,7 +17,19 @@ import ( func Disks(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) { resources := make([]models.Resource, 0) - svc, err := armcompute.NewDisksClient(client.AzureClient.SubscriptionId, client.AzureClient.Credentials, &arm.ClientOptions{}) + retryOptions := policy.RetryOptions{ + MaxRetries: 6, + RetryDelay: 2 * time.Second, + MaxRetryDelay: 120 * time.Second, + } + + clientOptions := &arm.ClientOptions{ + ClientOptions: policy.ClientOptions{ + Retry: retryOptions, + }, + } + + svc, err := armcompute.NewDisksClient(client.AzureClient.SubscriptionId, client.AzureClient.Credentials, clientOptions) if err != nil { return resources, err } diff --git a/providers/azure/compute/images.go b/providers/azure/compute/images.go index 92199fd84..c9b6eb27b 100644 --- a/providers/azure/compute/images.go +++ b/providers/azure/compute/images.go @@ -6,6 +6,7 @@ import ( "time" "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4" log "github.com/sirupsen/logrus" @@ -16,7 +17,19 @@ import ( func Images(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) { resources := make([]models.Resource, 0) - svc, err := armcompute.NewImagesClient(client.AzureClient.SubscriptionId, client.AzureClient.Credentials, &arm.ClientOptions{}) + retryOptions := policy.RetryOptions{ + MaxRetries: 6, + RetryDelay: 2 * time.Second, + MaxRetryDelay: 120 * time.Second, + } + + clientOptions := &arm.ClientOptions{ + ClientOptions: policy.ClientOptions{ + Retry: retryOptions, + }, + } + + svc, err := armcompute.NewImagesClient(client.AzureClient.SubscriptionId, client.AzureClient.Credentials, clientOptions) if err != nil { return resources, err } diff --git a/providers/azure/compute/snapshots.go b/providers/azure/compute/snapshots.go index 8dd86895f..cbc5b6965 100644 --- a/providers/azure/compute/snapshots.go +++ b/providers/azure/compute/snapshots.go @@ -6,6 +6,7 @@ import ( "time" "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4" log "github.com/sirupsen/logrus" @@ -16,7 +17,19 @@ import ( func Snapshots(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) { resources := make([]models.Resource, 0) - svc, err := armcompute.NewSnapshotsClient(client.AzureClient.SubscriptionId, client.AzureClient.Credentials, &arm.ClientOptions{}) + retryOptions := policy.RetryOptions{ + MaxRetries: 6, + RetryDelay: 2 * time.Second, + MaxRetryDelay: 120 * time.Second, + } + + clientOptions := &arm.ClientOptions{ + ClientOptions: policy.ClientOptions{ + Retry: retryOptions, + }, + } + + svc, err := armcompute.NewSnapshotsClient(client.AzureClient.SubscriptionId, client.AzureClient.Credentials, clientOptions) if err != nil { return resources, err } diff --git a/providers/azure/compute/virtual_machines.go b/providers/azure/compute/virtual_machines.go index 48f308449..14634d853 100644 --- a/providers/azure/compute/virtual_machines.go +++ b/providers/azure/compute/virtual_machines.go @@ -6,7 +6,8 @@ import ( "time" "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" - "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/policy" + armPolicy "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/policy" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v4" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/costmanagement/armcostmanagement" @@ -19,12 +20,24 @@ import ( func VirtualMachines(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) { resources := make([]models.Resource, 0) - svc, err := armcompute.NewVirtualMachinesClient(client.AzureClient.SubscriptionId, client.AzureClient.Credentials, &arm.ClientOptions{}) + retryOptions := policy.RetryOptions{ + MaxRetries: 6, + RetryDelay: 2 * time.Second, + MaxRetryDelay: 120 * time.Second, + } + + clientOptions := &arm.ClientOptions{ + ClientOptions: policy.ClientOptions{ + Retry: retryOptions, + }, + } + + svc, err := armcompute.NewVirtualMachinesClient(client.AzureClient.SubscriptionId, client.AzureClient.Credentials, clientOptions) if err != nil { return resources, err } - costClient, err := armcostmanagement.NewQueryClient(client.AzureClient.Credentials, &policy.ClientOptions{}) + costClient, err := armcostmanagement.NewQueryClient(client.AzureClient.Credentials, &armPolicy.ClientOptions{}) if err != nil { return resources, err } diff --git a/providers/azure/databases/sql.go b/providers/azure/databases/sql.go index 61bba4162..c08eff9f4 100644 --- a/providers/azure/databases/sql.go +++ b/providers/azure/databases/sql.go @@ -6,6 +6,7 @@ import ( "time" "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/sql/armsql" "github.com/tailwarden/komiser/models" "github.com/tailwarden/komiser/providers" @@ -16,7 +17,19 @@ import ( func Sql(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) { resources := make([]models.Resource, 0) - svc, err := armsql.NewServersClient(client.AzureClient.SubscriptionId, client.AzureClient.Credentials, &arm.ClientOptions{}) + retryOptions := policy.RetryOptions{ + MaxRetries: 6, + RetryDelay: 2 * time.Second, + MaxRetryDelay: 120 * time.Second, + } + + clientOptions := &arm.ClientOptions{ + ClientOptions: policy.ClientOptions{ + Retry: retryOptions, + }, + } + + svc, err := armsql.NewServersClient(client.AzureClient.SubscriptionId, client.AzureClient.Credentials, clientOptions) if err != nil { return resources, err diff --git a/providers/azure/networking/application_gateways.go b/providers/azure/networking/application_gateways.go index a3d867a89..31c9ca43b 100644 --- a/providers/azure/networking/application_gateways.go +++ b/providers/azure/networking/application_gateways.go @@ -6,6 +6,7 @@ import ( "time" "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork" log "github.com/sirupsen/logrus" @@ -16,10 +17,22 @@ import ( func ApplicationGateways(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) { resources := make([]models.Resource, 0) + retryOptions := policy.RetryOptions{ + MaxRetries: 6, + RetryDelay: 2 * time.Second, + MaxRetryDelay: 120 * time.Second, + } + + clientOptions := &arm.ClientOptions{ + ClientOptions: policy.ClientOptions{ + Retry: retryOptions, + }, + } + appGatewayClient, err := armnetwork.NewApplicationGatewaysClient( client.AzureClient.SubscriptionId, client.AzureClient.Credentials, - &arm.ClientOptions{}, + clientOptions, ) if err != nil { return resources, err diff --git a/providers/azure/networking/firewalls.go b/providers/azure/networking/firewalls.go index 991758f8e..b70f22f0c 100644 --- a/providers/azure/networking/firewalls.go +++ b/providers/azure/networking/firewalls.go @@ -6,6 +6,7 @@ import ( "time" "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork" log "github.com/sirupsen/logrus" @@ -16,7 +17,19 @@ import ( func Firewalls(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) { resources := make([]models.Resource, 0) - svc, err := armnetwork.NewAzureFirewallsClient(client.AzureClient.SubscriptionId, client.AzureClient.Credentials, &arm.ClientOptions{}) + retryOptions := policy.RetryOptions{ + MaxRetries: 6, + RetryDelay: 2 * time.Second, + MaxRetryDelay: 120 * time.Second, + } + + clientOptions := &arm.ClientOptions{ + ClientOptions: policy.ClientOptions{ + Retry: retryOptions, + }, + } + + svc, err := armnetwork.NewAzureFirewallsClient(client.AzureClient.SubscriptionId, client.AzureClient.Credentials, clientOptions) if err != nil { return resources, err } diff --git a/providers/azure/networking/load_balancers.go b/providers/azure/networking/load_balancers.go index 3860aa6ee..9249b8de3 100644 --- a/providers/azure/networking/load_balancers.go +++ b/providers/azure/networking/load_balancers.go @@ -6,6 +6,7 @@ import ( "time" "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork" log "github.com/sirupsen/logrus" @@ -16,10 +17,22 @@ import ( func LoadBalancers(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) { resources := make([]models.Resource, 0) + retryOptions := policy.RetryOptions{ + MaxRetries: 6, + RetryDelay: 2 * time.Second, + MaxRetryDelay: 120 * time.Second, + } + + clientOptions := &arm.ClientOptions{ + ClientOptions: policy.ClientOptions{ + Retry: retryOptions, + }, + } + loadBalancerClient, err := armnetwork.NewLoadBalancersClient( client.AzureClient.SubscriptionId, client.AzureClient.Credentials, - &arm.ClientOptions{}, + clientOptions, ) if err != nil { return resources, err diff --git a/providers/azure/networking/local_network_gateways.go b/providers/azure/networking/local_network_gateways.go index 2949bf138..2386ca706 100644 --- a/providers/azure/networking/local_network_gateways.go +++ b/providers/azure/networking/local_network_gateways.go @@ -3,11 +3,13 @@ package networking import ( "context" "fmt" + "time" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork" log "github.com/sirupsen/logrus" "github.com/tailwarden/komiser/providers/azure/resourcegroup" - "time" "github.com/tailwarden/komiser/models" "github.com/tailwarden/komiser/providers" @@ -24,10 +26,22 @@ func LocalNetworkGateways(ctx context.Context, client providers.ProviderClient) return resources, nil } + retryOptions := policy.RetryOptions{ + MaxRetries: 6, + RetryDelay: 2 * time.Second, + MaxRetryDelay: 120 * time.Second, + } + + clientOptions := &arm.ClientOptions{ + ClientOptions: policy.ClientOptions{ + Retry: retryOptions, + }, + } + localNetworkGatewayClient, err := armnetwork.NewLocalNetworkGatewaysClient( client.AzureClient.SubscriptionId, client.AzureClient.Credentials, - &arm.ClientOptions{}, + clientOptions, ) if err != nil { return resources, err diff --git a/providers/azure/resourcegroup/resource_groups.go b/providers/azure/resourcegroup/resource_groups.go index 3f1d8c380..a26b817d1 100644 --- a/providers/azure/resourcegroup/resource_groups.go +++ b/providers/azure/resourcegroup/resource_groups.go @@ -3,21 +3,35 @@ package resourcegroup import ( "context" "fmt" + "time" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources" log "github.com/sirupsen/logrus" "github.com/tailwarden/komiser/models" "github.com/tailwarden/komiser/providers" - "time" ) func ResourceGroups(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) { resources := make([]models.Resource, 0) + retryOptions := policy.RetryOptions{ + MaxRetries: 6, + RetryDelay: 2 * time.Second, + MaxRetryDelay: 120 * time.Second, + } + + clientOptions := &arm.ClientOptions{ + ClientOptions: policy.ClientOptions{ + Retry: retryOptions, + }, + } + resourceGroupClient, err := armresources.NewResourceGroupsClient( client.AzureClient.SubscriptionId, client.AzureClient.Credentials, - &arm.ClientOptions{}, + clientOptions, ) if err != nil { diff --git a/providers/azure/storage/databoxes.go b/providers/azure/storage/databoxes.go index 1f5a3fcd5..7b78479c2 100644 --- a/providers/azure/storage/databoxes.go +++ b/providers/azure/storage/databoxes.go @@ -5,6 +5,8 @@ import ( "fmt" "time" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/databox/armdatabox" log "github.com/sirupsen/logrus" @@ -15,11 +17,23 @@ import ( func Databoxes(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) { resources := make([]models.Resource, 0) - svc, err := armdatabox.NewJobsClient(client.AzureClient.SubscriptionId, client.AzureClient.Credentials, nil) + retryOptions := policy.RetryOptions{ + MaxRetries: 6, + RetryDelay: 2 * time.Second, + MaxRetryDelay: 120 * time.Second, + } + + clientOptions := &arm.ClientOptions{ + ClientOptions: policy.ClientOptions{ + Retry: retryOptions, + }, + } + + svc, err := armdatabox.NewJobsClient(client.AzureClient.SubscriptionId, client.AzureClient.Credentials, clientOptions) if err != nil { return resources, err } - + pager := svc.NewListPager(nil) for pager.More() { page, err := pager.NextPage(ctx) @@ -30,7 +44,7 @@ func Databoxes(ctx context.Context, client providers.ProviderClient) ([]models.R for _, val := range page.Value { tags := make([]models.Tag, 0) - for key, value := range val.Tags{ + for key, value := range val.Tags { tags = append(tags, models.Tag{ Key: key, Value: *value, @@ -40,7 +54,7 @@ func Databoxes(ctx context.Context, client providers.ProviderClient) ([]models.R resources = append(resources, models.Resource{ Provider: "Azure", Account: client.Name, - Service: "Databox", + Service: "Databox", Region: *val.Location, ResourceId: *val.ID, Cost: 0, @@ -60,4 +74,4 @@ func Databoxes(ctx context.Context, client providers.ProviderClient) ([]models.R "resources": len(resources), }).Info("Fetched resources") return resources, nil -} \ No newline at end of file +} diff --git a/providers/azure/storage/queues.go b/providers/azure/storage/queues.go index 7c3ffa7b2..479af8ee7 100644 --- a/providers/azure/storage/queues.go +++ b/providers/azure/storage/queues.go @@ -7,6 +7,7 @@ import ( "time" "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage" log "github.com/sirupsen/logrus" @@ -24,7 +25,19 @@ func Queues(ctx context.Context, client providers.ProviderClient) ([]models.Reso resources := make([]models.Resource, 0) storage := make([]Storage, 0) - storageAccountsClient, err := armstorage.NewAccountsClient(client.AzureClient.SubscriptionId, client.AzureClient.Credentials, &arm.ClientOptions{}) + retryOptions := policy.RetryOptions{ + MaxRetries: 6, + RetryDelay: 2 * time.Second, + MaxRetryDelay: 120 * time.Second, + } + + clientOptions := &arm.ClientOptions{ + ClientOptions: policy.ClientOptions{ + Retry: retryOptions, + }, + } + + storageAccountsClient, err := armstorage.NewAccountsClient(client.AzureClient.SubscriptionId, client.AzureClient.Credentials, clientOptions) if err != nil { return resources, err } diff --git a/providers/azure/storage/tables.go b/providers/azure/storage/tables.go index c9cd6b812..4052c6e30 100644 --- a/providers/azure/storage/tables.go +++ b/providers/azure/storage/tables.go @@ -7,6 +7,7 @@ import ( "time" "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" + "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage" log "github.com/sirupsen/logrus" @@ -18,7 +19,19 @@ func Tables(ctx context.Context, client providers.ProviderClient) ([]models.Reso resources := make([]models.Resource, 0) storage := make([]Storage, 0) - storageAccountsClient, err := armstorage.NewAccountsClient(client.AzureClient.SubscriptionId, client.AzureClient.Credentials, &arm.ClientOptions{}) + retryOptions := policy.RetryOptions{ + MaxRetries: 6, + RetryDelay: 2 * time.Second, + MaxRetryDelay: 120 * time.Second, + } + + clientOptions := &arm.ClientOptions{ + ClientOptions: policy.ClientOptions{ + Retry: retryOptions, + }, + } + + storageAccountsClient, err := armstorage.NewAccountsClient(client.AzureClient.SubscriptionId, client.AzureClient.Credentials, clientOptions) if err != nil { return resources, err } @@ -61,7 +74,6 @@ func Tables(ctx context.Context, client providers.ProviderClient) ([]models.Reso tags := make([]models.Tag, 0) - resources = append(resources, models.Resource{ Provider: "Azure", Account: client.Name,