Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't fetch unneeded DNS records in UpdateDNSRecord. #673

Merged
merged 1 commit into from
Jul 28, 2021
Merged

Don't fetch unneeded DNS records in UpdateDNSRecord. #673

merged 1 commit into from
Jul 28, 2021

Conversation

favonia
Copy link
Contributor

@favonia favonia commented Jul 22, 2021

Description

With this patch, UpdateDNSRecord only fetches the referred DNS record when Name or Type is empty. Previously, it always fetches the current record even if it is not used.

Has your change been tested?

The original test TestUpdateDNSRecord was updated to reject GET queries. Two new tests TestUpdateDNSRecordWithoutName and TestUpdateDNSRecordWithoutType were added for the cases where a GET query is expected.

Types of changes

What sort of change does your code introduce/modify?

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@@ -133,17 +133,20 @@ func (api *API) DNSRecord(ctx context.Context, zoneID, recordID string) (DNSReco
//
// API reference: https://api.cloudflare.com/#dns-records-for-a-zone-update-dns-record
func (api *API) UpdateDNSRecord(ctx context.Context, zoneID, recordID string, rr DNSRecord) error {
rec, err := api.DNSRecord(ctx, zoneID, recordID)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, this looks like a hangover from a80236a where we swapped from HTTP PUT => PATCH but still wanted the option for end users to only supply a single attribute.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Is there something else I should change in this PR?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not at this stage. I'm in the process of reviewing and checking this as it's pretty critical.

@jacobbednarz
Copy link
Member

i've had a play with this and i think we're 👌 to proceed with this. the client code i've found already passes in the full record so this shouldn't be an issue.

thanks for you contribution! 🥇

@jacobbednarz jacobbednarz merged commit 7193d32 into cloudflare:master Jul 28, 2021
@favonia favonia deleted the reduce-api-usage branch July 28, 2021 05:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants