Skip to content

Commit

Permalink
dbaas: external integrations (#636)
Browse files Browse the repository at this point in the history
exoscale/dbaas-api#296

# Description
<!--
* Prefix: the title with the component name being changed. Add a short
and self describing sentence to ease the review
* Please add a few lines providing context and describing the change
* Please self comment changes whenever applicable to help with the
review process
* Please keep the checklist as part of the PR. Tick what applies to this
change.
-->

## Checklist
(For exoscale contributors)

* [x] Changelog updated (under *Unreleased* block)
* [x] Testing

## Testing

```bash
go run . dbaas external-endpoint create datadog cli-test-name-6 \
--datadog-api-key asdfasdfsadfasd \
--datadog-site datadoghq.eu \
--datadog-tags '[{"comment": "blabla","tag":"sometag"}]'
 ✔ Creating DBaaS Datadog external Endpoint "cli-test-name-6" 0s
┼────────────────────────────────┼──────────────────────────────────────┼
│   DATADOG EXTERNAL ENDPOINT    │                                      │
┼────────────────────────────────┼──────────────────────────────────────┼
│ Endpoint ID                    │ c15f1766-2321-4684-b9a8-c7bcca22949c │
│ Endpoint Name                  │ cli-test-name-6                      │
│ Endpoint Type                  │ datadog                              │
│ Datadog API Key                │ asdfasdfsadfasd                      │
│ Site                           │ datadoghq.eu                         │
│ Disable Consumer Stats         │ false                                │
│ Kafka Consumer Check Instances │ 0                                    │
│ Kafka Consumer Stats Timeout   │ 0                                    │
│ Max Partition Contexts         │ 0                                    │
│ Datadog Tags                   │ sometag (blabla)                     │
┼────────────────────────────────┼──────────────────────────────────────┼
```

```
go run . dbaas external-endpoint show datadog e87cdc43-a902-4e46-80d1-22e2bc97931a
┼────────────────────────────────┼──────────────────────────────────────┼
│   DATADOG EXTERNAL ENDPOINT    │                                      │
┼────────────────────────────────┼──────────────────────────────────────┼
│ Endpoint ID                    │ e87cdc43-a902-4e46-80d1-22e2bc97931a │
│ Endpoint Name                  │ cli-test-name-4                      │
│ Endpoint Type                  │ datadog                              │
│ Datadog API Key                │ asdfasdfsadfasd                      │
│ Site                           │ datadoghq.eu                         │
│ Disable Consumer Stats         │ false                                │
│ Kafka Consumer Check Instances │ 0                                    │
│ Kafka Consumer Stats Timeout   │ 0                                    │
│ Max Partition Contexts         │ 0                                    │
│ Datadog Tags                   │ sometag (blabla)                     │
┼────────────────────────────────┼──────────────────────────────────────┼
```

```bash
go run . dbaas external-endpoint create opensearch cli-test-name-opensearch \
--opensearch-ca "-----BEGIN CERTIFICATE-----
....
-----END CERTIFICATE-----" \
--opensearch-index-days-max 30 \
--opensearch-index-prefix "logs-" \
--opensearch-timeout 30 \
--opensearch-url "https://some-opensearch-cluster.com:9200"
 ✔ Creating DBaaS OpenSearch external Endpoint "cli-test-name-opensearch" 0s
┼──────────────────────────────┼──────────────────────────────────────────┼
│ OPENSEARCH EXTERNAL ENDPOINT │                                          │
┼──────────────────────────────┼──────────────────────────────────────────┼
│ Endpoint ID                  │ a1b175a4-27eb-4c9a-8bbd-5b03cd5d5c6f     │
│ Endpoint Name                │ cli-test-name-opensearch                 │
│ Endpoint Type                │ opensearch                               │
│ OpenSearch URL               │ https://some-opensearch-cluster.com:9200 │
│ Index Prefix                 │ logs-                                    │
│ CA Certificate               │ -----BEGIN CERTIFICATE-----              │
│                              │ MIICnTCCAiSgAwIBAgIMCL...                │
│ Index Days Max               │ 30                                       │
│ Timeout                      │ 30                                       │
┼──────────────────────────────┼──────────────────────────────────────────┼
```
```bash
go run . dbaas external-endpoint create prometheus cli-prometheus \
--prometheus-basic-auth-username prom-username \
--prometheus-basic-auth-password super-strong-secret
 ✔ Creating DBaaS Prometheus external Endpoint "cli-prometheus" 0s
┼──────────────────────────────┼──────────────────────────────────────┼
│ PROMETHEUS EXTERNAL ENDPOINT │                                      │
┼──────────────────────────────┼──────────────────────────────────────┼
│ Endpoint ID                  │ eab185cf-8adc-4a72-9dec-39a01c08df7e │
│ Endpoint Name                │ cli-prometheus                       │
│ Endpoint Type                │ prometheus                           │
│ Basic Auth Username          │ prom-username                        │
│ Basic Auth Password          │ super-strong-secret                  │
┼──────────────────────────────┼──────────────────────────────────────┼
```

```bash
go run . dbaas external-endpoint show prometheus 0ffa5b3c-bde4-4888-b9f2-1bcdbf0f8c9f
┼──────────────────────────────┼──────────────────────────────────────┼
│ PROMETHEUS EXTERNAL ENDPOINT │                                      │
┼──────────────────────────────┼──────────────────────────────────────┼
│ Endpoint ID                  │ 0ffa5b3c-bde4-4888-b9f2-1bcdbf0f8c9f │
│ Endpoint Name                │ prom-settings                        │
│ Endpoint Type                │ prometheus                           │
│ Basic Auth Username          │ something                            │
│ Basic Auth Password          │ fantastickkk                         │
┼──────────────────────────────┼──────────────────────────────────────┼
```

```bash
go run . dbaas external-endpoint create rsyslog create-rsyslog-demo \
  --rsyslog-ca "$(openssl req -x509 -newkey rsa:4096 -keyout /dev/null -out /dev/stdout -days 365 -nodes -subj '/CN=DemoCA' 2>/dev/null)" \
  --rsyslog-cert "$(openssl req -x509 -newkey rsa:4096 -keyout /dev/null -out /dev/stdout -days 365 -nodes -subj '/CN=DemoClient' 2>/dev/null)" \
  --rsyslog-format "rfc5424" \
  --rsyslog-key "$(openssl genpkey -algorithm RSA -out /dev/stdout 2>/dev/null)" \
  --rsyslog-logline "%<PRIORITY>%<VERSION> %<TIMESTAMP> %<HOSTNAME> %<APP-NAME> %<PROCID> %<MSGID> %<MESSAGE>" \
  --rsyslog-max-message-size 1000000000 \
  --rsyslog-port 40404 \
  --rsyslog-sd "something" \
  --rsyslog-server "192.168.55.5" \
  --rsyslog-tls
 ✔ Creating DBaaS Rsyslog external Endpoint "create-rsyslog-demo" 0s
┼───────────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────┼
│ RSYSLOG EXTERNAL ENDPOINT │                                                                                          │
┼───────────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────┼
│ Endpoint ID               │ ae4af2ae-7367-462d-a0ad-bdbde9153f28                                                     │
│ Endpoint Name             │ create-rsyslog-demo                                                                      │
│ Endpoint Type             │ rsyslog                                                                                  │
│ Server                    │ 192.168.55.5                                                                             │
│ Port                      │ 40404                                                                                    │
│ Tls                       │ true                                                                                     │
│ CA Certificate            │ -----BEGIN CERTIFICATE-----                                                              │
│                           │ MIIE0TCCArmgAwIBAgIUZc...                                                                │
│ Client Certificate        │ -----BEGIN CERTIFICATE-----                                                              │
│                           │ MIIE2TCCAsGgAwIBAgIUS1...                                                                │
│ Client Key                │ -----BEGIN PRIVATE KEY-----                                                              │
│                           │ MIIEvAIBADANBgkqhkiG9w...                                                                │
│ Max Message Size          │ 1000000000                                                                               │
│ Structured data block     │ something                                                                                │
│ Custom logline format     │ %<PRIORITY>%<VERSION> %<TIMESTAMP> %<HOSTNAME> %<APP-NAME> %<PROCID> %<MSGID> %<MESSAGE> │
│ Custom logline format     │ %<PRIORITY>%<VERSION> %<TIMESTAMP> %<HOSTNAME> %<APP-NAME> %<PROCID> %<MSGID> %<MESSAGE> │
┼───────────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────┼
```
<!--
Describe the tests you did
-->
  • Loading branch information
simisoft-exo authored Oct 11, 2024
1 parent 3868b32 commit 66c40e4
Show file tree
Hide file tree
Showing 39 changed files with 2,980 additions and 438 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Features
- instance pool: added min-available flag to exo compute #629
- dbaas: external endpoints and external integration commands and sub-commands

## 1.79.1

Expand Down
14 changes: 14 additions & 0 deletions cmd/dbaas_external_endpoint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package cmd

import (
"github.com/spf13/cobra"
)

var dbaasExternalEndpointCmd = &cobra.Command{
Use: "external-endpoint",
Short: "Manage DBaaS external endpoints",
}

func init() {
dbaasCmd.AddCommand(dbaasExternalEndpointCmd)
}
115 changes: 115 additions & 0 deletions cmd/dbaas_external_endpoint_create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package cmd

import (
"fmt"
"os"

"github.com/spf13/cobra"
)

type dbaasExternalEndpointCreateCmd struct {
cliCommandSettings `cli-cmd:"-"`

_ bool `cli-cmd:"create"`

Type string `cli-arg:"#"`
Name string `cli-arg:"#"`

HelpDatadog bool `cli-usage:"show usage for flags specific to the datadog external endpoint type"`
HelpElasticsearch bool `cli-usage:"show usage for flags specific to the elasticsearch external endpoint type"`
HelpOpensearch bool `cli-usage:"show usage for flags specific to the opensearch external endpoint type"`
HelpPrometheus bool `cli-usage:"show usage for flags specific to the prometheus external endpoint type"`
HelpRsyslog bool `cli-usage:"show usage for flags specific to the rsyslog external endpoint type"`

DatadogAPIKey string `cli-flag:"datadog-api-key" cli-usage:"Datadog API key" cli-hidden:""`
DatadogSite string `cli-flag:"datadog-site" cli-usage:"Datadog intake site. Defaults to datadoghq.com" cli-hidden:""`
DatadogTags string `cli-flag:"datadog-tags" cli-usage:"Datadog tags. Example. '[{\"comment\": \"ex\", \"tag\": \"aiven-asdfasda\"}]'" cli-hidden:""`
DatadogDisableConsumerStats bool `cli-flag:"datadog-disable-consumer-stats" cli-usage:"Disable consumer group metrics" cli-hidden:""`
DatadogKafkaConsumerCheckInstances int64 `cli-flag:"datadog-kafka-consumer-check-instances" cli-usage:"Number of separate instances to fetch kafka consumer statistics with" cli-hidden:""`
DatadogKafkaConsumerStatsTimeout int64 `cli-flag:"datadog-kafka-consumer-stats-timeout" cli-usage:"Number of seconds that datadog will wait to get consumer statistics from brokers" cli-hidden:""`
DatadogMaxPartitionContexts int64 `cli-flag:"datadog-max-partition-contexts" cli-usage:"Maximum number of partition contexts to send" cli-hidden:""`

ElasticsearchURL string `cli-flag:"elasticsearch-url" cli-usage:"Elasticsearch connection URL" cli-hidden:""`
ElasticsearchIndexPrefix string `cli-flag:"elasticsearch-index-prefix" cli-usage:"Elasticsearch index prefix" cli-hidden:""`
ElasticsearchCA string `cli-flag:"elasticsearch-ca" cli-usage:"PEM encoded CA certificate" cli-hidden:""`
ElasticsearchIndexDaysMax int64 `cli-flag:"elasticsearch-index-days-max" cli-usage:"Maximum number of days of logs to keep" cli-hidden:""`
ElasticsearchTimeout int64 `cli-flag:"elasticsearch-timeout" cli-usage:"Elasticsearch request timeout limit" cli-hidden:""`

OpensearchURL string `cli-flag:"opensearch-url" cli-usage:"OpenSearch connection URL" cli-hidden:""`
OpensearchIndexPrefix string `cli-flag:"opensearch-index-prefix" cli-usage:"OpenSearch index prefix" cli-hidden:""`
OpensearchCA string `cli-flag:"opensearch-ca" cli-usage:"PEM encoded CA certificate" cli-hidden:""`
OpensearchIndexDaysMax int64 `cli-flag:"opensearch-index-days-max" cli-usage:"Maximum number of days of logs to keep" cli-hidden:""`
OpensearchTimeout int64 `cli-flag:"opensearch-timeout" cli-usage:"OpenSearch request timeout limit" cli-hidden:""`

PrometheusBasicAuthUsername string `cli-flag:"prometheus-basic-auth-username" cli-usage:"Prometheus basic authentication username" cli-hidden:""`
PrometheusBasicAuthPassword string `cli-flag:"prometheus-basic-auth-password" cli-usage:"Prometheus basic authentication password" cli-hidden:""`

RsyslogServer string `cli-flag:"rsyslog-server" cli-usage:"Rsyslog server IP address or hostname" cli-hidden:""`
RsyslogPort int64 `cli-flag:"rsyslog-port" cli-usage:"Rsyslog server port" cli-hidden:""`
RsyslogTls bool `cli-flag:"rsyslog-tls" cli-usage:"Require TLS" cli-hidden:""`
RsyslogFormat string `cli-flag:"rsyslog-format" cli-usage:"Message format" cli-hidden:""`
RsyslogKey string `cli-flag:"rsyslog-key" cli-usage:"PEM encoded client key" cli-hidden:""`
RsyslogLogline string `cli-flag:"rsyslog-logline" cli-usage:"Custom syslog message format" cli-hidden:""`
RsyslogCA string `cli-flag:"rsyslog-ca" cli-usage:"PEM encoded CA certificate" cli-hidden:""`
RsyslogCert string `cli-flag:"rsyslog-cert" cli-usage:"PEM encoded client certificate" cli-hidden:""`
RsyslogSD string `cli-flag:"rsyslog-sd" cli-usage:"Structured data block for log message" cli-hidden:""`
RsyslogMaxMessageSize int64 `cli-flag:"rsyslog-max-message-size" cli-usage:"Rsyslog max message size" cli-hidden:""`
}

func (c *dbaasExternalEndpointCreateCmd) cmdPreRun(cmd *cobra.Command, args []string) error {
switch {
case cmd.Flags().Changed("help-datadog"):
cmdShowHelpFlags(cmd.Flags(), "datadog-")
os.Exit(0)
case cmd.Flags().Changed("help-elasticsearch"):
cmdShowHelpFlags(cmd.Flags(), "elasticsearch-")
os.Exit(0)
case cmd.Flags().Changed("help-opensearch"):
cmdShowHelpFlags(cmd.Flags(), "opensearch-")
os.Exit(0)
case cmd.Flags().Changed("help-prometheus"):
cmdShowHelpFlags(cmd.Flags(), "prometheus-")
os.Exit(0)
case cmd.Flags().Changed("help-rsyslog"):
cmdShowHelpFlags(cmd.Flags(), "rsyslog-")
os.Exit(0)
}

return cliCommandDefaultPreRun(c, cmd, args)
}

func (c *dbaasExternalEndpointCreateCmd) cmdAliases() []string {
return gCreateAlias
}

func (c *dbaasExternalEndpointCreateCmd) cmdLong() string {
return "Create a new external endpoint for DBaaS"
}

func (c *dbaasExternalEndpointCreateCmd) cmdShort() string {
return "Create a new external endpoint for DBaaS"
}

func (c *dbaasExternalEndpointCreateCmd) cmdRun(cmd *cobra.Command, args []string) error {
switch c.Type {
case ExternalEndpointTypeDatadog:
return c.createDatadog(cmd, args)
case ExternalEndpointTypeOpensearch:
return c.createOpensearch(cmd, args)
case ExternalEndpointTypeElasticsearch:
return c.createElasticsearch(cmd, args)
case ExternalEndpointTypePrometheus:
return c.createPrometheus(cmd, args)
case ExternalEndpointTypeRsyslog:
return c.createRsyslog(cmd, args)
default:
return fmt.Errorf("unsupported external endpoint type %q", c.Type)
}

}

func init() {
cobra.CheckErr(registerCLICommand(dbaasExternalEndpointCmd, &dbaasExternalEndpointCreateCmd{
cliCommandSettings: defaultCLICmdSettings(),
}))
}
80 changes: 80 additions & 0 deletions cmd/dbaas_external_endpoint_create_datadog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package cmd

import (
"encoding/json"
"fmt"

"github.com/spf13/cobra"

"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
v3 "github.com/exoscale/egoscale/v3"
)

func (c *dbaasExternalEndpointCreateCmd) createDatadog(cmd *cobra.Command, _ []string) error {
ctx := gContext

client, err := switchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(account.CurrentAccount.DefaultZone))
if err != nil {
return err
}

var datadogTags []v3.DBAASDatadogTag
if c.DatadogTags != "" {
if err := json.Unmarshal([]byte(c.DatadogTags), &datadogTags); err != nil {
return fmt.Errorf("failed to parse datadog tags: %v", err)
}
}

datadogRequestPayload := v3.DBAASEndpointDatadogInputCreate{
Settings: &v3.DBAASEndpointDatadogInputCreateSettings{},
}

if c.DatadogAPIKey != "" {
datadogRequestPayload.Settings.DatadogAPIKey = c.DatadogAPIKey
}
if c.DatadogSite != "" {
datadogRequestPayload.Settings.Site = v3.EnumDatadogSite(c.DatadogSite)
}
if c.DatadogTags != "" {
datadogRequestPayload.Settings.DatadogTags = datadogTags
}
if cmd.Flags().Changed("datadog-disable-consumer-stats") {
datadogRequestPayload.Settings.DisableConsumerStats = v3.Bool(c.DatadogDisableConsumerStats)
}
if c.DatadogKafkaConsumerCheckInstances != 0 {
datadogRequestPayload.Settings.KafkaConsumerCheckInstances = int64(c.DatadogKafkaConsumerCheckInstances)
}
if c.DatadogKafkaConsumerStatsTimeout != 0 {
datadogRequestPayload.Settings.KafkaConsumerStatsTimeout = int64(c.DatadogKafkaConsumerStatsTimeout)
}
if c.DatadogMaxPartitionContexts != 0 {
datadogRequestPayload.Settings.MaxPartitionContexts = int64(c.DatadogMaxPartitionContexts)
}

op, err := client.CreateDBAASExternalEndpointDatadog(ctx, c.Name, datadogRequestPayload)

if err != nil {
return err
}

decorateAsyncOperation(fmt.Sprintf("Creating DBaaS Datadog external Endpoint %q", c.Name), func() {
op, err = client.Wait(ctx, op, v3.OperationStateSuccess)
})

if err != nil {
return err
}

endpointID := op.Reference.ID.String()

if !globalstate.Quiet {
return (&dbaasExternalEndpointShowCmd{
cliCommandSettings: defaultCLICmdSettings(),
EndpointID: endpointID,
Type: "datadog",
}).cmdRun(nil, nil)
}

return nil
}
59 changes: 59 additions & 0 deletions cmd/dbaas_external_endpoint_create_elasticsearch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package cmd

import (
"fmt"
"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
v3 "github.com/exoscale/egoscale/v3"
"github.com/spf13/cobra"
)

func (c *dbaasExternalEndpointCreateCmd) createElasticsearch(_ *cobra.Command, _ []string) error {
ctx := gContext
client, err := switchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(account.CurrentAccount.DefaultZone))
if err != nil {
return err
}

elasticsearchRequestPayload := v3.DBAASEndpointElasticsearchInputCreate{
Settings: &v3.DBAASEndpointElasticsearchInputCreateSettings{},
}

if c.ElasticsearchURL != "" {
elasticsearchRequestPayload.Settings.URL = c.ElasticsearchURL
}
if c.ElasticsearchIndexPrefix != "" {
elasticsearchRequestPayload.Settings.IndexPrefix = c.ElasticsearchIndexPrefix
}
if c.ElasticsearchCA != "" {
elasticsearchRequestPayload.Settings.CA = c.ElasticsearchCA
}
if c.ElasticsearchIndexDaysMax != 0 {
elasticsearchRequestPayload.Settings.IndexDaysMax = c.ElasticsearchIndexDaysMax
}
if c.ElasticsearchTimeout != 0 {
elasticsearchRequestPayload.Settings.Timeout = c.ElasticsearchTimeout
}

op, err := client.CreateDBAASExternalEndpointElasticsearch(ctx, c.Name, elasticsearchRequestPayload)
if err != nil {
return err
}

decorateAsyncOperation(fmt.Sprintf("Creating DBaaS ElasticSearch external Endpoint %q", c.Name), func() {
op, err = client.Wait(ctx, op, v3.OperationStateSuccess)
})
if err != nil {
return err
}

endpointID := op.Reference.ID.String()
if !globalstate.Quiet {
return (&dbaasExternalEndpointShowCmd{
cliCommandSettings: defaultCLICmdSettings(),
EndpointID: endpointID,
Type: "elasticsearch",
}).cmdRun(nil, nil)
}
return nil
}
59 changes: 59 additions & 0 deletions cmd/dbaas_external_endpoint_create_opensearch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package cmd

import (
"fmt"
"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
v3 "github.com/exoscale/egoscale/v3"
"github.com/spf13/cobra"
)

func (c *dbaasExternalEndpointCreateCmd) createOpensearch(_ *cobra.Command, _ []string) error {
ctx := gContext
client, err := switchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(account.CurrentAccount.DefaultZone))
if err != nil {
return err
}

opensearchRequestPayload := v3.DBAASEndpointOpensearchInputCreate{
Settings: &v3.DBAASEndpointOpensearchInputCreateSettings{},
}

if c.OpensearchURL != "" {
opensearchRequestPayload.Settings.URL = c.OpensearchURL
}
if c.OpensearchIndexPrefix != "" {
opensearchRequestPayload.Settings.IndexPrefix = c.OpensearchIndexPrefix
}
if c.OpensearchCA != "" {
opensearchRequestPayload.Settings.CA = c.OpensearchCA
}
if c.OpensearchIndexDaysMax != 0 {
opensearchRequestPayload.Settings.IndexDaysMax = c.OpensearchIndexDaysMax
}
if c.OpensearchTimeout != 0 {
opensearchRequestPayload.Settings.Timeout = c.OpensearchTimeout
}

op, err := client.CreateDBAASExternalEndpointOpensearch(ctx, c.Name, opensearchRequestPayload)
if err != nil {
return err
}

decorateAsyncOperation(fmt.Sprintf("Creating DBaaS OpenSearch external Endpoint %q", c.Name), func() {
op, err = client.Wait(ctx, op, v3.OperationStateSuccess)
})
if err != nil {
return err
}

endpointID := op.Reference.ID.String()
if !globalstate.Quiet {
return (&dbaasExternalEndpointShowCmd{
cliCommandSettings: defaultCLICmdSettings(),
EndpointID: endpointID,
Type: "opensearch",
}).cmdRun(nil, nil)
}
return nil
}
50 changes: 50 additions & 0 deletions cmd/dbaas_external_endpoint_create_prometheus.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package cmd

import (
"fmt"
"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
v3 "github.com/exoscale/egoscale/v3"
"github.com/spf13/cobra"
)

func (c *dbaasExternalEndpointCreateCmd) createPrometheus(_ *cobra.Command, _ []string) error {
ctx := gContext
client, err := switchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(account.CurrentAccount.DefaultZone))
if err != nil {
return err
}

prometheusRequestPayload := v3.DBAASEndpointPrometheusPayload{
Settings: &v3.DBAASEndpointPrometheusPayloadSettings{},
}

if c.PrometheusBasicAuthPassword != "" {
prometheusRequestPayload.Settings.BasicAuthPassword = c.PrometheusBasicAuthPassword
}
if c.PrometheusBasicAuthUsername != "" {
prometheusRequestPayload.Settings.BasicAuthUsername = c.PrometheusBasicAuthUsername
}

op, err := client.CreateDBAASExternalEndpointPrometheus(ctx, c.Name, prometheusRequestPayload)
if err != nil {
return err
}

decorateAsyncOperation(fmt.Sprintf("Creating DBaaS Prometheus external Endpoint %q", c.Name), func() {
op, err = client.Wait(ctx, op, v3.OperationStateSuccess)
})
if err != nil {
return err
}

endpointID := op.Reference.ID.String()
if !globalstate.Quiet {
return (&dbaasExternalEndpointShowCmd{
cliCommandSettings: defaultCLICmdSettings(),
EndpointID: endpointID,
Type: "prometheus",
}).cmdRun(nil, nil)
}
return nil
}
Loading

0 comments on commit 66c40e4

Please sign in to comment.