Skip to content

Commit

Permalink
feat(package): FilesHash (#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
Integralist authored May 11, 2023
1 parent b2a5a9f commit aa84258
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 60 deletions.
14 changes: 7 additions & 7 deletions fastly/fixtures/package/get.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ interactions:
form: {}
headers:
User-Agent:
- FastlyGo/7.0.0 (+github.com/fastly/go-fastly; go1.18.3)
url: https://api.fastly.com/service/I1VEQVKrgJFQszKVNY3FG7/version/2/package
- FastlyGo/8.2.0 (+github.com/fastly/go-fastly; go1.18.5)
url: https://api.fastly.com/service/sSsCewrlNQiMzZHiqD8Xr0/version/2/package
method: GET
response:
body: '{"service_id":"I1VEQVKrgJFQszKVNY3FG7","id":"OScOS6exfJIxlixRHMccN5","metadata":{"name":"wasm-test","description":"Default
package template used by the Fastly CLI for Rust-based Compute@Edge projects.","authors":["[email protected]"],"language":"rust","size":2015936,"hashsum":"f99485bd301e23f028474d26d398da525de17a372ae9e7026891d7f85361d2540d14b3b091929c3f170eade573595e20b3405a9e29651ede59915f2e1652f616"},"created_at":"2022-11-15T22:02:53Z","version":2,"updated_at":"2022-11-15T22:02:54Z","deleted_at":null}'
body: '{"created_at":"2023-05-11T10:57:54Z","id":"yiXgwy8Xl4n1jVMAbpM813","updated_at":"2023-05-11T10:57:54Z","service_id":"sSsCewrlNQiMzZHiqD8Xr0","deleted_at":null,"metadata":{"name":"wasm-test","description":"Default
package template used by the Fastly CLI for Rust-based Compute@Edge projects.","authors":["[email protected]"],"language":"rust","size":2015936,"hashsum":"f99485bd301e23f028474d26d398da525de17a372ae9e7026891d7f85361d2540d14b3b091929c3f170eade573595e20b3405a9e29651ede59915f2e1652f616","files_hash":"a763d3c88968ebc17691900d3c14306762296df8e47a1c2d7661cee0e0c5aa6d4c082a7c128d6e719fe333b73b46fe3ae32694716ccd2efa21f5d9f049ceec6d"},"version":2}'
headers:
Accept-Ranges:
- bytes
Expand All @@ -20,7 +20,7 @@ interactions:
Content-Type:
- application/json
Date:
- Tue, 15 Nov 2022 22:02:54 GMT
- Thu, 11 May 2023 10:57:55 GMT
Status:
- 200 OK
Strict-Transport-Security:
Expand All @@ -34,9 +34,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-cp-aws-us-east-1-prod-1-CONTROL-AWS, cache-mad22037-MAD
- cache-control-cp-aws-us-east-2-prod-2-CONTROL-AWS-UE2, cache-lhr7357-LHR
X-Timer:
- S1668549775.623402,VS0,VE153
- S1683802675.927307,VS0,VE343
status: 200 OK
code: 200
duration: ""
16 changes: 8 additions & 8 deletions fastly/fixtures/package/service_create.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ interactions:
Content-Type:
- application/x-www-form-urlencoded
User-Agent:
- FastlyGo/7.0.0 (+github.com/fastly/go-fastly; go1.18.3)
- FastlyGo/8.2.0 (+github.com/fastly/go-fastly; go1.18.5)
url: https://api.fastly.com/service
method: POST
response:
body: '{"customer_id":"2jBAEHPlLAI176TjYdnHpB","comment":"go-fastly wasm client
test","name":"test_service_wasm_package","type":"wasm","publish_key":"","created_at":"2022-11-15T22:02:51Z","updated_at":"2022-11-15T22:02:51Z","deleted_at":null,"versions":[{"updated_at":"2022-11-15T22:02:51Z","created_at":"2022-11-15T22:02:51Z","locked":false,"deleted_at":null,"active":false,"number":1,"staging":false,"comment":"","deployed":false,"testing":false,"service_id":"I1VEQVKrgJFQszKVNY3FG7"}],"paused":false,"id":"I1VEQVKrgJFQszKVNY3FG7"}'
body: '{"customer_id":"51MumwLiSJyFTWhtbByYgR","comment":"go-fastly wasm client
test","name":"test_service_wasm_package","type":"wasm","id":"sSsCewrlNQiMzZHiqD8Xr0","created_at":"2023-05-11T10:57:51Z","updated_at":"2023-05-11T10:57:51Z","publish_key":"","deleted_at":null,"versions":[{"updated_at":"2023-05-11T10:57:51Z","staging":false,"deployed":false,"service_id":"sSsCewrlNQiMzZHiqD8Xr0","created_at":"2023-05-11T10:57:51Z","testing":false,"locked":false,"active":false,"deleted_at":null,"number":1,"comment":""}],"paused":false}'
headers:
Accept-Ranges:
- bytes
Expand All @@ -28,11 +28,11 @@ interactions:
Content-Type:
- application/json
Date:
- Tue, 15 Nov 2022 22:02:51 GMT
- Thu, 11 May 2023 10:57:51 GMT
Fastly-Ratelimit-Remaining:
- "992"
- "9994"
Fastly-Ratelimit-Reset:
- "1668553200"
- "1683802800"
Status:
- 200 OK
Strict-Transport-Security:
Expand All @@ -46,9 +46,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-cp-aws-us-east-1-prod-2-CONTROL-AWS, cache-mad22037-MAD
- cache-control-cp-aws-us-east-2-prod-1-CONTROL-AWS-UE2, cache-lhr7357-LHR
X-Timer:
- S1668549771.189588,VS0,VE397
- S1683802672.502030,VS0,VE443
status: 200 OK
code: 200
duration: ""
14 changes: 7 additions & 7 deletions fastly/fixtures/package/service_delete.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ interactions:
form: {}
headers:
User-Agent:
- FastlyGo/7.0.0 (+github.com/fastly/go-fastly; go1.18.3)
url: https://api.fastly.com/service/I1VEQVKrgJFQszKVNY3FG7
- FastlyGo/8.2.0 (+github.com/fastly/go-fastly; go1.18.5)
url: https://api.fastly.com/service/sSsCewrlNQiMzZHiqD8Xr0
method: DELETE
response:
body: '{"status":"ok"}'
Expand All @@ -19,11 +19,11 @@ interactions:
Content-Type:
- application/json
Date:
- Tue, 15 Nov 2022 22:02:56 GMT
- Thu, 11 May 2023 10:57:56 GMT
Fastly-Ratelimit-Remaining:
- "988"
- "9990"
Fastly-Ratelimit-Reset:
- "1668553200"
- "1683802800"
Status:
- 200 OK
Strict-Transport-Security:
Expand All @@ -37,9 +37,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-cp-aws-us-east-1-prod-3-CONTROL-AWS, cache-mad22037-MAD
- cache-control-cp-aws-us-east-2-prod-2-CONTROL-AWS-UE2, cache-lhr7357-LHR
X-Timer:
- S1668549776.453193,VS0,VE195
- S1683802676.342249,VS0,VE205
status: 200 OK
code: 200
duration: ""
16 changes: 8 additions & 8 deletions fastly/fixtures/package/service_version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ interactions:
Content-Type:
- application/x-www-form-urlencoded
User-Agent:
- FastlyGo/7.0.0 (+github.com/fastly/go-fastly; go1.18.3)
url: https://api.fastly.com/service/I1VEQVKrgJFQszKVNY3FG7/version
- FastlyGo/8.2.0 (+github.com/fastly/go-fastly; go1.18.5)
url: https://api.fastly.com/service/sSsCewrlNQiMzZHiqD8Xr0/version
method: POST
response:
body: '{"service_id":"I1VEQVKrgJFQszKVNY3FG7","number":2}'
body: '{"service_id":"sSsCewrlNQiMzZHiqD8Xr0","number":2}'
headers:
Accept-Ranges:
- bytes
Expand All @@ -21,11 +21,11 @@ interactions:
Content-Type:
- application/json
Date:
- Tue, 15 Nov 2022 22:02:52 GMT
- Thu, 11 May 2023 10:57:52 GMT
Fastly-Ratelimit-Remaining:
- "991"
- "9993"
Fastly-Ratelimit-Reset:
- "1668553200"
- "1683802800"
Status:
- 200 OK
Strict-Transport-Security:
Expand All @@ -39,9 +39,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-cp-aws-us-east-1-prod-3-CONTROL-AWS, cache-mad22037-MAD
- cache-control-cp-aws-us-east-2-prod-1-CONTROL-AWS-UE2, cache-lhr7357-LHR
X-Timer:
- S1668549772.828238,VS0,VE225
- S1683802672.971934,VS0,VE256
status: 200 OK
code: 200
duration: ""
20 changes: 10 additions & 10 deletions fastly/fixtures/package/update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ interactions:
Accept:
- application/json
Content-Type:
- multipart/form-data; boundary=d4d79bf336c8b328cb0ce7ec87854d192b926571500b26688ab9524cebde
- multipart/form-data; boundary=8477e59d28ad8ddd91a7f8f2fb9341b91e99e684d3487c7de370975ca96b
User-Agent:
- FastlyGo/7.0.0 (+github.com/fastly/go-fastly; go1.18.3)
url: https://api.fastly.com/service/I1VEQVKrgJFQszKVNY3FG7/version/2/package
- FastlyGo/8.2.0 (+github.com/fastly/go-fastly; go1.18.5)
url: https://api.fastly.com/service/sSsCewrlNQiMzZHiqD8Xr0/version/2/package
method: PUT
response:
body: '{"service_id":"I1VEQVKrgJFQszKVNY3FG7","version":2,"created_at":"2022-11-15T22:02:53Z","updated_at":"2022-11-15T22:02:54Z","id":"OScOS6exfJIxlixRHMccN5","deleted_at":null,"metadata":{"name":"wasm-test","description":"Default
package template used by the Fastly CLI for Rust-based Compute@Edge projects.","authors":["[email protected]"],"language":"rust","size":2015936,"hashsum":"f99485bd301e23f028474d26d398da525de17a372ae9e7026891d7f85361d2540d14b3b091929c3f170eade573595e20b3405a9e29651ede59915f2e1652f616"}}'
body: '{"service_id":"sSsCewrlNQiMzZHiqD8Xr0","version":2,"deleted_at":null,"created_at":"2023-05-11T10:57:54Z","metadata":{"name":"wasm-test","description":"Default
package template used by the Fastly CLI for Rust-based Compute@Edge projects.","authors":["[email protected]"],"language":"rust","size":2015936,"hashsum":"f99485bd301e23f028474d26d398da525de17a372ae9e7026891d7f85361d2540d14b3b091929c3f170eade573595e20b3405a9e29651ede59915f2e1652f616","files_hash":"a763d3c88968ebc17691900d3c14306762296df8e47a1c2d7661cee0e0c5aa6d4c082a7c128d6e719fe333b73b46fe3ae32694716ccd2efa21f5d9f049ceec6d"},"id":"yiXgwy8Xl4n1jVMAbpM813","updated_at":"2023-05-11T10:57:54Z"}'
headers:
Accept-Ranges:
- bytes
Expand All @@ -24,11 +24,11 @@ interactions:
Content-Type:
- application/json
Date:
- Tue, 15 Nov 2022 22:02:54 GMT
- Thu, 11 May 2023 10:57:54 GMT
Fastly-Ratelimit-Remaining:
- "990"
- "9992"
Fastly-Ratelimit-Reset:
- "1668553200"
- "1683802800"
Status:
- 200 OK
Strict-Transport-Security:
Expand All @@ -42,9 +42,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-cp-aws-us-east-1-prod-3-CONTROL-AWS, cache-mad22037-MAD
- cache-control-cp-aws-us-east-2-prod-2-CONTROL-AWS-UE2, cache-lhr7357-LHR
X-Timer:
- S1668549772.424270,VS0,VE1708
- S1683802672.285738,VS0,VE2606
status: 200 OK
code: 200
duration: ""
16 changes: 8 additions & 8 deletions fastly/fixtures/package/update_invalid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ interactions:
Accept:
- application/json
Content-Type:
- multipart/form-data; boundary=79ff1e4065e457395040733c77ef3c67bdda74e9c08fab96fe0d7e4eef13
- multipart/form-data; boundary=759393c3176d38e7ff81407b8d0b4dc0dfa111165d9febbdeffd3fbd5841
User-Agent:
- FastlyGo/7.0.0 (+github.com/fastly/go-fastly; go1.18.3)
url: https://api.fastly.com/service/I1VEQVKrgJFQszKVNY3FG7/version/2/package
- FastlyGo/8.2.0 (+github.com/fastly/go-fastly; go1.18.5)
url: https://api.fastly.com/service/sSsCewrlNQiMzZHiqD8Xr0/version/2/package
method: PUT
response:
body: '{"msg":"Bad request","detail":"Failed to extract metadata from package"}'
Expand All @@ -23,11 +23,11 @@ interactions:
Content-Type:
- application/json
Date:
- Tue, 15 Nov 2022 22:02:56 GMT
- Thu, 11 May 2023 10:57:56 GMT
Fastly-Ratelimit-Remaining:
- "989"
- "9991"
Fastly-Ratelimit-Reset:
- "1668553200"
- "1683802800"
Status:
- 400 Bad Request
Strict-Transport-Security:
Expand All @@ -41,9 +41,9 @@ interactions:
X-Cache-Hits:
- 0, 0
X-Served-By:
- cache-control-cp-aws-us-east-1-prod-7-CONTROL-AWS, cache-mad22037-MAD
- cache-control-cp-aws-us-east-2-prod-1-CONTROL-AWS-UE2, cache-lhr7357-LHR
X-Timer:
- S1668549775.248550,VS0,VE921
- S1683802675.312595,VS0,VE1002
status: 400 Bad Request
code: 400
duration: ""
21 changes: 11 additions & 10 deletions fastly/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,23 @@ type Package struct {
CreatedAt *time.Time `mapstructure:"created_at"`
DeletedAt *time.Time `mapstructure:"deleted_at"`
ID string
Metadata PackageMetadata
ServiceID string `mapstructure:"service_id"`
ServiceVersion int `mapstructure:"version"`
UpdatedAt *time.Time `mapstructure:"updated_at"`
Metadata PackageMetadata `mapstructure:"metadata"`
ServiceID string `mapstructure:"service_id"`
ServiceVersion int `mapstructure:"version"`
UpdatedAt *time.Time `mapstructure:"updated_at"`
}

// PackageMetadata is a container for metadata returned about a package.
// It is a separate struct to allow correct serialisation by mapstructure -
// the raw data is returned as a json sub-block.
type PackageMetadata struct {
Authors []string
Description string
HashSum string
Language string
Name string
Size int64
Authors []string `mapstructure:"authors"`
Description string `mapstructure:"description"`
FilesHash string `mapstructure:"files_hash"`
HashSum string `mapstructure:"hashsum"`
Language string `mapstructure:"language"`
Name string `mapstructure:"name"`
Size int64 `mapstructure:"size"`
}

// GetPackageInput is used as input to the GetPackage function.
Expand Down
8 changes: 6 additions & 2 deletions fastly/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ func TestClient_Package(t *testing.T) {

testData := Package{
Metadata: PackageMetadata{
Name: "wasm-test",
Description: "Default package template used by the Fastly CLI for Rust-based Compute@Edge projects.",
HashSum: "f99485bd301e23f028474d26d398da525de17a372ae9e7026891d7f85361d2540d14b3b091929c3f170eade573595e20b3405a9e29651ede59915f2e1652f616",
Language: "rust",
Name: "wasm-test",
Size: 2015936,
HashSum: "f99485bd301e23f028474d26d398da525de17a372ae9e7026891d7f85361d2540d14b3b091929c3f170eade573595e20b3405a9e29651ede59915f2e1652f616",
FilesHash: "a763d3c88968ebc17691900d3c14306762296df8e47a1c2d7661cee0e0c5aa6d4c082a7c128d6e719fe333b73b46fe3ae32694716ccd2efa21f5d9f049ceec6d",
},
}

Expand Down Expand Up @@ -75,6 +76,9 @@ func TestClient_Package(t *testing.T) {
if wp.Metadata.HashSum != testData.Metadata.HashSum {
t.Errorf("bad package hashsum: %q != %q", wp.Metadata.HashSum, testData.Metadata.HashSum)
}
if wp.Metadata.FilesHash != testData.Metadata.FilesHash {
t.Errorf("bad package files_hash: %q != %q", wp.Metadata.FilesHash, testData.Metadata.FilesHash)
}
if wp.Metadata.Language != testData.Metadata.Language {
t.Errorf("bad package language: %q != %q", wp.Metadata.Language, testData.Metadata.Language)
}
Expand Down

0 comments on commit aa84258

Please sign in to comment.