Skip to content

Commit a9aef62

Browse files
authored
feat: don't switch zone for dns command (#750)
# Description The DNS command are not zone dependent, so this MR remove the need to change the zone for DNS command. The reason behind that: I created a role for DNS challenge for getting web certificate. ``` { "default-service-strategy": "deny", "services": { "dns": { "type": "rules", "rules": [ { "expression": "parameters.has('type') && parameters.type != 'TXT'", "action": "deny" }, { "expression": "parameters.has('name') && !parameters.name.startsWith('_acme-challenge')", "action": "deny" }, { "expression": "resources.has('dns_domain_record') && resources.dns_domain_record.has('type') && resources.dns_domain_record.type != 'TXT'", "action": "deny" }, { "expression": "resources.has('dns_domain_record') && resources.dns_domain_record.has('name') && !resources.dns_domain_record.name.startsWith('_acme-challenge')", "action": "deny" }, { "expression": "operation in ['list-dns-domains', 'list-dns-domain-records', 'get-dns-domain-record', 'create-dns-domain-record', 'delete-dns-domain-record']", "action": "allow" } ] } } } ``` I wanted to test if my role allows only the TXT records that I wanted. The easiest was to test with the exo cli. However, due to the `SwitchClientZoneV3`, the role need also the permission `compute.list-zones` (or something similar), if I want to edit DNS Records with the exo cli, which is not needed for the tools like lego or cert-manager. From what I understood, the client will be created within the `buildClient`. Let me know if I missed something. ## Checklist (For exoscale contributors) * [ ] Changelog updated (under *Unreleased* block) * [ ] Testing ## Testing Create, delete, update DNS records work.
1 parent 2212800 commit a9aef62

File tree

7 files changed

+8
-37
lines changed

7 files changed

+8
-37
lines changed

cmd/dns/dns_add.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"github.com/spf13/cobra"
88

99
exocmd "github.com/exoscale/cli/cmd"
10-
"github.com/exoscale/cli/pkg/account"
1110
"github.com/exoscale/cli/pkg/globalstate"
1211
"github.com/exoscale/cli/utils"
1312
v3 "github.com/exoscale/egoscale/v3"
@@ -25,10 +24,7 @@ func init() {
2524
func addDomainRecord(domainIdent, name, rType, content string, ttl int64, priority *int64) error {
2625

2726
ctx := exocmd.GContext
28-
client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(account.CurrentAccount.DefaultZone))
29-
if err != nil {
30-
return err
31-
}
27+
client := globalstate.EgoscaleV3Client
3228

3329
domainsList, err := client.ListDNSDomains(ctx)
3430
if err != nil {

cmd/dns/dns_create.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"github.com/spf13/cobra"
77

88
exocmd "github.com/exoscale/cli/cmd"
9-
"github.com/exoscale/cli/pkg/account"
109
"github.com/exoscale/cli/pkg/globalstate"
1110
"github.com/exoscale/cli/utils"
1211
v3 "github.com/exoscale/egoscale/v3"
@@ -31,10 +30,8 @@ func createDomain(domainName string) error {
3130
var err error
3231

3332
ctx := exocmd.GContext
34-
client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(account.CurrentAccount.DefaultZone))
35-
if err != nil {
36-
return err
37-
}
33+
client := globalstate.EgoscaleV3Client
34+
3835
utils.DecorateAsyncOperation(fmt.Sprintf("Creating DNS domain %q...", domainName), func() {
3936
_, err = client.CreateDNSDomain(ctx, v3.CreateDNSDomainRequest{
4037
UnicodeName: domainName,

cmd/dns/dns_delete.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
exocmd "github.com/exoscale/cli/cmd"
1010
"github.com/exoscale/cli/utils"
1111

12-
"github.com/exoscale/cli/pkg/account"
1312
"github.com/exoscale/cli/pkg/globalstate"
1413
v3 "github.com/exoscale/egoscale/v3"
1514
)
@@ -38,10 +37,7 @@ func init() {
3837

3938
func deleteDomain(ident string, force bool) error {
4039
ctx := exocmd.GContext
41-
client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(account.CurrentAccount.DefaultZone))
42-
if err != nil {
43-
return err
44-
}
40+
client := globalstate.EgoscaleV3Client
4541

4642
domainsList, err := client.ListDNSDomains(ctx)
4743
if err != nil {

cmd/dns/dns_list.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ import (
77

88
"github.com/spf13/cobra"
99

10-
"github.com/exoscale/cli/pkg/account"
1110
"github.com/exoscale/cli/utils"
1211

1312
exocmd "github.com/exoscale/cli/cmd"
1413
"github.com/exoscale/cli/pkg/globalstate"
1514
"github.com/exoscale/cli/pkg/output"
1615
"github.com/exoscale/cli/table"
17-
v3 "github.com/exoscale/egoscale/v3"
1816
)
1917

2018
type dnsListItemOutput struct {
@@ -60,10 +58,7 @@ Supported output template annotations: %s`,
6058

6159
func listDomains(filters []string) (output.Outputter, error) {
6260
ctx := exocmd.GContext
63-
client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(account.CurrentAccount.DefaultZone))
64-
if err != nil {
65-
return nil, err
66-
}
61+
client := globalstate.EgoscaleV3Client
6762

6863
domainsList, err := client.ListDNSDomains(ctx)
6964
if err != nil {

cmd/dns/dns_records_update.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"github.com/spf13/cobra"
77

88
exocmd "github.com/exoscale/cli/cmd"
9-
"github.com/exoscale/cli/pkg/account"
109
"github.com/exoscale/cli/pkg/globalstate"
1110
"github.com/exoscale/cli/utils"
1211
v3 "github.com/exoscale/egoscale/v3"
@@ -93,10 +92,7 @@ func updateDomainRecord(
9392
ttl, priority *int64,
9493
) error {
9594
ctx := exocmd.GContext
96-
client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(account.CurrentAccount.DefaultZone))
97-
if err != nil {
98-
return err
99-
}
95+
client := globalstate.EgoscaleV3Client
10096

10197
domainsList, err := client.ListDNSDomains(ctx)
10298
if err != nil {

cmd/dns/dns_remove.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
exocmd "github.com/exoscale/cli/cmd"
99
"github.com/exoscale/cli/utils"
1010

11-
"github.com/exoscale/cli/pkg/account"
1211
"github.com/exoscale/cli/pkg/globalstate"
1312
v3 "github.com/exoscale/egoscale/v3"
1413
)
@@ -37,10 +36,7 @@ func init() {
3736

3837
func removeDomainRecord(domainIdent, recordIdent string, force bool) error {
3938
ctx := exocmd.GContext
40-
client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(account.CurrentAccount.DefaultZone))
41-
if err != nil {
42-
return err
43-
}
39+
client := globalstate.EgoscaleV3Client
4440

4541
domainsList, err := client.ListDNSDomains(ctx)
4642
if err != nil {

cmd/dns/dns_show.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ import (
88
"github.com/spf13/cobra"
99

1010
exocmd "github.com/exoscale/cli/cmd"
11-
"github.com/exoscale/cli/pkg/account"
1211
"github.com/exoscale/cli/pkg/globalstate"
1312
"github.com/exoscale/cli/pkg/output"
1413
"github.com/exoscale/cli/utils"
15-
v3 "github.com/exoscale/egoscale/v3"
1614
)
1715

1816
type dnsShowItemOutput struct {
@@ -68,10 +66,7 @@ func showDNS(ident, name string, types []string) (output.Outputter, error) {
6866
}
6967

7068
ctx := exocmd.GContext
71-
client, err := exocmd.SwitchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(account.CurrentAccount.DefaultZone))
72-
if err != nil {
73-
return nil, err
74-
}
69+
client := globalstate.EgoscaleV3Client
7570

7671
domainsList, err := client.ListDNSDomains(ctx)
7772
if err != nil {

0 commit comments

Comments
 (0)