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

refactor: refactor decisions API and add traefik (#486) #487

Closed
wants to merge 1 commit into from
Closed
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ _book
node_modules/
LICENSE.txt
*-packr.go
dev
dev
.bin/
149 changes: 146 additions & 3 deletions .schema/api.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
}
}
},
"/decisions": {
"/decisions/generic": {
"get": {
"description": "\u003e This endpoint works with all HTTP Methods (GET, POST, PUT, ...) and matches every path prefixed with /decision.\n\nThis endpoint mirrors the proxy capability of ORY Oathkeeper's proxy functionality but instead of forwarding the\nrequest to the upstream server, returns 200 (request should be allowed), 401 (unauthorized), or 403 (forbidden)\nstatus codes. This endpoint can be used to integrate with other API Proxies like Ambassador, Kong, Envoy, and many more.",
"schemes": [
Expand All @@ -88,8 +88,151 @@
"tags": [
"api"
],
"summary": "Access Control Decision API",
"operationId": "decisions",
"summary": "Access Control Generic Decision API",
"operationId": "makeGenericDecision",
"responses": {
"200": {
"description": "An empty response"
},
"401": {
"description": "The standard error format",
"schema": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int64"
},
"details": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": true
}
},
"message": {
"type": "string"
},
"reason": {
"type": "string"
},
"request": {
"type": "string"
},
"status": {
"type": "string"
}
}
}
},
"403": {
"description": "The standard error format",
"schema": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int64"
},
"details": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": true
}
},
"message": {
"type": "string"
},
"reason": {
"type": "string"
},
"request": {
"type": "string"
},
"status": {
"type": "string"
}
}
}
},
"404": {
"description": "The standard error format",
"schema": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int64"
},
"details": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": true
}
},
"message": {
"type": "string"
},
"reason": {
"type": "string"
},
"request": {
"type": "string"
},
"status": {
"type": "string"
}
}
}
},
"500": {
"description": "The standard error format",
"schema": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int64"
},
"details": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": true
}
},
"message": {
"type": "string"
},
"reason": {
"type": "string"
},
"request": {
"type": "string"
},
"status": {
"type": "string"
}
}
}
}
}
}
},
"/decisions/traefik": {
"get": {
"description": "This endpoint mirrors the proxy capability of ORY Oathkeeper's proxy functionality but instead of forwarding the\nrequest to the upstream server, returns 200 (request should be allowed), 401 (unauthorized), or 403 (forbidden)\nstatus codes. This endpoint can be used to integrate with the Traefik proxy.",
"schemes": [
"http",
"https"
],
"tags": [
"api"
],
"summary": "Access Control Decision Traefik API",
"operationId": "makeTraefikDecision",
"responses": {
"200": {
"description": "An empty response"
Expand Down
20 changes: 10 additions & 10 deletions api/decision.go → api/decision_generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,26 @@ import (
)

const (
DecisionPath = "/decisions"
DecisionPath = "/decisions/generic"
)

type decisionHandlerRegistry interface {
type decisionGenericHandlerDependencies interface {
x.RegistryWriter
x.RegistryLogger

RuleMatcher() rule.Matcher
ProxyRequestHandler() *proxy.RequestHandler
}

type DecisionHandler struct {
r decisionHandlerRegistry
type DecisionGenericHandler struct {
r decisionGenericHandlerDependencies
}

func NewJudgeHandler(r decisionHandlerRegistry) *DecisionHandler {
return &DecisionHandler{r: r}
func NewDecisionGenericHandler(r decisionGenericHandlerDependencies) *DecisionGenericHandler {
return &DecisionGenericHandler{r: r}
}

func (h *DecisionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
func (h *DecisionGenericHandler) ServeHTTP(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
if len(r.URL.Path) >= len(DecisionPath) && r.URL.Path[:len(DecisionPath)] == DecisionPath {
r.URL.Scheme = "http"
r.URL.Host = r.Host
Expand All @@ -65,9 +65,9 @@ func (h *DecisionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request, next
}
}

// swagger:route GET /decisions api decisions
// swagger:route GET /decisions/generic api makeGenericDecision
//
// Access Control Decision API
// Access Control Generic Decision API
//
// > This endpoint works with all HTTP Methods (GET, POST, PUT, ...) and matches every path prefixed with /decision.
//
Expand All @@ -83,7 +83,7 @@ func (h *DecisionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request, next
// 403: genericError
// 404: genericError
// 500: genericError
func (h *DecisionHandler) decisions(w http.ResponseWriter, r *http.Request) {
func (h *DecisionGenericHandler) decisions(w http.ResponseWriter, r *http.Request) {
fields := map[string]interface{}{
"http_method": r.Method,
"http_url": r.URL.String(),
Expand Down
Loading