Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create local network gateway resource #1457

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 _, 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
}
68 changes: 68 additions & 0 deletions providers/azure/resourcegroup/resource_groups.go
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
}
Loading