-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
144 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ linters: | |
- varnamelen | ||
- whitespace | ||
- asciicheck | ||
- bodyclose | ||
|
||
linters-settings: | ||
whitespace: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,90 +1,83 @@ | ||
package echoplus | ||
|
||
import ( | ||
"regexp" | ||
|
||
"github.com/labstack/echo/v4" | ||
|
||
"github.com/go-sigma/sigma/pkg/middlewares/authn" | ||
"github.com/go-sigma/sigma/pkg/middlewares/authz" | ||
) | ||
|
||
// Plus ... | ||
type Plus interface { | ||
// Get ... | ||
Get(path string, authnConfig *authn.AuthnConfig, authzConfig *authz.AuthzConfig, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route | ||
// Post ... | ||
Post(path string, authnConfig *authn.AuthnConfig, authzConfig *authz.AuthzConfig, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route | ||
// Put ... | ||
Put(path string, authnConfig *authn.AuthnConfig, authzConfig *authz.AuthzConfig, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route | ||
// Delete ... | ||
Delete(path string, authnConfig *authn.AuthnConfig, authzConfig *authz.AuthzConfig, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route | ||
// Patch ... | ||
Patch(path string, authnConfig *authn.AuthnConfig, authzConfig *authz.AuthzConfig, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route | ||
} | ||
|
||
type engine interface { | ||
// Get ... | ||
GET(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route | ||
// POST ... | ||
POST(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route | ||
// PUT ... | ||
PUT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route | ||
// DELETE ... | ||
DELETE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route | ||
// PATCH ... | ||
PATCH(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route | ||
} | ||
|
||
type plus struct { | ||
*echo.Echo | ||
engine engine | ||
} | ||
|
||
// New ... | ||
func New(echo *echo.Echo) Plus { | ||
func New(e engine) Plus { | ||
return &plus{ | ||
Echo: echo, | ||
engine: e, | ||
} | ||
} | ||
|
||
// AuthzConfig ... | ||
type AuthzConfig struct { | ||
Skip bool | ||
Source []AuthzConfigSource | ||
} | ||
|
||
// AuthzConfigSource ... | ||
type AuthzConfigSource struct { | ||
Name string `json:"name"` | ||
Position string `json:"position"` | ||
} | ||
|
||
// AuthnConfig ... | ||
type AuthnConfig struct { | ||
Skip bool | ||
} | ||
|
||
// AuthConfig ... | ||
type AuthConfig struct { | ||
AuthnConfig *AuthnConfig | ||
AuthzConfig *AuthzConfig | ||
} | ||
|
||
// AuthMapper ... | ||
var AuthMapper = make(map[string]AuthConfig) | ||
|
||
// Get ... | ||
func (p *plus) Get(path string, authnConfig *AuthnConfig, authzConfig *AuthzConfig, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route { | ||
AuthMapper[path] = AuthConfig{ | ||
AuthnConfig: authnConfig, | ||
AuthzConfig: authzConfig, | ||
} | ||
return p.Echo.GET(path, h, m...) | ||
func (p *plus) Get(path string, authnConfig *authn.AuthnConfig, authzConfig *authz.AuthzConfig, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route { | ||
authn.AuthMapper[regexp.MustCompile(path)] = authnConfig | ||
authz.AuthMapper[regexp.MustCompile(path)] = authzConfig | ||
return p.engine.GET(path, h, m...) | ||
} | ||
|
||
// Post ... | ||
func (p *plus) Post(path string, authnConfig *AuthnConfig, authzConfig *AuthzConfig, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route { | ||
AuthMapper[path] = AuthConfig{ | ||
AuthnConfig: authnConfig, | ||
AuthzConfig: authzConfig, | ||
} | ||
return p.Echo.POST(path, h, m...) | ||
func (p *plus) Post(path string, authnConfig *authn.AuthnConfig, authzConfig *authz.AuthzConfig, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route { | ||
authn.AuthMapper[regexp.MustCompile(path)] = authnConfig | ||
authz.AuthMapper[regexp.MustCompile(path)] = authzConfig | ||
return p.engine.POST(path, h, m...) | ||
} | ||
|
||
// Put ... | ||
func (p *plus) Put(path string, authnConfig *AuthnConfig, authzConfig *AuthzConfig, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route { | ||
AuthMapper[path] = AuthConfig{ | ||
AuthnConfig: authnConfig, | ||
AuthzConfig: authzConfig, | ||
} | ||
return p.Echo.PUT(path, h, m...) | ||
func (p *plus) Put(path string, authnConfig *authn.AuthnConfig, authzConfig *authz.AuthzConfig, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route { | ||
authn.AuthMapper[regexp.MustCompile(path)] = authnConfig | ||
authz.AuthMapper[regexp.MustCompile(path)] = authzConfig | ||
return p.engine.PUT(path, h, m...) | ||
} | ||
|
||
// Delete ... | ||
func (p *plus) Delete(path string, authnConfig *AuthnConfig, authzConfig *AuthzConfig, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route { | ||
AuthMapper[path] = AuthConfig{ | ||
AuthnConfig: authnConfig, | ||
AuthzConfig: authzConfig, | ||
} | ||
return p.Echo.DELETE(path, h, m...) | ||
func (p *plus) Delete(path string, authnConfig *authn.AuthnConfig, authzConfig *authz.AuthzConfig, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route { | ||
authn.AuthMapper[regexp.MustCompile(path)] = authnConfig | ||
authz.AuthMapper[regexp.MustCompile(path)] = authzConfig | ||
return p.engine.DELETE(path, h, m...) | ||
} | ||
|
||
// Patch ... | ||
func (p *plus) Patch(path string, authnConfig *AuthnConfig, authzConfig *AuthzConfig, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route { | ||
AuthMapper[path] = AuthConfig{ | ||
AuthnConfig: authnConfig, | ||
AuthzConfig: authzConfig, | ||
} | ||
return p.Echo.PATCH(path, h, m...) | ||
func (p *plus) Patch(path string, authnConfig *authn.AuthnConfig, authzConfig *authz.AuthzConfig, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route { | ||
authn.AuthMapper[regexp.MustCompile(path)] = authnConfig | ||
authz.AuthMapper[regexp.MustCompile(path)] = authzConfig | ||
return p.engine.PATCH(path, h, m...) | ||
} |