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

fix(json): fix invalid field name json mapping for workers subdomain #1240

Closed
wants to merge 1 commit into from

Conversation

infosec-au
Copy link

Description

We were unable to use the function inside this Golang API to retrieve the accounts worker subdomain. This was because the API response is different to what the code is expecting. The JSON field name from the API response is subdomain where as this code was expecting name. Changing the expected field name allows for us to successfully obtain the cloudflare subdomain name via this golang api.

Has your change been tested?

Yes it has been tested.

API response:

{
  "result": {
    "subdomain": "fifty-lashes-blah"
  },
  "success": true,
  "errors": [],
  "messages": []
}

With my code change:

workers subdomain {Name:fifty-lashes-blah}

Before my code change:

workers subdomain {Name:}

Code:

	api, err := cloudflare.NewWithAPIToken(token.ApiToken)
	if err != nil {
		return nil, errors.Wrap(err, "Failed to create cloudflare API session")
	}

	accs, _, err := api.Accounts(ctx, cloudflare.AccountsListParams{})
	if err != nil {
		return nil, errors.Wrap(err, "Failed to get cloudflare accounts")
	}

	var accountIds []string

	for _, acc := range accs {
		accountIds = append(accountIds, acc.ID)
	}

	for _, accIdentifier := range accountIds {
		workersSubdomain, err := api.WorkersGetSubdomain(ctx, cloudflare.AccountIdentifier(accIdentifier))
		if err != nil {
			return nil, errors.Wrap(err, "Failed to list cloudflare worker domains")
		}
		fmt.Printf("workers subdomain %+v", workersSubdomain)
	}

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.
  • This change is using publicly documented (api.cloudflare.com or developers.cloudflare.com) and stable APIs.

@github-actions
Copy link
Contributor

Oops! It looks like no changelog entry is attached to this PR. Please include a release note as described in https://github.com/cloudflare/cloudflare-go/blob/master/docs/changelog-process.md.

Example:

```release-note:TYPE
Release note
```

If you do not require a release note to be included, please add the workflow/skip-changelog-entry label.

@jacobbednarz
Copy link
Member

name is the publicly defined value in the API documentation so we'll need the team to update this accordingly.

see https://developers.cloudflare.com/api/operations/worker-subdomain-get-subdomain

@infosec-au
Copy link
Author

Hi @jacobbednarz -

Will the API response change so that it is name in the response as the API docs suggest? or will the docs change so that they reference subdomain instead?

Thank you for responding

@jacobbednarz
Copy link
Member

that's up to the team but this is technically a breaking change if the key is subdomain and not name.

@jacobbednarz
Copy link
Member

@infosec-au this has been updated in the API documentation. if you add a changelog entry to this PR, we can get it merged.

@infosec-au
Copy link
Author

Hi @jacobbednarz -

Can you please do this and get this merged, if you need it merged soon? I fixed this bug almost a year ago, and I don't have time right now to add a change log entry.

@jacobbednarz
Copy link
Member

afraid not. you've made changes to your fork's master which has branch protection enabled and is not editable by maintainers of the source repository.

if you don't have time to add the file, that's fine we can close it out and some near future work can address it.

@jacobbednarz
Copy link
Member

closing PR due to age and lack of activity. if someone wants to revive, please do otherwise this will be covered in v2 automatically.

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