How stratoff/dynamic-permissions works
Project Type and Purpose
• The README indicates that this middleware adds dynamic permissions for KrakenD.
• Its purpose is to integrate with KrakenD by intercepting API requests, checking JWT payloads, and validating permissions dynamically.
• This isn’t a full-stack application but a standalone middleware component with examples to demonstrate its usage.
File Structure
• Core Files: Files like config.go, jwt.go, permissions.go, and gin.go indicate separation of concerns (configuration setup, JWT handling, permissions logic, and possibly integration with the Gin framework).
• Example Directory: Contains krakend.json and a sample main.go that illustrate how to integrate/configure the middleware with KrakenD.
• Test Files: jwt_test.go and permissions_test.go hint that these functionalities are modular and have corresponding unit tests.
• Go Modules: go.mod and go.sum show dependency management.
Main Components
a. Middleware Integration Component:
• This represents how the middleware sits in the KrakenD pipeline.
b. Configuration Component (config.go):
• Handles reading and managing configuration parameters.
c. JWT Handling Component (jwt.go):
• Parses and validates the JWT payload.
d. Permissions Evaluation Component (permissions.go):
• Implements the dynamic permissions logic based on the JWT contents.
• Role in deciding if access should be granted.
e. Optional Integration Module (gin.go):
• If the middleware supports integration with the Gin framework, show it as an adapter for this specific web framework.
f. Example Usage:
• Example folder showing a sample configuration (krakend.json) and a sample application runner (main.go) that demonstrates the middleware configuration and invocation.
Relationships and Interactions
• KrakenD routes the request through the middleware component.
• The middleware consults the configuration module to determine settings.
• The request’s JWT is passed to the JWT handling module to extract necessary information.
• The permissions module uses data from the JWT to evaluate dynamic permissions and issues an allow/deny decision.
• If applicable, show an alternative path where the Gin integration adapter manages similar functionality for Gin-based servers.
Architectural Patterns and Design Principles
• Separation of concerns by isolating configuration, authentication (JWT), and authorization (permissions).
• Use modular design principles: each Go file represents a discrete module with well-defined responsibilities.
• Extensibility through “Next Steps” noted in the README (e.g., flexible parsing, caching enhancements).
• That unit tests exist for JWT and permission functionalities, which can also be mentioned as “tested modules” in your design.