From 33da40abd91083015bc76ed96f1b47638b779187 Mon Sep 17 00:00:00 2001 From: Azanul Date: Mon, 30 Oct 2023 21:43:17 +0530 Subject: [PATCH] feat: ovh load config Signed-off-by: Azanul --- internal/config/load.go | 32 ++++++++++++++++++++++++++++++++ models/config.go | 9 +++++++++ 2 files changed, 41 insertions(+) diff --git a/internal/config/load.go b/internal/config/load.go index 9d3d25fcb..fb8dea3ce 100644 --- a/internal/config/load.go +++ b/internal/config/load.go @@ -19,6 +19,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" @@ -455,5 +456,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 } diff --git a/models/config.go b/models/config.go index 528bfe7fd..34a0ffd6a 100644 --- a/models/config.go +++ b/models/config.go @@ -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"` @@ -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"`