Skip to content

Commit 6843a99

Browse files
authored
Merge pull request #808 from AnnuCode/feature-RDSProxy
adding support for RDS Proxies
2 parents 6f8be8d + 74890c1 commit 6843a99

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

providers/aws/aws.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ func listOfSupportedServices() []providers.FetchDataFunction {
6161
kms.Keys,
6262
rds.Clusters,
6363
rds.Instances,
64+
rds.Proxies,
6465
rds.Snapshots,
6566
rds.ClusterSnapshots,
6667
rds.ProxyEndpoints,

providers/aws/rds/proxies.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package rds
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"time"
7+
8+
log "github.com/sirupsen/logrus"
9+
10+
"github.com/aws/aws-sdk-go-v2/aws"
11+
"github.com/aws/aws-sdk-go-v2/service/rds"
12+
"github.com/tailwarden/komiser/models"
13+
"github.com/tailwarden/komiser/providers"
14+
"github.com/tailwarden/komiser/utils"
15+
)
16+
17+
func Proxies(ctx context.Context, client providers.ProviderClient) ([]models.Resource, error) {
18+
var config rds.DescribeDBProxiesInput
19+
resources := make([]models.Resource, 0)
20+
rdsClient := rds.NewFromConfig(*client.AWSClient)
21+
22+
oldRegion := client.AWSClient.Region
23+
client.AWSClient.Region = "us-east-1"
24+
client.AWSClient.Region = oldRegion
25+
26+
for {
27+
output, err := rdsClient.DescribeDBProxies(ctx, &config)
28+
if err != nil {
29+
return resources, err
30+
}
31+
32+
for _, proxy := range output.DBProxies {
33+
var _ProxyName string = *proxy.DBProxyName
34+
startOfMonth := utils.BeginningOfMonth(time.Now())
35+
hourlyUsage := 0
36+
if (*proxy.CreatedDate).Before(startOfMonth) {
37+
hourlyUsage = int(time.Since(startOfMonth).Hours())
38+
} else {
39+
hourlyUsage = int(time.Since(*proxy.CreatedDate).Hours())
40+
}
41+
42+
hourlyCost := 0.0
43+
monthlyCost := float64(hourlyUsage) * hourlyCost
44+
45+
resources = append(resources, models.Resource{
46+
Provider: "AWS",
47+
Account: client.Name,
48+
Service: "RDS Proxy",
49+
Region: client.AWSClient.Region,
50+
ResourceId: *proxy.DBProxyArn,
51+
Cost: monthlyCost,
52+
Name: _ProxyName,
53+
FetchedAt: time.Now(),
54+
Link: fmt.Sprintf("https:/%s.console.aws.amazon.com/rds/home?region=%s#proxies:id=%s", client.AWSClient.Region, client.AWSClient.Region, *proxy.DBProxyName),
55+
})
56+
}
57+
58+
if aws.ToString(output.Marker) == "" {
59+
break
60+
}
61+
62+
config.Marker = output.Marker
63+
}
64+
log.WithFields(log.Fields{
65+
"provider": "AWS",
66+
"account": client.Name,
67+
"region": client.AWSClient.Region,
68+
"service": "RDS Proxy",
69+
"resources": len(resources),
70+
}).Info("Fetched resources")
71+
return resources, nil
72+
}

0 commit comments

Comments
 (0)