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

feat(products): Product-specific enablement and configuration. #570

Merged
merged 8 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 30 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ FILES ?= ./...

# List all our actual files, excluding vendor
GOPKGS ?= $(shell $(GO) list $(FILES) | grep -v /vendor/)
GOFILES ?= $(shell find . -name '*.go' | grep -v /vendor/)

# Tags specific for building
GOTAGS ?=
Expand All @@ -31,11 +30,6 @@ TEST_COMMAND ?= $(GO) test
all: mod-download dev-dependencies tidy fmt fiximports test vet staticcheck semgrep ## Runs all of the required cleaning and verification targets.
.PHONY: all

tidy: ## Cleans the Go module.
@echo "==> Tidying module"
@$(GO) mod tidy
.PHONY: tidy

mod-download: ## Downloads the Go module.
@echo "==> Downloading Go module"
@$(GO) mod download
Expand All @@ -48,11 +42,41 @@ dev-dependencies: ## Downloads the necessary dev dependencies.
@if [[ "$$(uname)" == 'Darwin' ]]; then brew install semgrep; fi
.PHONY: dev-dependencies

tidy: ## Cleans the Go module.
@echo "==> Tidying module"
@$(GO) mod tidy
.PHONY: tidy

fmt: ## Properly formats Go files and orders dependencies.
@echo "==> Running gofmt"
@gofmt -s -w fastly internal tools
.PHONY: fmt

fiximports: ## Properly formats and orders imports.
@echo "==> Fixing imports"
@goimports -w fastly internal tools
.PHONY: fiximports

test: ## Runs the test suite with VCR mocks enabled.
@echo "==> Testing ${NAME}"
@$(TEST_COMMAND) -timeout=30s -parallel=20 -tags="${GOTAGS}" ${GOPKGS} ${TESTARGS}
.PHONY: test

vet: ## Identifies common errors.
@echo "==> Running go vet"
@$(GO) vet ./...
.PHONY: vet

staticcheck: ## Runs the staticcheck linter.
@echo "==> Running staticcheck"
@staticcheck -version
@staticcheck ./...
.PHONY: staticcheck

semgrep: ## Run semgrep checker.
if command -v semgrep &> /dev/null; then semgrep ci --config auto --exclude-rule generic.secrets.security.detected-private-key.detected-private-key $(SEMGREP_ARGS); fi
.PHONY: semgrep

test-race: ## Runs the test suite with the -race flag to identify race conditions, if they exist.
@echo "==> Testing ${NAME} (race)"
@$(TEST_COMMAND) -timeout=60s -race -tags="${GOTAGS}" ${GOPKGS} ${TESTARGS}
Expand Down Expand Up @@ -92,35 +116,9 @@ check-mod: ## A check which lists extraneous dependencies, if they exist.
@$(shell pwd)/scripts/check-mod.sh
.PHONY: check-mod

fiximports: ## Properly formats and orders imports.
@echo "==> Fixing imports"
@goimports -w {fastly,tools}
.PHONY: fiximports

fmt: ## Properly formats Go files and orders dependencies.
@echo "==> Running gofmt"
@gofmt -s -w ${GOFILES}
.PHONY: fmt

vet: ## Identifies common errors.
@echo "==> Running go vet"
@$(GO) vet ./...
.PHONY: vet

staticcheck: ## Runs the staticcheck linter.
@echo "==> Running staticcheck"
@staticcheck -version
@staticcheck ./...
.PHONY: staticcheck

nilaway: ## Run nilaway
@nilaway ./...

# Run semgrep checker.
.PHONY: semgrep
semgrep:
if command -v semgrep &> /dev/null; then semgrep ci --config auto --exclude-rule generic.secrets.security.detected-private-key.detected-private-key $(SEMGREP_ARGS); fi

.PHONY: help
help: ## Prints this help menu.
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
Expand Down
14 changes: 14 additions & 0 deletions fastly/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,20 @@ func (c *Client) Get(p string, ro *RequestOptions) (*http.Response, error) {
return c.Request("GET", p, ro)
}

// GetJSON issues an HTTP GET request and indicates that the response
// should be JSON encoded.
func (c *Client) GetJSON(p string, ro *RequestOptions) (*http.Response, error) {
if ro == nil {
ro = new(RequestOptions)
}
if ro.Headers == nil {
ro.Headers = make(map[string]string)
}
ro.Parallel = true
ro.Headers["Accept"] = JSONMimeType
return c.Request("GET", p, ro)
}

// Head issues an HTTP HEAD request.
func (c *Client) Head(p string, ro *RequestOptions) (*http.Response, error) {
if ro == nil {
Expand Down
9 changes: 7 additions & 2 deletions fastly/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,12 +521,17 @@ func (e *HTTPError) Error() string {
}

// String implements the stringer interface and returns the string representing
// the string text that includes the status code and corresponding status text.
// the error text that includes the status code and corresponding status text.
func (e *HTTPError) String() string {
return e.Error()
}

// IsNotFound returns true if the HTTP error code is a 404, false otherwise.
// IsBadRequest returns true if the HTTP status code is 400, false otherwise.
func (e *HTTPError) IsBadRequest() bool {
return e.StatusCode == 400
}

// IsNotFound returns true if the HTTP status code is 404, false otherwise.
func (e *HTTPError) IsNotFound() bool {
return e.StatusCode == 404
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
version: 1
interactions:
- request:
body: "null"
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
User-Agent:
- FastlyGo/9.11.0 (+github.com/fastly/go-fastly; go1.23.4)
url: https://api.fastly.com/enabled-products/v1/image_optimizer/services/kKJb5bOFI47uHeBVluGfX1
method: PUT
response:
body: |
{"product":{"id":"image_optimizer","object":"product"},"service":{"id":"kKJb5bOFI47uHeBVluGfX1","object":"service"},"_links":{"self":"/enabled-products/v1/image_optimizer/services/kKJb5bOFI47uHeBVluGfX1"}}
headers:
Accept-Ranges:
- bytes
Cache-Control:
- no-store
Content-Length:
- "206"
Content-Type:
- application/json
Date:
- Sat, 07 Dec 2024 16:56:50 GMT
Pragma:
- no-cache
Server:
- fastly control-gateway
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-chi-klot8100132-CHI, cache-nyc-kteb1890026-NYC
X-Timer:
- S1733590610.048385,VS0,VE454
status: 200 OK
code: 200
duration: ""
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,51 @@
version: 1
interactions:
- request:
body: ProductID=image_optimizer&ServiceID=kKJb5bOFI47uHeBVluGfX1
form:
ProductID:
- image_optimizer
ServiceID:
- kKJb5bOFI47uHeBVluGfX1
body: "null"
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/x-www-form-urlencoded
- application/json
User-Agent:
- FastlyGo/9.3.2 (+github.com/fastly/go-fastly; go1.22.2)
url: https://api.fastly.com/enabled-products/image_optimizer/services/kKJb5bOFI47uHeBVluGfX1
- FastlyGo/9.11.0 (+github.com/fastly/go-fastly; go1.23.4)
url: https://api.fastly.com/enabled-products/v1/image_optimizer/services/kKJb5bOFI47uHeBVluGfX1
method: PUT
response:
body: |
{"product":{"id":"image_optimizer","object":"product"},"service":{"id":"kKJb5bOFI47uHeBVluGfX1","object":"service"},"_links":{"self":"/enabled-products/image_optimizer/services/kKJb5bOFI47uHeBVluGfX1"}}
{"product":{"id":"image_optimizer","object":"product"},"service":{"id":"kKJb5bOFI47uHeBVluGfX1","object":"service"},"_links":{"self":"/enabled-products/v1/image_optimizer/services/kKJb5bOFI47uHeBVluGfX1"}}
headers:
Accept-Ranges:
- bytes
Cache-Control:
- no-store
Content-Length:
- "203"
- "206"
Content-Type:
- application/json
Date:
- Tue, 14 May 2024 16:16:29 GMT
- Sat, 07 Dec 2024 16:56:45 GMT
Pragma:
- no-cache
Server:
- control-gateway
- fastly control-gateway
Status:
- 200 OK
Strict-Transport-Security:
- max-age=31536000
Vary:
- Accept-Encoding
Via:
- 1.1 varnish
- 1.1 varnish, 1.1 varnish
X-Cache:
- MISS
- MISS, MISS
X-Cache-Hits:
- "0"
- 0, 0
X-Served-By:
- cache-bfi-krnt7300110-BFI
- cache-chi-klot8100132-CHI, cache-nyc-kteb1890026-NYC
X-Timer:
- S1715703388.864441,VS0,VE1596
- S1733590605.919096,VS0,VE708
status: 200 OK
code: 200
duration: ""
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ interactions:
Content-Type:
- application/json
User-Agent:
- FastlyGo/9.3.2 (+github.com/fastly/go-fastly; go1.22.2)
url: https://api.fastly.com/service/kKJb5bOFI47uHeBVluGfX1/version/87/image_optimizer_default_settings
- FastlyGo/9.11.0 (+github.com/fastly/go-fastly; go1.23.4)
url: https://api.fastly.com/service/kKJb5bOFI47uHeBVluGfX1/version/6/image_optimizer_default_settings
method: PATCH
response:
body: '{"resize_filter":"nearest","webp":false,"webp_quality":85,"jpeg_type":"auto","jpeg_quality":85,"upscale":false,"allow_video":false}'
Expand All @@ -23,31 +23,31 @@ interactions:
Content-Type:
- application/json
Date:
- Tue, 14 May 2024 16:16:34 GMT
- Sat, 07 Dec 2024 16:56:50 GMT
Fastly-Ratelimit-Remaining:
- "986"
- "972"
Fastly-Ratelimit-Reset:
- "1715706000"
- "1733590800"
Pragma:
- no-cache
Server:
- control-gateway
- fastly control-gateway
Status:
- 200 OK
Strict-Transport-Security:
- max-age=31536000
Vary:
- Accept-Encoding
Via:
- 1.1 varnish
- 1.1 varnish, 1.1 varnish
X-Cache:
- MISS
- MISS, MISS
X-Cache-Hits:
- "0"
- 0, 0
X-Served-By:
- cache-bfi-krnt7300110-BFI
- cache-chi-klot8100033-CHI, cache-nyc-kteb1890026-NYC
X-Timer:
- S1715703394.322383,VS0,VE301
- S1733590610.764507,VS0,VE276
status: 200 OK
code: 200
duration: ""
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ interactions:
Content-Type:
- application/json
User-Agent:
- FastlyGo/9.3.2 (+github.com/fastly/go-fastly; go1.22.2)
url: https://api.fastly.com/service/kKJb5bOFI47uHeBVluGfX1/version/87/image_optimizer_default_settings
- FastlyGo/9.11.0 (+github.com/fastly/go-fastly; go1.23.4)
url: https://api.fastly.com/service/kKJb5bOFI47uHeBVluGfX1/version/6/image_optimizer_default_settings
method: PATCH
response:
body: '{"type":"https://www.fastly.com/documentation/reference/api/services/image-optimizer-default-settings/","title":"Bad
Expand All @@ -24,31 +24,31 @@ interactions:
Content-Type:
- application/problem+json
Date:
- Tue, 14 May 2024 16:16:31 GMT
- Sat, 07 Dec 2024 16:56:46 GMT
Fastly-Ratelimit-Remaining:
- "996"
- "982"
Fastly-Ratelimit-Reset:
- "1715706000"
- "1733590800"
Pragma:
- no-cache
Server:
- control-gateway
- fastly control-gateway
Status:
- 400 Bad Request
Strict-Transport-Security:
- max-age=31536000
Vary:
- Accept-Encoding
Via:
- 1.1 varnish
- 1.1 varnish, 1.1 varnish
X-Cache:
- MISS
- MISS, MISS
X-Cache-Hits:
- "0"
- 0, 0
X-Served-By:
- cache-bfi-krnt7300110-BFI
- cache-chi-klot8100033-CHI, cache-nyc-kteb1890026-NYC
X-Timer:
- S1715703391.172090,VS0,VE235
- S1733590607.717156,VS0,VE140
status: 400 Bad Request
code: 400
duration: ""
Loading
Loading