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

Support for Service Authorizations #349

Merged
merged 9 commits into from Jun 20, 2022
8 changes: 8 additions & 0 deletions fastly/errors.go
Expand Up @@ -171,6 +171,14 @@ var ErrMissingServerSideEncryptionKMSKeyID = NewFieldError("ServerSideEncryption
// requires a "ServiceID" key, but one was not set.
var ErrMissingServiceID = NewFieldError("ServiceID")

// ErrMissingUserID is an error that is returned when an input struct
// requires a "UserID" key, but one was not set
var ErrMissingUserID = NewFieldError("UserID")

// ErrMissingPermissions is an error that is returned when an input struct
// requires a "Permissions" key, but one was not set
var ErrMissingPermissions = NewFieldError("Permissions")

// ErrMissingServiceVersion is an error that is returned when an input struct
// requires a "ServiceVersion" key, but one was not set.
var ErrMissingServiceVersion = NewFieldError("ServiceVersion")
Expand Down
16 changes: 16 additions & 0 deletions fastly/fastly_test.go
Expand Up @@ -19,9 +19,15 @@ var testStatsClient = NewRealtimeStatsClient()
// testServiceID is the ID of the testing service.
var testServiceID = serviceIDForTest()

// testUserID is the ID of the testing user.
var testUserID = userIDForTest()

// Default ID of the testing service.
var defaultTestServiceID = "7i6HN3TK9wS159v2gPAZ8A"

// Default ID of the testing user.
var defaultTestUserID = "4tKBSuFhNEiIpNDxmmVydt"
noseglid marked this conversation as resolved.
Show resolved Hide resolved

const (
// ServiceTypeVCL is the type for VCL services.
ServiceTypeVCL = "vcl"
Expand All @@ -43,6 +49,16 @@ func serviceIDForTest() string {
return defaultTestServiceID
}

func userIDForTest() string {
uid := os.Getenv("FASTLY_TEST_USER_ID")

if uid != "" {
return uid
}

return defaultTestUserID
}

func vcrDisabled() bool {
vcrDisable := os.Getenv("VCR_DISABLE")

Expand Down
45 changes: 45 additions & 0 deletions fastly/fixtures/service_authorizations/cleanup.yaml
@@ -0,0 +1,45 @@
---
version: 1
interactions:
- request:
body: ""
form: {}
headers:
User-Agent:
- FastlyGo/6.3.2 (+github.com/fastly/go-fastly; go1.18)
url: https://api.fastly.com/service-authorizations/dTYPkfosjJ6dMSBZNAPff
method: DELETE
response:
body: '{"msg":"Record not found","detail":"Cannot find serviceauthorization ''dTYPkfosjJ6dMSBZNAPff''"}'
headers:
Accept-Ranges:
- bytes
Cache-Control:
- no-store
Content-Type:
- application/json
Date:
- Thu, 16 Jun 2022 14:54:33 GMT
Fastly-Ratelimit-Remaining:
- "956"
Fastly-Ratelimit-Reset:
- "1655391600"
Status:
- 404 Not Found
Strict-Transport-Security:
- max-age=31536000
Vary:
- Accept-Encoding
Via:
- 1.1 varnish, 1.1 varnish
X-Cache:
- MISS, MISS
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-slwdc9035-CONTROL-SLWDC, cache-bma1646-BMA
X-Timer:
- S1655391273.306991,VS0,VE433
status: 404 Not Found
code: 404
duration: ""
50 changes: 50 additions & 0 deletions fastly/fixtures/service_authorizations/create.yaml
@@ -0,0 +1,50 @@
---
version: 1
interactions:
- request:
body: |
{"data":{"type":"service_authorization","attributes":{"permission":"full"},"relationships":{"service":{"data":{"type":"service","id":"7i6HN3TK9wS159v2gPAZ8A"}},"user":{"data":{"type":"user","id":"4tKBSuFhNEiIpNDxmmVydt"}}}},"included":[{"type":"user","id":"4tKBSuFhNEiIpNDxmmVydt"},{"type":"service","id":"7i6HN3TK9wS159v2gPAZ8A"}]}
form: {}
headers:
Accept:
- application/vnd.api+json
Content-Type:
- application/vnd.api+json
User-Agent:
- FastlyGo/6.3.2 (+github.com/fastly/go-fastly; go1.18)
url: https://api.fastly.com/service-authorizations
method: POST
response:
body: '{"data":{"id":"dTYPkfosjJ6dMSBZNAPff","type":"service_authorization","attributes":{"created_at":"2022-06-16T14:54:32Z","updated_at":"2022-06-16T14:54:32Z","deleted_at":null,"permission":"full"},"relationships":{"service":{"data":{"id":"7i6HN3TK9wS159v2gPAZ8A","type":"service"}},"user":{"data":{"id":"4tKBSuFhNEiIpNDxmmVydt","type":"user"}}}}}'
headers:
Accept-Ranges:
- bytes
Cache-Control:
- no-store
Content-Type:
- application/vnd.api+json
Date:
- Thu, 16 Jun 2022 14:54:32 GMT
Fastly-Ratelimit-Remaining:
- "959"
Fastly-Ratelimit-Reset:
- "1655391600"
Status:
- 200 OK
Strict-Transport-Security:
- max-age=31536000
Vary:
- Accept-Encoding
Via:
- 1.1 varnish, 1.1 varnish
X-Cache:
- MISS, MISS
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-slwdc9036-CONTROL-SLWDC, cache-bma1646-BMA
X-Timer:
- S1655391272.193824,VS0,VE172
status: 200 OK
code: 200
duration: ""
41 changes: 41 additions & 0 deletions fastly/fixtures/service_authorizations/delete.yaml
@@ -0,0 +1,41 @@
---
version: 1
interactions:
- request:
body: ""
form: {}
headers:
User-Agent:
- FastlyGo/6.3.2 (+github.com/fastly/go-fastly; go1.18)
url: https://api.fastly.com/service-authorizations/dTYPkfosjJ6dMSBZNAPff
method: DELETE
response:
body: ""
headers:
Accept-Ranges:
- bytes
Cache-Control:
- no-store
Date:
- Thu, 16 Jun 2022 14:54:33 GMT
Fastly-Ratelimit-Remaining:
- "957"
Fastly-Ratelimit-Reset:
- "1655391600"
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-Served-By:
- cache-control-slwdc9036-CONTROL-SLWDC, cache-bma1646-BMA
X-Timer:
- S1655391273.032612,VS0,VE260
status: 204 No Content
code: 204
duration: ""
41 changes: 41 additions & 0 deletions fastly/fixtures/service_authorizations/get.yaml
@@ -0,0 +1,41 @@
---
version: 1
interactions:
- request:
body: ""
form: {}
headers:
User-Agent:
- FastlyGo/6.3.2 (+github.com/fastly/go-fastly; go1.18)
url: https://api.fastly.com/service-authorizations/dTYPkfosjJ6dMSBZNAPff
method: GET
response:
body: '{"data":{"id":"dTYPkfosjJ6dMSBZNAPff","type":"service_authorization","attributes":{"created_at":"2022-06-16T14:54:32Z","updated_at":"2022-06-16T14:54:32Z","deleted_at":null,"permission":"full"},"relationships":{"service":{"data":{"id":"7i6HN3TK9wS159v2gPAZ8A","type":"service"}},"user":{"data":{"id":"4tKBSuFhNEiIpNDxmmVydt","type":"user"}}}}}'
headers:
Accept-Ranges:
- bytes
Cache-Control:
- no-store
Content-Type:
- application/vnd.api+json
Date:
- Thu, 16 Jun 2022 14:54:32 GMT
Status:
- 200 OK
Strict-Transport-Security:
- max-age=31536000
Vary:
- Accept-Encoding
Via:
- 1.1 varnish, 1.1 varnish
X-Cache:
- MISS, MISS
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-slwdc9036-CONTROL-SLWDC, cache-bma1646-BMA
X-Timer:
- S1655391272.387855,VS0,VE432
status: 200 OK
code: 200
duration: ""
50 changes: 50 additions & 0 deletions fastly/fixtures/service_authorizations/update.yaml
@@ -0,0 +1,50 @@
---
version: 1
interactions:
- request:
body: |
{"data":{"type":"service_authorization","id":"dTYPkfosjJ6dMSBZNAPff","attributes":{"permission":"purge_select"}}}
form: {}
headers:
Accept:
- application/vnd.api+json
Content-Type:
- application/vnd.api+json
User-Agent:
- FastlyGo/6.3.2 (+github.com/fastly/go-fastly; go1.18)
url: https://api.fastly.com/service-authorizations/dTYPkfosjJ6dMSBZNAPff
method: PATCH
response:
body: '{"data":{"id":"dTYPkfosjJ6dMSBZNAPff","type":"service_authorization","attributes":{"created_at":"2022-06-16T14:54:32Z","updated_at":"2022-06-16T14:54:32Z","deleted_at":null,"permission":"purge_select"},"relationships":{"service":{"data":{"id":"7i6HN3TK9wS159v2gPAZ8A","type":"service"}},"user":{"data":{"id":"4tKBSuFhNEiIpNDxmmVydt","type":"user"}}}}}'
headers:
Accept-Ranges:
- bytes
Cache-Control:
- no-store
Content-Type:
- application/vnd.api+json
Date:
- Thu, 16 Jun 2022 14:54:33 GMT
Fastly-Ratelimit-Remaining:
- "958"
Fastly-Ratelimit-Reset:
- "1655391600"
Status:
- 200 OK
Strict-Transport-Security:
- max-age=31536000
Vary:
- Accept-Encoding
Via:
- 1.1 varnish, 1.1 varnish
X-Cache:
- MISS, MISS
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-slwdc9036-CONTROL-SLWDC, cache-bma1646-BMA
X-Timer:
- S1655391273.836430,VS0,VE181
status: 200 OK
code: 200
duration: ""