Skip to content

Commit

Permalink
create local network gateway resource with resource group
Browse files Browse the repository at this point in the history
  • Loading branch information
Aldair Zamora committed Jul 6, 2024
1 parent f1b149a commit f52f0cf
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 1 deletion.
3 changes: 2 additions & 1 deletion dashboard/utils/serviceHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ export const allProvidersServices: { [key in Providers]: string[] } = {
'firewall',
'load balancer',
'databox',
'queue'
'queue',
'Local Network Gateway'
],
civo: [
'compute',
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ require (
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/costmanagement/armcostmanagement v1.1.1
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/databox/armdatabox v1.0.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork v1.1.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.2.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/sql/armsql v1.0.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.2.0
github.com/BurntSushi/toml v1.2.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork v1.1.0
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/network/armnetwork v1.1.0/go.mod h1:243D9iHbcQXoFUtgHJwL7gl2zx1aDuDMjvBZVGr2uW0=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0 h1:ECsQtyERDVz3NP3kvDOTLvbQhqWp/x9EsGKtb4ogUr8=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0/go.mod h1:s1tW/At+xHqjNFvWU4G0c0Qv33KOhvbGNj0RCTQDV8s=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.2.0 h1:Dd+RhdJn0OTtVGaeDLZpcumkIVCtA/3/Fo42+eoYvVM=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.2.0/go.mod h1:5kakwfW5CjC9KK+Q4wjXAg+ShuIm2mBMua0ZFj2C8PE=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/sql/armsql v1.0.0 h1:rycGPpUtVFwM9uLUL2ux8EL8kGfl3qF1u76aEHvB4Qw=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/sql/armsql v1.0.0/go.mod h1:lirt6L2DmxromyM4w5Vd2QPz4PrWRV38Izy43xgkBVI=
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/storage/armstorage v1.2.0 h1:Ma67P/GGprNwsslzEH6+Kb8nybI8jpDTm4Wmzu2ReK8=
Expand Down
1 change: 1 addition & 0 deletions providers/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func listOfSupportedServices() []providers.FetchDataFunction {
networking.ApplicationGateways,
networking.LoadBalancers,
networking.Firewalls,
networking.LocalNetworkGateways,
storage.Queues,
storage.Tables,
storage.Databoxes,
Expand Down
80 changes: 80 additions & 0 deletions providers/azure/networking/local_network_gateways.go
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 _, name := range resourceGroups {
pager := localNetworkGatewayClient.NewListPager(
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.Sprint("https://portal.azure.com/#resource%s", *lng.ID),

Check failure on line 66 in providers/azure/networking/local_network_gateways.go

View workflow job for this annotation

GitHub Actions / build_test_cli

fmt.Sprint call has possible Printf formatting directive %s

Check failure on line 66 in providers/azure/networking/local_network_gateways.go

View workflow job for this annotation

GitHub Actions / golangci-lint

printf: fmt.Sprint call has possible Printf formatting directive %s (govet)
})
}
}
}

log.WithFields(log.Fields{
"provider": "Azure",
"account": client.Name,
"service": "Local Network Gateway",
"resources": len(resources),
}).Info("Fetched resources")

return resources, nil
}
45 changes: 45 additions & 0 deletions providers/azure/resourcegroup/resource_groups.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package resourcegroup

import (
"context"
"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/providers"
)

func ResourceGroups(ctx context.Context, client providers.ProviderClient) ([]string, error) {
resourceGroupNames := make([]string, 0)

resourceGroupClient, err := armresources.NewResourceGroupsClient(
client.AzureClient.SubscriptionId,
client.AzureClient.Credentials,
&arm.ClientOptions{},
)

if err != nil {
return resourceGroupNames, err
}

pager := resourceGroupClient.NewListPager(nil)
for pager.More() {
page, err := pager.NextPage(ctx)
if err != nil {
return resourceGroupNames, err
}

for _, resourceGroup := range page.ResourceGroupListResult.Value {

resourceGroupNames = append(resourceGroupNames, *resourceGroup.Name)
}
}

log.WithFields(log.Fields{
"provider": "Azure",
"account": client.Name,
"service": "Resource Group",
"resources": len(resourceGroupNames),
}).Info("Fetched resource groups")

return resourceGroupNames, nil
}

0 comments on commit f52f0cf

Please sign in to comment.