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

Restore OVH provider #1144

Merged
merged 24 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 19 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
Binary file added dashboard/public/assets/img/providers/ovh.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 14 additions & 3 deletions dashboard/utils/providerHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export type Provider =
| 'tencent'
| 'oci'
| 'scaleway'
| 'mongodbatlas';
| 'mongodbatlas'
| 'ovh';

type ProviderKey =
| 'AWS'
Expand All @@ -22,7 +23,8 @@ type ProviderKey =
| 'TENCENT'
| 'OCI'
| 'SCALE_WAY'
| 'MONGODB_ATLAS';
| 'MONGODB_ATLAS'
| 'OVH';

export const allProviders: { [key in ProviderKey]: Provider } = {
AWS: 'aws',
Expand All @@ -35,7 +37,8 @@ export const allProviders: { [key in ProviderKey]: Provider } = {
TENCENT: 'tencent',
OCI: 'oci',
SCALE_WAY: 'scaleway',
MONGODB_ATLAS: 'mongodbatlas'
MONGODB_ATLAS: 'mongodbatlas',
OVH: 'ovh'
};

export type DBProvider = 'postgres' | 'sqlite';
Expand Down Expand Up @@ -94,6 +97,10 @@ const providers = {
label = 'MongoDB Atlas';
}

if (arg.toLowerCase() === 'ovh') {
label = 'OVHcloud';
}

return label;
},
providerImg(arg: Provider) {
Expand Down Expand Up @@ -143,6 +150,10 @@ const providers = {
img = '/assets/img/providers/mongodbatlas.jpg';
}

if (arg.toLowerCase() === 'ovh') {
img = '/assets/img/providers/ovh.png';
}

return img;
}
};
Expand Down
20 changes: 12 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

require (
cloud.google.com/go/bigquery v1.50.0
cloud.google.com/go/compute v1.19.1
cloud.google.com/go/compute v1.20.1
cloud.google.com/go/container v1.16.0
cloud.google.com/go/kms v1.10.1
cloud.google.com/go/monitoring v1.13.0
Expand Down Expand Up @@ -56,6 +56,7 @@ require (
github.com/linode/linodego v1.12.0
github.com/mongodb-forks/digest v1.0.4
github.com/oracle/oci-go-sdk v24.3.0+incompatible
github.com/ovh/go-ovh v1.4.3
github.com/rs/xid v1.4.0
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.13
github.com/segmentio/analytics-go v3.1.0+incompatible
Expand All @@ -72,9 +73,9 @@ require (
github.com/uptrace/bun/driver/pgdriver v1.1.8
github.com/uptrace/bun/driver/sqliteshim v1.1.8
go.mongodb.org/atlas v0.23.1
golang.org/x/oauth2 v0.7.0
golang.org/x/oauth2 v0.13.0
golang.org/x/text v0.13.0
google.golang.org/api v0.114.0
google.golang.org/api v0.126.0
k8s.io/apimachinery v0.26.1
k8s.io/client-go v0.26.1
)
Expand All @@ -84,10 +85,13 @@ require (
github.com/apache/arrow/go/v11 v11.0.0 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.12 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/google/s2a-go v0.1.4 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect
)

require (
cloud.google.com/go v0.110.0 // indirect
cloud.google.com/go v0.110.2 // indirect
cloud.google.com/go/certificatemanager v1.6.0
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/iam v0.13.0 // indirect
Expand Down Expand Up @@ -139,7 +143,7 @@ require (
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
github.com/googleapis/gax-go/v2 v2.7.1 // indirect
github.com/googleapis/gax-go/v2 v2.11.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/imdario/mergo v0.3.6 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
Expand Down Expand Up @@ -183,16 +187,16 @@ require (
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect
golang.org/x/tools v0.6.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
google.golang.org/genproto v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/grpc v1.56.3 // indirect
google.golang.org/protobuf v1.30.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
79 changes: 63 additions & 16 deletions go.sum

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions internal/config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/linode/linodego"
"github.com/mongodb-forks/digest"
"github.com/oracle/oci-go-sdk/common"
"github.com/ovh/go-ovh/ovh"
"github.com/scaleway/scaleway-sdk-go/scw"
"github.com/tailwarden/komiser/models"
. "github.com/tailwarden/komiser/models"
Expand Down Expand Up @@ -454,5 +455,36 @@ func Load(configPath string, telemetry bool, analytics utils.Analytics, db *bun.
}
}

if len(config.OVH) > 0 {
for _, account := range config.OVH {
cloudAccount := models.Account{
Provider: "OVH",
Name: account.Name,
Credentials: map[string]string{
"endpoint": account.Endpoint,
"applicationKey": account.ApplicationKey,
"applicationSecret": account.ApplicationSecret,
"consumerKey": account.ConsumerKey,
},
}
accounts = append(accounts, cloudAccount)

client, err := ovh.NewClient(
account.Endpoint,
account.ApplicationKey,
account.ApplicationSecret,
account.ConsumerKey,
)
if err != nil {
log.Fatal(err)
}

clients = append(clients, providers.ProviderClient{
OVHClient: client,
Name: account.Name,
})
}
}

return config, clients, accounts, nil
}
14 changes: 10 additions & 4 deletions internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@ import (
"github.com/tailwarden/komiser/models"
"github.com/tailwarden/komiser/providers"
"github.com/tailwarden/komiser/providers/aws"
azure "github.com/tailwarden/komiser/providers/azure"
"github.com/tailwarden/komiser/providers/azure"
"github.com/tailwarden/komiser/providers/civo"
do "github.com/tailwarden/komiser/providers/digitalocean"
"github.com/tailwarden/komiser/providers/gcp"
k8s "github.com/tailwarden/komiser/providers/k8s"
linode "github.com/tailwarden/komiser/providers/linode"
"github.com/tailwarden/komiser/providers/k8s"
"github.com/tailwarden/komiser/providers/linode"
"github.com/tailwarden/komiser/providers/mongodbatlas"
"github.com/tailwarden/komiser/providers/oci"
scaleway "github.com/tailwarden/komiser/providers/scaleway"
"github.com/tailwarden/komiser/providers/ovh"

"github.com/tailwarden/komiser/providers/scaleway"
"github.com/tailwarden/komiser/providers/tencent"
"github.com/tailwarden/komiser/utils"
"github.com/uptrace/bun"
Expand Down Expand Up @@ -253,6 +255,8 @@ func triggerFetchingWorfklow(ctx context.Context, client providers.ProviderClien
mongodbatlas.FetchResources(ctx, client, db, telemetry, analytics)
case "GCP":
gcp.FetchResources(ctx, client, db, telemetry, analytics)
case "OVH":
ovh.FetchResources(ctx, client, db, telemetry, analytics)
}
}

Expand Down Expand Up @@ -293,6 +297,8 @@ func fetchResources(ctx context.Context, clients []providers.ProviderClient, reg
workflowTrigger(client, "MongoDBAtlas")
} else if client.GCPClient != nil {
workflowTrigger(client, "GCP")
} else if client.OVHClient != nil {
workflowTrigger(client, "OVH")
}
}

Expand Down
9 changes: 9 additions & 0 deletions models/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type Config struct {
Scaleway []ScalewayConfig `toml:"scaleway"`
MongoDBAtlas []MongoDBAtlasConfig `toml:"mongodbatlas"`
GCP []GCPConfig `toml:"gcp"`
OVH []OVHConfig `toml:"ovh"`
Postgres PostgresConfig `toml:"postgres,omitempty"`
SQLite SQLiteConfig `toml:"sqlite"`
Slack SlackConfig `toml:"slack"`
Expand Down Expand Up @@ -94,6 +95,14 @@ type GCPConfig struct {
ServiceAccountKeyPath string `toml:"serviceAccountKeyPath"`
}

type OVHConfig struct {
Name string `toml:"name"`
Endpoint string `toml:"endpoint"`
ApplicationKey string `toml:"application_key"`
ApplicationSecret string `toml:"application_secret"`
ConsumerKey string `toml:"consumer_key"`
}

type SlackConfig struct {
Webhook string `toml:"webhook"`
Reporting bool `toml:"reporting"`
Expand Down
2 changes: 1 addition & 1 deletion providers/azure/azure.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package digitalocean
package azure

import (
"context"
Expand Down
59 changes: 59 additions & 0 deletions providers/ovh/alerting/alerts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package alerting

import (
"context"
"fmt"
"time"

log "github.com/sirupsen/logrus"

"github.com/tailwarden/komiser/models"
"github.com/tailwarden/komiser/providers"
"github.com/tailwarden/komiser/providers/ovh/utils"
)

func Alerts(_ context.Context, client providers.ProviderClient) ([]models.Resource, error) {
resources := []models.Resource{}

projectIds, err := utils.GetProjects(client)
if err != nil {
return resources, err
}

for _, projectId := range projectIds {
alertingIds := []string{}
err = client.OVHClient.Get(fmt.Sprintf("/cloud/project/%s/alerting", projectId), &alertingIds)
if err != nil {
return resources, err
}

for _, alertingId := range alertingIds {
alertIds := []string{}
err = client.OVHClient.Get(fmt.Sprintf("/cloud/project/%s/alerting/%s/alert", projectId, alertingId), &alertIds)
if err != nil {
return resources, err
}

for _, alertId := range alertIds {
resources = append(resources, models.Resource{
Provider: "OVH",
Account: client.Name,
Service: "Alerting",
Region: client.OVHClient.Endpoint(),
ResourceId: alertId,
Cost: 0,
Name: alertingId,
FetchedAt: time.Now(),
})
}
}
}

log.WithFields(log.Fields{
"provider": "OVH",
"account": client.Name,
"service": "Alerting",
"resources": len(resources),
}).Info("Fetched resources")
return resources, nil
}
56 changes: 56 additions & 0 deletions providers/ovh/image/image.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package image

import (
"context"
"fmt"
"time"

log "github.com/sirupsen/logrus"

"github.com/tailwarden/komiser/models"
"github.com/tailwarden/komiser/providers"
"github.com/tailwarden/komiser/providers/ovh/utils"
)

type image struct {
Id string `json:"id"`
Name string `json:"name"`
}

func Images(_ context.Context, client providers.ProviderClient) ([]models.Resource, error) {
resources := []models.Resource{}

projectIds, err := utils.GetProjects(client)
if err != nil {
return resources, err
}

for _, projectId := range projectIds {
images := []image{}
err = client.OVHClient.Get(fmt.Sprintf("/cloud/project/%s/image", projectId), &images)
if err != nil {
return resources, err
}

for _, image := range images {
resources = append(resources, models.Resource{
Provider: "OVH",
Account: client.Name,
Service: "Image",
Region: client.OVHClient.Endpoint(),
ResourceId: image.Id,
Cost: 0,
Name: image.Name,
FetchedAt: time.Now(),
})
}
}

log.WithFields(log.Fields{
"provider": "OVH",
"account": client.Name,
"service": "Image",
"resources": len(resources),
}).Info("Fetched resources")
return resources, nil
}
Loading