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

Custom TLS API #225

Merged
merged 62 commits into from
Dec 9, 2020
Merged

Custom TLS API #225

merged 62 commits into from
Dec 9, 2020

Conversation

joel-g
Copy link
Contributor

@joel-g joel-g commented Oct 20, 2020

My organization needs Custom TLS certs and we hope to not maintain our own fork.

I may have discovered a platform bug. I have noticed that POST /tls/certificates will return a 500 Internal Server Error when the "type" field is blank (see https://developer.fastly.com/reference/api/tls/custom-certs/certificates/)

The Private Key (POST /tls/private_keys) and Platform TLS (POST /tls/bulk/certificates) APIs do not return an error if "type" is blank.

This is relevant because the jsonapi marshaller only marshals the attributes and not the type. Therefore the CreateCustomCertificate() function in this PR does not currently work. I can work around this by adding "type" to the Go type and marshaling however this will break the convention found throughout the library.

@joel-g
Copy link
Contributor Author

joel-g commented Oct 20, 2020

I have also reported this possible bug in an enterprise support ticket: #300454

@ryansouza
Copy link

Hey @joel-g. I believe I've found a fix for getting the correct type in the request json. In my testing adding a primary ID field to CreateCustomCertificateInput did cause the type to be set and did not require the ID to be set nor did it include an extraneous empty ID field in the json.

type CreateCustomCertificateInput struct {
	ID       string `jsonapi:"primary,tls_certificate"`
	CertBlob string `jsonapi:"attr,cert_blob"`
	Name     string `jsonapi:"attr,name"`
}

and from testing

// json before
{"data":{"type":"","attributes":{"cert_blob":"-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----\n","name":"My certificate"}}}

// json after
{"data":{"type":"tls_certificate","attributes":{"cert_blob":"-----BEGIN CERTIFICATE-----\n...\n-----END CERTIFICATE-----\n","name":"My certificate"}}}

Does this look like it will fix the issue?

@joel-g
Copy link
Contributor Author

joel-g commented Nov 4, 2020

@ryansouza I actually discovered the same thing this morning and added a "Type string jsonapi:"primary,tls_certificate"" field that achieves the same thing.

I also have pushed more files to cover the /tls/activation and /tls/configuration API.

/tls/activation has the same issue and returns a server error if "type" is not present in the POST/PATCH update. I have added the field to the input struct to work around this.

That solves the blocker on this being mergeable.

I see there is a dev-v2 branch. Should I re-base this PR to that branch or leave it on master?

Copy link
Member

@phamann phamann left a comment

Choose a reason for hiding this comment

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

Hey @joel-g thank you for your contribution, this is a very large API with multiple endpoints, so we really appreciate your effort here. While there are a lot of comments, the majority are minor and just to enforce project convention and the others around how the JSONAPI library behaves. Let us know if you have any questions/issues.

(co-authored with @Integralist)

fastly/custom_tls_activation.go Outdated Show resolved Hide resolved
fastly/custom_tls_activation.go Outdated Show resolved Hide resolved
fastly/custom_tls_activation.go Show resolved Hide resolved
fastly/custom_tls_activation.go Show resolved Hide resolved
fastly/custom_tls_activation.go Outdated Show resolved Hide resolved
fastly/custom_tls_certificate_test.go Show resolved Hide resolved
fastly/custom_tls_configuration.go Show resolved Hide resolved
fastly/custom_tls_configuration.go Outdated Show resolved Hide resolved
fastly/custom_tls_configuration.go Show resolved Hide resolved
fastly/custom_tls_configuration.go Outdated Show resolved Hide resolved
joel-g and others added 3 commits November 6, 2020 09:18
"Include" value

Co-authored-by: Patrick Hamann <[email protected]>
@joel-g
Copy link
Contributor Author

joel-g commented Nov 10, 2020

@phamann Accepted your suggestions and removed that pesky Type field 👍

Copy link
Member

@phamann phamann left a comment

Choose a reason for hiding this comment

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

LGTM 🎉

Thank you SO MUCH for your contribution @joel-g and for your patience and understanding throughout this process. Apologies it's taken so long. Part of the reason has been we're transitioning the go-fastly project over to a new internal team and owner, @Integralist, which will hopefully mean there won't be as much delay in the future.

Related: I want him to have one final look over the PR and then we will merge and release this week for you.

@joel-g
Copy link
Contributor Author

joel-g commented Nov 11, 2020

@phamann that was actually very fast compared so some vendors open source. And it was a big PR so I'm happy to "get it right". I'm already working on adding these to https://github.com/fastly/terraform-provider-fastly so I'll see you there

Copy link
Collaborator

@Integralist Integralist left a comment

Choose a reason for hiding this comment

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

Thanks for the great work on this PR @joel-g 🙂 it's a huge chunk of the TLS API so we really appreciate the effort you've put into this.

Before I approve the PR I just had some small comments for you. If you could take a look and either address/resolve them or let me know your thoughts.

fastly/custom_tls_activation.go Outdated Show resolved Hide resolved
fastly/custom_tls_activation.go Outdated Show resolved Hide resolved
fastly/custom_tls_certificate.go Show resolved Hide resolved
fastly/custom_tls_configuration.go Outdated Show resolved Hide resolved
fastly/custom_tls_configuration.go Outdated Show resolved Hide resolved
fastly/custom_tls_configuration.go Outdated Show resolved Hide resolved
fastly/custom_tls_configuration.go Outdated Show resolved Hide resolved
fastly/errors.go Outdated Show resolved Hide resolved
fastly/errors.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@Integralist Integralist left a comment

Choose a reason for hiding this comment

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

Hi @joel-g a few quick comments.

fastly/custom_tls_certificate.go Outdated Show resolved Hide resolved
fastly/custom_tls_certificate.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@Integralist Integralist left a comment

Choose a reason for hiding this comment

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

A few more small tweaks required please Joel. Thanks!

fastly/errors.go Outdated Show resolved Hide resolved
fastly/errors.go Outdated Show resolved Hide resolved
fastly/errors.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@Integralist Integralist left a comment

Choose a reason for hiding this comment

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

Apologies @joel-g I think some of my suggestions might have been missed/mis-understood. I've added/re-added some stuff.

fastly/custom_tls_certificate.go Outdated Show resolved Hide resolved
fastly/custom_tls_certificate.go Outdated Show resolved Hide resolved
fastly/errors.go Outdated Show resolved Hide resolved
fastly/errors.go Outdated Show resolved Hide resolved
fastly/errors.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@Integralist Integralist left a comment

Choose a reason for hiding this comment

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

OK I think we might have gotten there 🎉

Thanks for all your patience and hard work @joel-g 👍🏻

Note: I have three other Go-Fastly PRs that I'm reviewing today, and so I might not cut a new Go-Fastly release just yet (e.g. once merging this PR) as I'd like to combine the other PR changesets into a single release.

@Integralist Integralist merged commit ff2c0b2 into fastly:master Dec 9, 2020
@Integralist Integralist added the enhancement New feature or request label Dec 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants