Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

feat(storagezone): add the ability to add, get, list, and remove stor… #19

Merged
merged 4 commits into from
Jun 7, 2022

Conversation

jspizziri
Copy link
Contributor

…age zones

@jspizziri
Copy link
Contributor Author

My overarching goal is to get storage zone management into the TF provider you've written. My Golang-foo is weak (this is in fact the first Go I've ever written. There's a lot of repetition from the pullzone code and I think a more generic resource that has abstractions for Add, Get, List, Pagination, etc would be best. I took a look at Go generics and played around with them for a few minutes, and couldn't immediately get them to work for me. I figured I'd push this up as something that works is more valuable than something that's better but ultimately doesn't exist.

Would be interested in your thoughts and guidance.

Copy link
Contributor

@fho fho left a comment

Choose a reason for hiding this comment

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

@jspizziri thanks a lot for your contribution!
It looks great overall.

Please see my review comments + also check out the warnings from the CI check.

storagezone_test.go Outdated Show resolved Hide resolved
storagezone_list.go Outdated Show resolved Hide resolved
storagezone_add.go Outdated Show resolved Hide resolved
@jspizziri jspizziri force-pushed the feat/storage-zone branch from 5f5ae25 to 0b1263c Compare May 31, 2022 14:44
@jspizziri
Copy link
Contributor Author

@fho please see my updates. I believe I've taken care of everything you mentioned. I refactored things to use functions with generics and I had to upgrade to go 1.18 to do so. LMK what you think.

@jspizziri jspizziri requested a review from fho May 31, 2022 14:53
@fho
Copy link
Contributor

fho commented May 31, 2022

@jspizziri CI is failing because it uses Go 1.17 (needs to be upgraded in .github/workflows/ci.yml).

I would prefer if you could split those changes into multiple PRs or at least multiple commits.
Updating Go, supporting the storage API and refactoring the code to generics are separate topics.

It makes it easier to use the commit messages as base for changelogs, enables to revert specific changes that have introduced bugs, makes it easier to review PRs and it's also quicker to finish small changes and get them into master. :-)

@jspizziri jspizziri force-pushed the feat/storage-zone branch from 1ea304d to 84cdfd4 Compare May 31, 2022 15:26
@jspizziri
Copy link
Contributor Author

@fho please see my updates.

@jspizziri
Copy link
Contributor Author

jspizziri commented May 31, 2022

@fho the workflow is failing due to the linter. I checked and it looks like golangci-lint might not support go 1.18 yet. I did see references to go 1.18 in the changelog however, so I just pushed an update to the version of the linter the workflow is using. We'll see what happens.

@jspizziri jspizziri force-pushed the feat/storage-zone branch from 84cdfd4 to c24ca2e Compare May 31, 2022 15:47
@fho
Copy link
Contributor

fho commented May 31, 2022

@jspizziri yes, the recent golangci-lint versions work with go 1.18 but some linters are still unsupported and get disabled when requiring go 1.18

@jspizziri jspizziri force-pushed the feat/storage-zone branch 2 times, most recently from bc57b8f to 1fc8d8d Compare May 31, 2022 16:17
@jspizziri
Copy link
Contributor Author

@fho alright, all the linter errors are cleaned up and the workflow is passing.

@fho
Copy link
Contributor

fho commented May 31, 2022

@jspizziri awesome, thanks a lot.

I like the idea with the generic resource functions!
I'll review it more thoroughly latest on Thursday, have to read a bit about go-generics again first, haven't used them so far. :-)

@jspizziri
Copy link
Contributor Author

FYI I'm adding update as well since it's required by TF. I'll let you know once it's there, but it will be almost identical to everything else in terms of design so please still take a look at the generics usage.

@jspizziri jspizziri force-pushed the feat/storage-zone branch from 1fc8d8d to fbca6da Compare June 1, 2022 16:41
@jspizziri
Copy link
Contributor Author

Alright, I've updated the client to add update to storage zones. A few things of note:

  1. I modified the client to check for a 204 status code and not require a response (204 is an empty response code).
  2. There was a notable naming inconsistency with the ReplicationRegions/ReplicationZones property.

Copy link
Contributor

@fho fho left a comment

Choose a reason for hiding this comment

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

looks great, I added some comments

client.go Outdated Show resolved Hide resolved
resource_add.go Outdated Show resolved Hide resolved
resource_add.go Outdated Show resolved Hide resolved
resource_list.go Outdated Show resolved Hide resolved
resource_update.go Outdated Show resolved Hide resolved
storagezone_add.go Outdated Show resolved Hide resolved
storagezone_add.go Outdated Show resolved Hide resolved
storagezone_get.go Show resolved Hide resolved
storagezone_update.go Outdated Show resolved Hide resolved
@jspizziri jspizziri force-pushed the feat/storage-zone branch 4 times, most recently from cb342b4 to 10efbb0 Compare June 2, 2022 21:23
@fho
Copy link
Contributor

fho commented Jun 3, 2022

@jspizziri there are multiple mehtods that do not use the new resource functions, e.g.: AddCustomCertificate, RemoveCustomHostname, SetEdgeRuleEnabled could you change all to use the new resource functions, so it is consistent?

@fho
Copy link
Contributor

fho commented Jun 3, 2022

@jspizziri fyi, I made https://github.com/simplesurance/bunny-cli public.
I created the tool to test the bunny-go package manually and make experimenting with the bunny-go api a bit easier.
Often using curl + jq works similar well and testing bunny-go is better done with testcases. :-)
Maybe it's still helpful to you

@jspizziri jspizziri force-pushed the feat/storage-zone branch 3 times, most recently from 8d0d4b6 to 8e4b532 Compare June 3, 2022 13:43
@jspizziri
Copy link
Contributor Author

jspizziri commented Jun 3, 2022

I've pushed a new update. Some things of note:

  1. Refactored all the pullzone functions to use the abstracted resource* functions
  2. In doing so, I had to abstract the resource functions a bit more (pulled path interpolation out and added some more options)
  3. I removed resource_add and resource_update in favor of a resource_post which has functions for getting a response with & without content. Bunny doesn't really have a true update/PUT endpoint, so it reflects more closely their actual API.
  4. The LoadFreeCertificate function seemed a bit special so I didn't touch that for now.

LMK your thoughts from here

@jspizziri jspizziri force-pushed the feat/storage-zone branch 2 times, most recently from 12d0ead to 436d471 Compare June 3, 2022 14:05
@jspizziri
Copy link
Contributor Author

jspizziri commented Jun 3, 2022

Also, something I want to note that I just discovered about on PullZones:

The docs say that on creation of a PZ an OriginURL is required and a StorageZoneId is optional. However, the reality is that ONE of the TWO are required. You must either specify a OriginURL OR a StorageZoneID. Furthermore, passing BOTH results in OriginURL being entirely ignored (StorageZoneID is preferred).

I found this while updating the TF provider to support Storage Zones. I feel that the libs should help in this regard, and my thought was that bunny-go could log a warning if you pass both at the same time and that the TF provider could throw an error if you pass both at the same time (since it creates issues with the TF diff make it seem like there are changes to apply when there are not)

Update: I've addressed this issue in the TF provider here simplesurance/terraform-provider-bunny#67, but I think there should be something in this package that at least warns people.

@jspizziri
Copy link
Contributor Author

jspizziri commented Jun 6, 2022

Also, it should be noted that the refactor of pagination actually introduces a breaking change since it removes some old structs in favor of abstract ones. I've updated the commit dealing with that refactor/feature to document the breaking change.

@jspizziri jspizziri requested a review from fho June 6, 2022 16:55
…esource functions

upgrade pullzone to take advantaged of the abstract resource functions. a breaking change has been
introduced in this version by removing PullZone specific pagination structs in favor of more
abstract ones.

BREAKING CHANGE: `PullZonePaginationOptions` and `PullZonePaginationReply` have been replaced with
`PaginationOptions` and `PaginationReply`
@jspizziri jspizziri force-pushed the feat/storage-zone branch from 436d471 to 5d45067 Compare June 6, 2022 17:02
@fho
Copy link
Contributor

fho commented Jun 7, 2022

The docs say that on creation of a PZ an OriginURL is required and a StorageZoneId is optional. However, the reality is that ONE of the TWO are required. You must either specify a OriginURL OR a StorageZoneID. Furthermore, passing BOTH results in OriginURL being entirely ignored (StorageZoneID is preferred).

nice find, lets document it in the godoc for PullZoneAddOptions and log a message if both are passed as you suggested in a separate PR

@fho
Copy link
Contributor

fho commented Jun 7, 2022

@jspizziri looks good! thanks a for the work again.

I'm in favor of removing resourceUpdate204 and pass resp to resourcePost explicitly. I think it's more simple and clear.
I also can do that before I merge the PR.

My plan is to fix the failing integrationtest in the bunny-terraform-go provider, then run the the terraform provider with this bunny-go version to test the change thoroughly. I expect that everything works fine but better be safe. :-)
Afterwards I'll merge it.

@jspizziri
Copy link
Contributor Author

The docs say that on creation of a PZ an OriginURL is required and a StorageZoneId is optional. However, the reality is that ONE of the TWO are required. You must either specify a OriginURL OR a StorageZoneID. Furthermore, passing BOTH results in OriginURL being entirely ignored (StorageZoneID is preferred).

nice find, lets document it in the godoc for PullZoneAddOptions and log a message if both are passed as you suggested in a separate PR

#24

@jspizziri
Copy link
Contributor Author

I also can do that before I merge the PR.

@fho if you're willing to do that I'd appreciate it. I'm quite anxious to get my hands on that tf provider as I'm sure you can imagine and whatever makes that happen the fastest is my preference (and if you do it we won't need to go through another review cycle).

fho pushed a commit to simplesurance/terraform-provider-bunny that referenced this pull request Jun 7, 2022
The docs say that on creation of a PZ an OriginURL is required and a StorageZoneId is optional. 
However, the reality is that ONE of the TWO are required. You must either specify a OriginURL OR a StorageZoneID. Furthermore, passing BOTH results in OriginURL being entirely ignored (StorageZoneID is preferred).
(simplesurance/bunny-go#19 (comment))
fho added a commit that referenced this pull request Jun 7, 2022
This merge:
- updates the minimum go version to 1.18,
- updates golangci-lint in CI,
- add support for retrieving, adding, updating and deleting storage zones
- introduces resource* functions that combine calling new*Request and
  sendRequest,
- fixes typos in some error messages

GitHub Pull-Request #19
@fho fho merged commit 5d45067 into simplesurance:main Jun 7, 2022
@jspizziri jspizziri deleted the feat/storage-zone branch June 7, 2022 17:11
@fho
Copy link
Contributor

fho commented Jun 7, 2022

@jspizziri my idea to of passing resp directly did not work as I thought because I still had the type parameter I could not pass nil.

I merged with some small changes on top, thanks a lot for the PR!

@jspizziri
Copy link
Contributor Author

jspizziri commented Jun 7, 2022

@fho thanks! Thanks for all the work on this lib and the tf provider. Definitely going to be super helpful for us.

Have you reached out to the Bunny folks to let them know about these tools? I feel like a lot of people could use the TF provider and they may want to list it here

@fho
Copy link
Contributor

fho commented Jun 8, 2022

@jspizziri yes, they are aware of both. I also told them that it would be great if they could list them on their 3. party tools page but it did not happen 🤷.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants