-
Notifications
You must be signed in to change notification settings - Fork 20
/
dbaas_cacertificate.go
52 lines (37 loc) · 1.32 KB
/
dbaas_cacertificate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"github.com/exoscale/cli/pkg/account"
"github.com/exoscale/cli/pkg/globalstate"
exoapi "github.com/exoscale/egoscale/v2/api"
)
type dbaasCACertificateCmd struct {
cliCommandSettings `cli-cmd:"-"`
_ bool `cli-cmd:"ca-certificate"`
Zone string `cli-short:"z"`
}
func (c *dbaasCACertificateCmd) cmdAliases() []string { return nil }
func (c *dbaasCACertificateCmd) cmdShort() string { return "Retrieve the Database CA certificate" }
func (c *dbaasCACertificateCmd) cmdLong() string {
return `This command retrieves the Exoscale organization-level CA certificate
required to access Database Services using a TLS connection.`
}
func (c *dbaasCACertificateCmd) cmdPreRun(cmd *cobra.Command, args []string) error {
cmdSetZoneFlagFromDefault(cmd)
return cliCommandDefaultPreRun(c, cmd, args)
}
func (c *dbaasCACertificateCmd) cmdRun(_ *cobra.Command, _ []string) error {
ctx := exoapi.WithEndpoint(gContext, exoapi.NewReqEndpoint(account.CurrentAccount.Environment, c.Zone))
caCertificate, err := globalstate.EgoscaleClient.GetDatabaseCACertificate(ctx, c.Zone)
if err != nil {
return err
}
_, _ = fmt.Print(caCertificate)
return nil
}
func init() {
cobra.CheckErr(registerCLICommand(dbaasCmd, &dbaasCACertificateCmd{
cliCommandSettings: defaultCLICmdSettings(),
}))
}