mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.
## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
69 lines
2.0 KiB
Go
69 lines
2.0 KiB
Go
package frontend
|
|
|
|
import (
|
|
"bytes"
|
|
"compress/gzip"
|
|
"io"
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
"go.temporal.io/api/temporalproto/openapi"
|
|
"go.temporal.io/server/common/log"
|
|
"go.temporal.io/server/common/log/tag"
|
|
"go.temporal.io/server/common/rpc/interceptor"
|
|
"go.temporal.io/server/service/frontend/configs"
|
|
)
|
|
|
|
// Small wrapper that does some pre-processing before handing requests over to the OpenAPI SDK's HTTP handler.
|
|
type OpenAPIHTTPHandler struct {
|
|
logger log.Logger
|
|
rateLimitInterceptor *interceptor.RateLimitInterceptor
|
|
}
|
|
|
|
func NewOpenAPIHTTPHandler(
|
|
rateLimitInterceptor *interceptor.RateLimitInterceptor,
|
|
logger log.Logger,
|
|
) *OpenAPIHTTPHandler {
|
|
return &OpenAPIHTTPHandler{
|
|
logger: logger,
|
|
rateLimitInterceptor: rateLimitInterceptor,
|
|
}
|
|
}
|
|
|
|
func (h *OpenAPIHTTPHandler) RegisterRoutes(r *mux.Router) {
|
|
serve := func(version int, apiName string, contentType string, spec []byte) func(http.ResponseWriter, *http.Request) {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
if err := h.rateLimitInterceptor.Allow(apiName, r.Header); err != nil {
|
|
w.WriteHeader(http.StatusTooManyRequests)
|
|
return
|
|
}
|
|
|
|
rdr, err := gzip.NewReader(bytes.NewReader(spec))
|
|
if err != nil {
|
|
h.logger.Error("failed to initialize openapi spec reader", tag.NewInt("version", version), tag.Error(err))
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
if _, err := io.Copy(w, rdr); err != nil {
|
|
h.logger.Error("failed to send openapi spec", tag.NewInt("version", version), tag.Error(err))
|
|
}
|
|
if err := rdr.Close(); err != nil {
|
|
h.logger.Error("failed to verify openapi spec checksum", tag.NewInt("version", version), tag.Error(err))
|
|
}
|
|
}
|
|
}
|
|
|
|
r.PathPrefix("/swagger.json").Methods("GET").HandlerFunc(serve(
|
|
2,
|
|
configs.OpenAPIV2APIName,
|
|
"application/vnd.oai.openapi+json;version=2.0",
|
|
openapi.OpenAPIV2JSONSpec,
|
|
))
|
|
r.PathPrefix("/openapi.yaml").Methods("GET").HandlerFunc(serve(
|
|
3,
|
|
configs.OpenAPIV3APIName,
|
|
"application/vnd.oai.openapi;version=3.0",
|
|
openapi.OpenAPIV3YAMLSpec,
|
|
))
|
|
}
|