From 74af6c9d956f10fbad9f0aab3e2419b73fe02f0a Mon Sep 17 00:00:00 2001 From: PatrickMenoti Date: Tue, 16 Jun 2026 15:01:49 -0300 Subject: [PATCH 1/3] refactor: update v3 api url #patch --- env/prod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/env/prod b/env/prod index 810be7c8d..00289ac14 100644 --- a/env/prod +++ b/env/prod @@ -1,4 +1,4 @@ -API_URL=https://api.azion.net +API_URL=https://api.azionapi.net API_V4_URL=https://api.azion.com/v4 AUTH_URL=https://sso.azion.com/api STORAGE_URL=https://api.azion.com/v4 From c26d653207b74a4e764c63df94ee9dd6c3945b43 Mon Sep 17 00:00:00 2001 From: PatrickMenoti Date: Thu, 18 Jun 2026 16:49:45 -0300 Subject: [PATCH 2/3] chore: change calls to patch endpoint --- pkg/api/device_groups/device_groups.go | 6 +++--- pkg/api/dns_record/dns_record.go | 6 +++--- pkg/api/dns_zone/dns_zone.go | 6 +++--- pkg/cmd/update/device_groups/device_groups.go | 2 +- pkg/cmd/update/dns_record/dns_record.go | 2 +- pkg/cmd/update/dns_zone/dns_zone.go | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/api/device_groups/device_groups.go b/pkg/api/device_groups/device_groups.go index a8eedcaa8..d958e84ff 100644 --- a/pkg/api/device_groups/device_groups.go +++ b/pkg/api/device_groups/device_groups.go @@ -30,12 +30,12 @@ func (c *Client) Create(ctx context.Context, req sdk.DeviceGroupRequest, applica return resp.GetData(), nil } -func (c *Client) Update(ctx context.Context, req sdk.DeviceGroupRequest, applicationID, deviceGroupID int64) (sdk.DeviceGroup, error) { +func (c *Client) Update(ctx context.Context, req sdk.PatchedDeviceGroupRequest, applicationID, deviceGroupID int64) (sdk.DeviceGroup, error) { logger.Debug("Update Device Group") request := c.apiClient.ApplicationsDeviceGroupsAPI. - UpdateDeviceGroup(ctx, applicationID, deviceGroupID). - DeviceGroupRequest(req) + PartialUpdateDeviceGroup(ctx, applicationID, deviceGroupID). + PatchedDeviceGroupRequest(req) resp, httpResp, err := request.Execute() if err != nil { logger.Debug("Error while updating a Device Group", zap.Any("ID", deviceGroupID), zap.Error(err)) diff --git a/pkg/api/dns_record/dns_record.go b/pkg/api/dns_record/dns_record.go index 82538a86f..8cc57f84b 100644 --- a/pkg/api/dns_record/dns_record.go +++ b/pkg/api/dns_record/dns_record.go @@ -30,12 +30,12 @@ func (c *Client) Create(ctx context.Context, req sdk.RecordRequest, zoneID int64 return resp.GetData(), nil } -func (c *Client) Update(ctx context.Context, req sdk.RecordRequest, zoneID, recordID int64) (sdk.Record, error) { +func (c *Client) Update(ctx context.Context, req sdk.PatchedRecordRequest, zoneID, recordID int64) (sdk.Record, error) { logger.Debug("Update DNS Record") request := c.apiClient.DNSRecordsAPI. - UpdateDnsRecord(ctx, recordID, zoneID). - RecordRequest(req) + PartialUpdateDnsRecord(ctx, recordID, zoneID). + PatchedRecordRequest(req) resp, httpResp, err := request.Execute() if err != nil { logger.Debug("Error while updating a DNS Record", zap.Any("ID", recordID), zap.Error(err)) diff --git a/pkg/api/dns_zone/dns_zone.go b/pkg/api/dns_zone/dns_zone.go index 89c433e69..6ae53aeec 100644 --- a/pkg/api/dns_zone/dns_zone.go +++ b/pkg/api/dns_zone/dns_zone.go @@ -30,12 +30,12 @@ func (c *Client) Create(ctx context.Context, req sdk.ZoneRequest) (sdk.Zone, err return resp.GetData(), nil } -func (c *Client) Update(ctx context.Context, req sdk.UpdateZoneRequest, zoneID int64) (sdk.Zone, error) { +func (c *Client) Update(ctx context.Context, req sdk.PatchedUpdateZoneRequest, zoneID int64) (sdk.Zone, error) { logger.Debug("Update DNS Zone") request := c.apiClient.DNSZonesAPI. - UpdateDnsZone(ctx, zoneID). - UpdateZoneRequest(req) + PartialUpdateDnsZone(ctx, zoneID). + PatchedUpdateZoneRequest(req) resp, httpResp, err := request.Execute() if err != nil { logger.Debug("Error while updating a DNS Zone", zap.Any("ID", zoneID), zap.Error(err)) diff --git a/pkg/cmd/update/device_groups/device_groups.go b/pkg/cmd/update/device_groups/device_groups.go index c8108b216..a1ad96430 100644 --- a/pkg/cmd/update/device_groups/device_groups.go +++ b/pkg/cmd/update/device_groups/device_groups.go @@ -43,7 +43,7 @@ func NewCmd(f *cmdutil.Factory) *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { client := api.NewClient(f.HttpClient, f.Config.GetString("api_v4_url"), f.Config.GetString("token")) - request := sdk.DeviceGroupRequest{} + request := sdk.PatchedDeviceGroupRequest{} if !cmd.Flags().Changed("application-id") { answers, err := utils.AskInput(msg.DeviceGroupsUpdateAskInputApplicationID) diff --git a/pkg/cmd/update/dns_record/dns_record.go b/pkg/cmd/update/dns_record/dns_record.go index e92bf8e7d..6d1937064 100644 --- a/pkg/cmd/update/dns_record/dns_record.go +++ b/pkg/cmd/update/dns_record/dns_record.go @@ -49,7 +49,7 @@ func NewCmd(f *cmdutil.Factory) *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { client := api.NewClient(f.HttpClient, f.Config.GetString("api_v4_url"), f.Config.GetString("token")) - request := sdk.RecordRequest{} + request := sdk.PatchedRecordRequest{} if !cmd.Flags().Changed("zone-id") { answers, err := utils.AskInput(msg.DNSRecordUpdateAskInputZoneID) diff --git a/pkg/cmd/update/dns_zone/dns_zone.go b/pkg/cmd/update/dns_zone/dns_zone.go index c62ee2544..b6290b014 100644 --- a/pkg/cmd/update/dns_zone/dns_zone.go +++ b/pkg/cmd/update/dns_zone/dns_zone.go @@ -42,7 +42,7 @@ func NewCmd(f *cmdutil.Factory) *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { client := api.NewClient(f.HttpClient, f.Config.GetString("api_v4_url"), f.Config.GetString("token")) - request := sdk.UpdateZoneRequest{} + request := sdk.PatchedUpdateZoneRequest{} if !cmd.Flags().Changed("zone-id") { answers, err := utils.AskInput(msg.DNSZoneUpdateAskInputZoneID) From e1594596263e7173f191314cac0946d95e264404 Mon Sep 17 00:00:00 2001 From: PatrickMenoti Date: Thu, 18 Jun 2026 17:10:48 -0300 Subject: [PATCH 3/3] tests: fix tests --- pkg/cmd/update/device_groups/device_groups.go | 3 --- pkg/cmd/update/dns_record/dns_record.go | 5 ++--- pkg/cmd/update/dns_record/dns_record_test.go | 4 ++-- pkg/cmd/update/dns_zone/dns_zone.go | 6 +++--- pkg/cmd/update/dns_zone/dns_zone_test.go | 8 ++++---- utils/helpers.go | 4 ++++ 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/pkg/cmd/update/device_groups/device_groups.go b/pkg/cmd/update/device_groups/device_groups.go index a1ad96430..8f35502d9 100644 --- a/pkg/cmd/update/device_groups/device_groups.go +++ b/pkg/cmd/update/device_groups/device_groups.go @@ -84,9 +84,6 @@ func NewCmd(f *cmdutil.Factory) *cobra.Command { return utils.ErrorUnmarshalReader } } else { - // The device group update is a full replacement (PUT), and both - // name and user_agent are required. Fetch the current values for - // any attribute the user didn't provide so they are preserved. if !cmd.Flags().Changed("name") || !cmd.Flags().Changed("user-agent") { current, err := client.Get(context.Background(), fields.ApplicationID, fields.GroupID) if err != nil { diff --git a/pkg/cmd/update/dns_record/dns_record.go b/pkg/cmd/update/dns_record/dns_record.go index 6d1937064..0599e1bea 100644 --- a/pkg/cmd/update/dns_record/dns_record.go +++ b/pkg/cmd/update/dns_record/dns_record.go @@ -90,9 +90,8 @@ func NewCmd(f *cmdutil.Factory) *cobra.Command { return utils.ErrorUnmarshalReader } } else { - // The DNS record update is a full replacement (PUT); name, type - // and rdata are required. Fetch the current record and preserve - // any attribute the user didn't provide. + // The update is a partial update (PATCH). Fetch the current + // record and preserve any attribute the user didn't provide. current, err := client.Get(context.Background(), fields.ZoneID, fields.RecordID) if err != nil { return fmt.Errorf(msg.ErrorGetDNSRecord.Error(), err) diff --git a/pkg/cmd/update/dns_record/dns_record_test.go b/pkg/cmd/update/dns_record/dns_record_test.go index 289b19b0e..81d48c0c9 100644 --- a/pkg/cmd/update/dns_record/dns_record_test.go +++ b/pkg/cmd/update/dns_record/dns_record_test.go @@ -25,7 +25,7 @@ func TestUpdate(t *testing.T) { httpmock.JSONFromFile("./fixtures/response.json"), ) mock.Register( - httpmock.REST("PUT", "workspace/dns/zones/1337/records/1111"), + httpmock.REST("PATCH", "workspace/dns/zones/1337/records/1111"), httpmock.JSONFromFile("./fixtures/response.json"), ) @@ -42,7 +42,7 @@ func TestUpdate(t *testing.T) { t.Run("update with file", func(t *testing.T) { mock := &httpmock.Registry{} mock.Register( - httpmock.REST("PUT", "workspace/dns/zones/1337/records/1111"), + httpmock.REST("PATCH", "workspace/dns/zones/1337/records/1111"), httpmock.JSONFromFile("./fixtures/response.json"), ) diff --git a/pkg/cmd/update/dns_zone/dns_zone.go b/pkg/cmd/update/dns_zone/dns_zone.go index b6290b014..5061170b1 100644 --- a/pkg/cmd/update/dns_zone/dns_zone.go +++ b/pkg/cmd/update/dns_zone/dns_zone.go @@ -67,9 +67,9 @@ func NewCmd(f *cmdutil.Factory) *cobra.Command { return utils.ErrorUnmarshalReader } } else { - // The DNS zone update is a full replacement (PUT), and both - // name and active are required. Fetch the current values for - // any attribute the user didn't provide so they are preserved. + // The update is a partial update (PATCH). Fetch the current + // values for any attribute the user didn't provide so they are + // preserved. if !cmd.Flags().Changed("name") || !cmd.Flags().Changed("active") { current, err := client.Get(context.Background(), fields.ZoneID) if err != nil { diff --git a/pkg/cmd/update/dns_zone/dns_zone_test.go b/pkg/cmd/update/dns_zone/dns_zone_test.go index 7999308b6..efdc3869f 100644 --- a/pkg/cmd/update/dns_zone/dns_zone_test.go +++ b/pkg/cmd/update/dns_zone/dns_zone_test.go @@ -20,7 +20,7 @@ func TestUpdate(t *testing.T) { t.Run("update DNS zone with name and active", func(t *testing.T) { mock := &httpmock.Registry{} mock.Register( - httpmock.REST("PUT", "workspace/dns/zones/1337"), + httpmock.REST("PATCH", "workspace/dns/zones/1337"), httpmock.JSONFromFile("./fixtures/response.json"), ) @@ -42,7 +42,7 @@ func TestUpdate(t *testing.T) { httpmock.JSONFromFile("./fixtures/response.json"), ) mock.Register( - httpmock.REST("PUT", "workspace/dns/zones/1337"), + httpmock.REST("PATCH", "workspace/dns/zones/1337"), httpmock.JSONFromFile("./fixtures/response.json"), ) @@ -59,7 +59,7 @@ func TestUpdate(t *testing.T) { t.Run("update with file", func(t *testing.T) { mock := &httpmock.Registry{} mock.Register( - httpmock.REST("PUT", "workspace/dns/zones/1337"), + httpmock.REST("PATCH", "workspace/dns/zones/1337"), httpmock.JSONFromFile("./fixtures/response.json"), ) @@ -76,7 +76,7 @@ func TestUpdate(t *testing.T) { t.Run("not found", func(t *testing.T) { mock := &httpmock.Registry{} mock.Register( - httpmock.REST("PUT", "workspace/dns/zones/1234"), + httpmock.REST("PATCH", "workspace/dns/zones/1234"), httpmock.StatusStringResponse(http.StatusNotFound, "Not Found"), ) diff --git a/utils/helpers.go b/utils/helpers.go index cb47333a4..95946d11c 100644 --- a/utils/helpers.go +++ b/utils/helpers.go @@ -799,6 +799,10 @@ func LogAndRewindBody(httpResp *http.Response) error { } func LogAndRewindBodyV4(httpResp *http.Response) (string, error) { + if httpResp == nil { + return "", nil + } + logger.Debug("", zap.Any("Status Code", httpResp.StatusCode)) logger.Debug("", zap.Any("Headers", httpResp.Header)) var errResp ErrorResponse