-
Notifications
You must be signed in to change notification settings - Fork 130
Updates needed to support Terraform TLS resources #259
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c373412
Change TLS certificate `name` attribute to be optional
wjam dead44d
Not use uint pointers in ListPrivateKeysInput struct
bengesoff 76ac7ff
Change TLS Activation `configuration` attribute to be optional (#28)
bengesoff d8c51e4
Add TLS domains endpoint support
wjam 7b47bb2
Drop use of reflection to build request parameters
wjam 051dab9
Add documentation
wjam 2f92063
TLS Subscriptions endpoints (#30)
bengesoff 9d578de
Add TLS Authorizations to TLS Subscriptions (#31)
bengesoff 78b094e
Avoid use pointers and uint in ListBulkCertificatesInput struct
wjam 4cae210
Add allow_untrusted_root field to platform TLS
bengesoff ef9a9df
Get Certificate ID for TLS Subscriptions when available
bengesoff a7472d8
Remove (TLS)\w* from field names of TLS structs
bengesoff 2732f6b
Add CommonName to Create, Get, and List TLSSubscription functions
bengesoff acf345e
Add "force" flag to TLS Subscription deletion
bengesoff 48754ff
go mod tidy
bengesoff a5451bc
Add comments describing new structs and function
bengesoff a730878
Document TLSAuthorizations struct
bengesoff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| package fastly | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "reflect" | ||
| "strconv" | ||
|
|
||
| "github.com/google/jsonapi" | ||
| ) | ||
|
|
||
| // ListTLSDomainsInput is used as input to Client.ListTLSDomains. | ||
| type ListTLSDomainsInput struct { | ||
| // Limit the returned domains to those currently using Fastly to terminate TLS with SNI (that is, domains considered "in use") | ||
| FilterInUse *bool | ||
| // Limit the returned domains to those listed in the given TLS certificate's SAN list | ||
| FilterTLSCertificateID string | ||
| // Limit the returned domains to those for a given TLS subscription | ||
| FilterTLSSubscriptionID string | ||
| // Include related objects | ||
| Include string | ||
| // Current page | ||
| PageNumber int | ||
| // Number of records per page | ||
| PageSize int | ||
| // The order in which to list the results by creation date | ||
| Sort string | ||
| } | ||
|
|
||
| // formatFilters converts user input into query parameters for filtering. | ||
| func (l *ListTLSDomainsInput) formatFilters() map[string]string { | ||
| result := map[string]string{} | ||
| pairings := map[string]interface{}{ | ||
| "filter[in_use]": l.FilterInUse, | ||
| "filter[tls_certificate.id]": l.FilterTLSCertificateID, | ||
| "filter[tls_subscriptions.id]": l.FilterTLSSubscriptionID, | ||
| "include": l.Include, | ||
| "page[number]": l.PageNumber, | ||
| "page[size]": l.PageSize, | ||
| "sort": l.Sort, | ||
| } | ||
|
|
||
| for key, value := range pairings { | ||
| switch t := value.(type) { | ||
| case string: | ||
| if t != "" { | ||
| result[key] = t | ||
| } | ||
| case int: | ||
| if t != 0 { | ||
| result[key] = strconv.Itoa(t) | ||
| } | ||
| case *bool: | ||
| if t != nil { | ||
| result[key] = strconv.FormatBool(*t) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return result | ||
| } | ||
|
|
||
| // ListTLSDomains retrieves a page of TLS domains. | ||
| func (c *Client) ListTLSDomains(i *ListTLSDomainsInput) ([]*TLSDomain, error) { | ||
| p := "/tls/domains" | ||
| filters := &RequestOptions{ | ||
| Params: i.formatFilters(), | ||
| Headers: map[string]string{ | ||
| "Accept": "application/vnd.api+json", // this is required otherwise the filters don't work | ||
| }, | ||
| } | ||
|
|
||
| r, err := c.Get(p, filters) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| data, err := jsonapi.UnmarshalManyPayload(r.Body, reflect.TypeOf(new(TLSDomain))) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| a := make([]*TLSDomain, len(data)) | ||
| for i := range data { | ||
| typed, ok := data[i].(*TLSDomain) | ||
| if !ok { | ||
| return nil, fmt.Errorf("unexpected response type: %T", data[i]) | ||
| } | ||
| a[i] = typed | ||
| } | ||
|
|
||
| return a, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package fastly | ||
|
|
||
| import ( | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestClient_ListTLSDomains(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| fixtureBase := "custom_tls_domain/" | ||
|
|
||
| var err error | ||
|
|
||
| // List | ||
| var ldom []*TLSDomain | ||
| record(t, fixtureBase+"list", func(c *Client) { | ||
| ldom, err = c.ListTLSDomains(&ListTLSDomainsInput{ | ||
| PageSize: 10, | ||
| }) | ||
| }) | ||
| if err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| if len(ldom) < 1 { | ||
| t.Errorf("bad tls domains: %v", ldom) | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| --- | ||
| version: 1 | ||
| interactions: | ||
| - request: | ||
| body: "" | ||
| form: {} | ||
| headers: | ||
| Accept: | ||
| - application/vnd.api+json | ||
| User-Agent: | ||
| - FastlyGo/2.1.0 (+github.com/fastly/go-fastly; go1.15.4) | ||
| url: https://api.fastly.com/tls/domains?page%5Bsize%5D=10 | ||
| method: GET | ||
| response: | ||
| body: '{"data":[{"id":"a-real-tld.example","type":"tls_domain","relationships":{"tls_activations":{"data":[]},"tls_certificates":{"data":[{"id":"6RltCYkOfFfzPVitOyLCnV","type":"tls_certificate"}]},"tls_subscriptions":{"data":[]}}},{"id":"along-with.localhost","type":"tls_domain","relationships":{"tls_activations":{"data":[]},"tls_certificates":{"data":[{"id":"64JrNBzdRRzkefaHXLvg3e","type":"tls_certificate"}]},"tls_subscriptions":{"data":[]}}},{"id":"also-real.invalid","type":"tls_domain","relationships":{"tls_activations":{"data":[]},"tls_certificates":{"data":[{"id":"2TMKp6R51PW2VMJKiWW3eO","type":"tls_certificate"}]},"tls_subscriptions":{"data":[]}}},{"id":"and-this-is-real.test","type":"tls_domain","relationships":{"tls_activations":{"data":[]},"tls_certificates":{"data":[{"id":"1f44cer2CdblNR2WVgfGnU","type":"tls_certificate"}]},"tls_subscriptions":{"data":[]}}},{"id":"dummy.test","type":"tls_domain","relationships":{"tls_activations":{"data":[]},"tls_certificates":{"data":[{"id":"1jBkBddyG0bcMlaLp6i1Ur","type":"tls_certificate"}]},"tls_subscriptions":{"data":[]}}},{"id":"first.example","type":"tls_domain","relationships":{"tls_activations":{"data":[]},"tls_certificates":{"data":[{"id":"5tjYkVLnZKc4yscdDQ4lzz","type":"tls_certificate"}]},"tls_subscriptions":{"data":[]}}},{"id":"hello-world.example","type":"tls_domain","relationships":{"tls_activations":{"data":[]},"tls_certificates":{"data":[{"id":"4RWSfyNCwPAfUIWqtTKg2N","type":"tls_certificate"}]},"tls_subscriptions":{"data":[]}}},{"id":"pagination-pad1.test","type":"tls_domain","relationships":{"tls_activations":{"data":[]},"tls_certificates":{"data":[{"id":"7d34I8GLEja5zVq4gCq294","type":"tls_certificate"}]},"tls_subscriptions":{"data":[]}}},{"id":"pagination-pad2.test","type":"tls_domain","relationships":{"tls_activations":{"data":[]},"tls_certificates":{"data":[{"id":"77MQa3kQ1Ke3BodIuEdr3Y","type":"tls_certificate"}]},"tls_subscriptions":{"data":[]}}},{"id":"pagination-pad3.test","type":"tls_domain","relationships":{"tls_activations":{"data":[]},"tls_certificates":{"data":[{"id":"7eQZD0jAsebDtWAWphdu3p","type":"tls_certificate"}]},"tls_subscriptions":{"data":[]}}}],"links":{"self":"https://api.fastly.com/tls/domains?page%5Bnumber%5D=1\u0026page%5Bsize%5D=10","first":"https://api.fastly.com/tls/domains?page%5Bnumber%5D=1\u0026page%5Bsize%5D=10","prev":null,"next":"https://api.fastly.com/tls/domains?page%5Bnumber%5D=2\u0026page%5Bsize%5D=10","last":"https://api.fastly.com/tls/domains?page%5Bnumber%5D=2\u0026page%5Bsize%5D=10"},"meta":{"record_count":12,"current_page":1,"per_page":10,"total_pages":2}}' | ||
| headers: | ||
| Accept-Ranges: | ||
| - bytes | ||
| Content-Length: | ||
| - "2599" | ||
| Content-Type: | ||
| - application/vnd.api+json | ||
| Date: | ||
| - Mon, 25 Jan 2021 15:02:43 GMT | ||
| Status: | ||
| - 200 OK | ||
| Strict-Transport-Security: | ||
| - max-age=31536000 | ||
| Via: | ||
| - 1.1 varnish, 1.1 varnish | ||
| X-Cache: | ||
| - MISS, MISS | ||
| X-Cache-Hits: | ||
| - 0, 0 | ||
| X-Content-Type-Options: | ||
| - nosniff | ||
| X-Served-By: | ||
| - cache-control-slwdc9035-CONTROL-SLWDC, cache-lcy19235-LCY | ||
| X-Timer: | ||
| - S1611586963.753130,VS0,VE572 | ||
| status: 200 OK | ||
| code: 200 | ||
| duration: "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| --- | ||
| version: 1 | ||
| interactions: | ||
| - request: | ||
| body: "" | ||
| form: {} | ||
| headers: | ||
| User-Agent: | ||
| - FastlyGo/2.1.0 (+github.com/fastly/go-fastly; go1.15.6) | ||
| url: https://api.fastly.com/tls/subscriptions/SUBSCRIPTION_ID | ||
| method: DELETE | ||
| response: | ||
| body: "" | ||
| headers: | ||
| Accept-Ranges: | ||
| - bytes | ||
| Date: | ||
| - Mon, 25 Jan 2021 18:00:06 GMT | ||
| Status: | ||
| - 204 No Content | ||
| Strict-Transport-Security: | ||
| - max-age=31536000 | ||
| Via: | ||
| - 1.1 varnish, 1.1 varnish | ||
| X-Cache: | ||
| - MISS, MISS | ||
| X-Cache-Hits: | ||
| - 0, 0 | ||
| X-Content-Type-Options: | ||
| - nosniff | ||
| X-Served-By: | ||
| - cache-control-slwdc9037-CONTROL-SLWDC, cache-lcy19251-LCY | ||
| X-Timer: | ||
| - S1611597606.927024,VS0,VE145 | ||
| status: 204 No Content | ||
| code: 204 | ||
| duration: "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| --- | ||
| version: 1 | ||
| interactions: | ||
| - request: | ||
| body: | | ||
| {"data":{"type":"tls_subscription","relationships":{"tls_domain":{"data":[{"type":"tls_domain"}]}}},"included":[{"type":"tls_domain","attributes":{"type":""}}]} | ||
| form: {} | ||
| headers: | ||
| Accept: | ||
| - application/vnd.api+json | ||
| Content-Type: | ||
| - application/vnd.api+json | ||
| User-Agent: | ||
| - FastlyGo/2.1.0 (+github.com/fastly/go-fastly; go1.15.6) | ||
| url: https://api.fastly.com/tls/subscriptions | ||
| method: POST | ||
| response: | ||
| body: '{"data":{"id":"SUBSCRIPTION_ID","type":"tls_subscription","attributes":{"certificate_authority":"lets-encrypt","created_at":"2021-01-25T17:11:41.000Z","state":"pending","updated_at":"2021-01-25T17:11:41.000Z"},"relationships":{"tls_authorizations":{"data":[{"id":"AUTHORIZATION_ID","type":"tls_authorization"}]},"tls_certificates":{"data":[]},"tls_domains":{"data":[{"id":"DOMAIN_NAME","type":"tls_domain"}]},"common_name":{"data":{"id":"DOMAIN_NAME","type":"tls_domain"}},"tls_configuration":{"data":{"id":"CONFIGURATION_ID","type":"tls_configuration"}}}},"included":[{"id":"AUTHORIZATION_ID","type":"tls_authorization","attributes":{"challenges":[{"type":"managed-dns","record_type":"CNAME","record_name":"CNAME_CHALLENGE_DOMAIN_NAME","values":["CNAME_CHALLENGE_DOMAIN_NAME_TARGET"]},{"type":"managed-http-cname","record_type":"CNAME","record_name":"DOMAIN_NAME","values":["j.sni.global.fastly.net"]},{"type":"managed-http-a","record_type":"A","record_name":"DOMAIN_NAME","values":["151.101.2.132","151.101.66.132","151.101.130.132","151.101.194.132"]}],"created_at":"2021-01-25T17:11:41.000Z","state":"pending","updated_at":"2021-01-25T17:11:41.000Z","warnings":null},"relationships":{"tls_domain":{"data":{"id":"DOMAIN_NAME","type":"tls_domain"}}}}]}' | ||
| headers: | ||
| Accept-Ranges: | ||
| - bytes | ||
| Content-Length: | ||
| - "1322" | ||
| Content-Type: | ||
| - application/vnd.api+json | ||
| Date: | ||
| - Mon, 25 Jan 2021 17:11:41 GMT | ||
| Status: | ||
| - 201 Created | ||
| Strict-Transport-Security: | ||
| - max-age=31536000 | ||
| Via: | ||
| - 1.1 varnish, 1.1 varnish | ||
| X-Cache: | ||
| - MISS, MISS | ||
| X-Cache-Hits: | ||
| - 0, 0 | ||
| X-Content-Type-Options: | ||
| - nosniff | ||
| X-Served-By: | ||
| - cache-control-slwdc9035-CONTROL-SLWDC, cache-lcy19271-LCY | ||
| X-Timer: | ||
| - S1611594701.776296,VS0,VE800 | ||
| status: 201 Created | ||
| code: 201 | ||
| duration: "" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.