From 0b8b1e12aa3a4dc8cc8689da90226285582574b3 Mon Sep 17 00:00:00 2001 From: Eugene Zuev Date: Fri, 19 Jan 2024 22:44:59 +0000 Subject: [PATCH] fix: use struct instead of using pointers --- openstack/db/v1/instances/requests.go | 5 +++-- openstack/db/v1/instances/results.go | 2 +- openstack/db/v1/instances/testing/fixtures_test.go | 4 ++-- openstack/db/v1/instances/testing/requests_test.go | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/openstack/db/v1/instances/requests.go b/openstack/db/v1/instances/requests.go index 4391a106c7..504872bc2b 100644 --- a/openstack/db/v1/instances/requests.go +++ b/openstack/db/v1/instances/requests.go @@ -86,7 +86,7 @@ type CreateOpts struct { // Networks dictates how this server will be attached to available networks. Networks []NetworkOpts // A access object defines how the database service is exposed. Optional. - Access *AccessOpts `json:"access,omitempty"` + Access AccessOpts `json:"access,omitempty"` } // ToInstanceCreateMap will render a JSON map. @@ -148,7 +148,8 @@ func (opts CreateOpts) ToInstanceCreateMap() (map[string]interface{}, error) { instance["nics"] = networks } - if opts.Access != nil { + // Add check for opts.Access + if opts.Access.IsPublic || len(opts.Access.AllowedCIDR) > 0 { access, err := opts.Access.ToMap() if err != nil { return nil, err diff --git a/openstack/db/v1/instances/results.go b/openstack/db/v1/instances/results.go index 07fd8677e6..6935524261 100644 --- a/openstack/db/v1/instances/results.go +++ b/openstack/db/v1/instances/results.go @@ -114,7 +114,7 @@ type Instance struct { Addresses []Address // Controls database service exposing. - Access *AccessOpts + Access AccessOpts } func (r *Instance) UnmarshalJSON(b []byte) error { diff --git a/openstack/db/v1/instances/testing/fixtures_test.go b/openstack/db/v1/instances/testing/fixtures_test.go index 2b84a62ab9..81bd4c787f 100644 --- a/openstack/db/v1/instances/testing/fixtures_test.go +++ b/openstack/db/v1/instances/testing/fixtures_test.go @@ -240,7 +240,7 @@ var expectedInstance = instances.Instance{ Type: "mysql", Version: "5.6", }, - Access: &instances.AccessOpts{ + Access: instances.AccessOpts{ IsPublic: true, AllowedCIDR: []string{"202.78.240.0/24"}, }, @@ -271,7 +271,7 @@ var expectedGetInstance = instances.Instance{ {Type: "private", Address: "10.1.0.62"}, {Type: "public", Address: "172.24.5.114"}, }, - Access: &instances.AccessOpts{ + Access: instances.AccessOpts{ IsPublic: true, AllowedCIDR: []string{"202.78.240.0/24"}, }, diff --git a/openstack/db/v1/instances/testing/requests_test.go b/openstack/db/v1/instances/testing/requests_test.go index 5d722f3450..5ae253e7e6 100644 --- a/openstack/db/v1/instances/testing/requests_test.go +++ b/openstack/db/v1/instances/testing/requests_test.go @@ -35,7 +35,7 @@ func TestCreate(t *testing.T) { }, Size: 2, VolumeType: "ssd", - Access: &instances.AccessOpts{ + Access: instances.AccessOpts{ IsPublic: true, AllowedCIDR: []string{"202.78.240.0/24"}, }, @@ -71,7 +71,7 @@ func TestCreateWithFault(t *testing.T) { }, Size: 2, VolumeType: "ssd", - Access: &instances.AccessOpts{ + Access: instances.AccessOpts{ IsPublic: true, AllowedCIDR: []string{"202.78.240.0/24"}, },