Skip to content

Commit

Permalink
feat: Add proxy endpoints.
Browse files Browse the repository at this point in the history
Include response writer to httpserver requestinfo middleware, use it in
goa.
  • Loading branch information
Matovidlo committed Jul 17, 2024
1 parent 0b6134a commit 7fc7f57
Show file tree
Hide file tree
Showing 20 changed files with 1,017 additions and 53 deletions.
70 changes: 56 additions & 14 deletions api/appsproxy/design.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ var _ = API("appsproxy", func() {
Description("A service for proxing requests/authorization to data applications using Keboola components.")
Version("1.0")
HTTP(func() {
Path("v1")
Consumes("application/json")
Produces("application/json")
})
Expand Down Expand Up @@ -81,14 +80,14 @@ var _ = Service("apps-proxy", func() {
// Auxiliary endpoints ---------------------------------------------------------------------------------------------

Method("ApiRootIndex", func() {
Meta("openapi:summary", "Redirect to /v1")
Description("Redirect to /v1.")
Meta("openapi:summary", "Redirect to /_proxy")
Description("Redirect to /_proxy.")
NoSecurity()
HTTP(func() {
// Redirect / -> /v1
// Redirect / -> /_proxy
GET("//")
Meta("openapi:tag:documentation")
Redirect("/v1", StatusMovedPermanently)
Meta("openapi:tag:appsproxy")
Redirect("/_proxy", StatusMovedPermanently)
})
})

Expand All @@ -98,7 +97,7 @@ var _ = Service("apps-proxy", func() {
NoSecurity()
Result(ServiceDetail)
HTTP(func() {
GET("")
GET("v1/")
Meta("openapi:tag:documentation")
Response(StatusOK)
})
Expand All @@ -118,23 +117,23 @@ var _ = Service("apps-proxy", func() {
})
})

Files("/documentation/openapi.json", "openapi.json", func() {
Files("v1/documentation/openapi.json", "openapi.json", func() {
Meta("openapi:summary", "Swagger 2.0 JSON Specification")
Meta("openapi:tag:documentation")
})
Files("/documentation/openapi.yaml", "openapi.yaml", func() {
Files("v1/documentation/openapi.yaml", "openapi.yaml", func() {
Meta("openapi:summary", "Swagger 2.0 YAML Specification")
Meta("openapi:tag:documentation")
})
Files("/documentation/openapi3.json", "openapi3.json", func() {
Files("v1/documentation/openapi3.json", "openapi3.json", func() {
Meta("openapi:summary", "OpenAPI 3.0 JSON Specification")
Meta("openapi:tag:documentation")
})
Files("/documentation/openapi3.yaml", "openapi3.yaml", func() {
Files("v1/documentation/openapi3.yaml", "openapi3.yaml", func() {
Meta("openapi:summary", "OpenAPI 3.0 YAML Specification")
Meta("openapi:tag:documentation")
})
Files("/documentation/{*path}", "swagger-ui", func() {
Files("v1/documentation/{*path}", "swagger-ui", func() {
Meta("openapi:generate", "false")
Meta("openapi:summary", "Swagger UI")
Meta("openapi:tag:documentation")
Expand All @@ -147,12 +146,46 @@ var _ = Service("apps-proxy", func() {
Description("Validation endpoint of OIDC authorization provider configuration.")
Result(Configurations)
HTTP(func() {
GET("/validate")
Meta("openapi:tag:template")
GET("v1/validate")
Meta("openapi:tag:appsproxy")
Response(StatusOK)
})
})

Method("ProxyPath", func() {
NoSecurity()
Meta("openapi:summary", "Proxying endpoint for data applications")
Description("This endpoint proxies (accepts) all requests and redirects them to the data application.")
Payload(ProxyRequest)
Result(Any)
HTTP(func() {
GET("/_proxy/{*path}")
POST("/_proxy/{*path}")
PUT("/_proxy/{*path}")
DELETE("/_proxy/{*path}")
TRACE("/_proxy/{*path}")
CONNECT("/_proxy/{*path}")
PATCH("/_proxy/{*path}")
Meta("openapi:tag:appsproxy")
})
})
Method("Proxy", func() {
NoSecurity()
Meta("openapi:summary", "Proxying endpoint for data applications")
Description("This endpoint proxies (accepts) all requests and redirects them to the data application.")
Result(Any)
HTTP(func() {
GET("/_proxy")
POST("/_proxy")
PUT("/_proxy")
DELETE("/_proxy")
TRACE("/_proxy")
CONNECT("/_proxy")
PATCH("/_proxy")
Meta("openapi:tag:appsproxy")
})
})

// Method("RepositoryIndex", func() {
// Meta("openapi:summary", "Get template repository detail")
// Description("Get details of specified repository. Use \"keboola\" for default Keboola repository.")
Expand Down Expand Up @@ -211,6 +244,15 @@ var tokenSecurity = APIKeySecurity("storage-api-token", func() {

// Types --------------------------------------------------------------------------------------------------------------

var ProxyRequest = Type("ProxyRequest", func() {
Attribute("path", PathRequestOrDefault)
})

var PathRequestOrDefault = Type("PathRequestOrDefault", String, func() {
Description(`"Path that proxies to data application".`)
Example("")
})

var ServiceDetail = Type("ServiceDetail", func() {
Description("Information about the service")
Attribute("api", String, "Name of the API", func() {
Expand Down
2 changes: 1 addition & 1 deletion cmd/apps-proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func run(ctx context.Context, cfg config.Config, _ []string) error {
middleware.WithRedactedHeader("X-StorageAPI-Token"),
middleware.WithPropagators(propagation.TraceContext{}),
middleware.WithFilter(func(req *http.Request) bool {
return req.URL.Path != "/health-check"
return req.URL.Path != "/health-check" && req.URL.Path != "/robots.txt"
}),
},
Mount: func(c httpserver.Components) {
Expand Down
26 changes: 25 additions & 1 deletion internal/pkg/service/appsproxy/api/gen/apps_proxy/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions internal/pkg/service/appsproxy/api/gen/apps_proxy/endpoints.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions internal/pkg/service/appsproxy/api/gen/apps_proxy/service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7fc7f57

Please sign in to comment.