-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into dependabot/npm_and_yarn/dashboard/storybo…
…ok/addon-links-8.1.11
- Loading branch information
Showing
8 changed files
with
208 additions
and
55 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package networking | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" | ||
"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" | ||
) | ||
|
||
func LocalNetworkGateways(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) { | ||
resources := make([]models.Resource, 0) | ||
resourceGroups, err := resourcegroup.ResourceGroups(ctx, client) | ||
if err != nil { | ||
return resources, err | ||
} | ||
|
||
if len(resourceGroups) < 1 { | ||
return resources, nil | ||
} | ||
|
||
localNetworkGatewayClient, err := armnetwork.NewLocalNetworkGatewaysClient( | ||
client.AzureClient.SubscriptionId, | ||
client.AzureClient.Credentials, | ||
&arm.ClientOptions{}, | ||
) | ||
if err != nil { | ||
return resources, err | ||
} | ||
|
||
// check resources on each resource group | ||
for _, rg := range resourceGroups { | ||
pager := localNetworkGatewayClient.NewListPager( | ||
rg.Name, nil) | ||
for pager.More() { | ||
page, err := pager.NextPage(ctx) | ||
if err != nil { | ||
return resources, err | ||
} | ||
|
||
for _, lng := range page.LocalNetworkGatewayListResult.Value { | ||
tags := make([]models.Tag, 0) | ||
|
||
for key, value := range lng.Tags { | ||
tags = append(tags, models.Tag{ | ||
Key: key, | ||
Value: *value, | ||
}) | ||
} | ||
|
||
resources = append(resources, models.Resource{ | ||
Provider: "Azure", | ||
Account: client.Name, | ||
Service: "Local Network Gateway", | ||
Region: *lng.Location, | ||
ResourceId: *lng.ID, | ||
Cost: 0, | ||
Name: *lng.Name, | ||
FetchedAt: time.Now(), | ||
Tags: tags, | ||
Link: fmt.Sprintf("https://portal.azure.com/#resource%s", *lng.ID), | ||
}) | ||
} | ||
} | ||
} | ||
|
||
log.WithFields(log.Fields{ | ||
"provider": "Azure", | ||
"account": client.Name, | ||
"service": "Local Network Gateway", | ||
"resources": len(resources), | ||
}).Info("Fetched resources") | ||
|
||
return resources, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package resourcegroup | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm" | ||
"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) | ||
|
||
resourceGroupClient, err := armresources.NewResourceGroupsClient( | ||
client.AzureClient.SubscriptionId, | ||
client.AzureClient.Credentials, | ||
&arm.ClientOptions{}, | ||
) | ||
|
||
if err != nil { | ||
return resources, err | ||
} | ||
|
||
pager := resourceGroupClient.NewListPager(nil) | ||
for pager.More() { | ||
page, err := pager.NextPage(ctx) | ||
if err != nil { | ||
return resources, err | ||
} | ||
|
||
for _, resourceGroup := range page.ResourceGroupListResult.Value { | ||
|
||
tags := make([]models.Tag, 0) | ||
|
||
for key, value := range resourceGroup.Tags { | ||
tags = append(tags, models.Tag{ | ||
Key: key, | ||
Value: *value, | ||
}) | ||
} | ||
|
||
resources = append(resources, models.Resource{ | ||
Provider: "Azure", | ||
Account: client.Name, | ||
Service: "Resource Group", | ||
Region: *resourceGroup.Location, | ||
ResourceId: *resourceGroup.ID, | ||
Cost: 0, | ||
Name: *resourceGroup.Name, | ||
FetchedAt: time.Now(), | ||
Tags: tags, | ||
Link: fmt.Sprintf("https://portal.azure.com/#resource%s", *resourceGroup.ID), | ||
}) | ||
} | ||
} | ||
|
||
log.WithFields(log.Fields{ | ||
"provider": "Azure", | ||
"account": client.Name, | ||
"service": "Resource Group", | ||
"resources": len(resources), | ||
}).Info("Fetched resource groups") | ||
|
||
return resources, nil | ||
} |