Claude-assisted improvements (untested)
- dev auth flow (side-step OAuth) - db event processing integration tests - dev scripts (eg Makefile) - db / test db migration setup scripts.
This commit is contained in:
@@ -27,11 +27,13 @@ func Routes(
|
||||
unp *sse.UpdateNotificationPublisher,
|
||||
rawEvents *raw_events.Store,
|
||||
etsy *etsy_platform.Platform,
|
||||
devAuthEnabled bool,
|
||||
) {
|
||||
auth_api.Routes(
|
||||
r.Group("/auth"),
|
||||
logger.WithGroup("/auth"),
|
||||
auth.GetAuthenticator(),
|
||||
devAuthEnabled,
|
||||
)
|
||||
sse_api.Routes(
|
||||
r.Group("/events", auth.Authenticate()),
|
||||
|
||||
@@ -21,6 +21,7 @@ func Routes(
|
||||
r *gin.RouterGroup,
|
||||
logger *logging.Logger,
|
||||
auth *authentication.Authenticator,
|
||||
devAuthEnabled bool,
|
||||
) {
|
||||
ls := &loginSubrouter{
|
||||
log: logger,
|
||||
@@ -30,6 +31,11 @@ func Routes(
|
||||
r.GET("/login", response.Handler(ls.loginPage))
|
||||
r.GET("/login/callback", response.Handler(ls.loginCallback))
|
||||
r.GET("/logout", response.Handler(ls.logoutPage))
|
||||
|
||||
if devAuthEnabled {
|
||||
logger.Warn("DEV_AUTH_ENABLED is set: /api/auth/dev-login is live and lets any caller authenticate as any user_id with no credentials. Never enable this outside local development.")
|
||||
r.GET("/dev-login", response.Handler(ls.devLoginPage))
|
||||
}
|
||||
}
|
||||
|
||||
func (s *loginSubrouter) loginPage(c *gin.Context) (response.Response, error) {
|
||||
@@ -75,6 +81,43 @@ func (s *loginSubrouter) loginCallback(c *gin.Context) (response.Response, error
|
||||
Cookie(cookies.AccessToken(accessToken, expiration)), nil
|
||||
}
|
||||
|
||||
// devLoginPage mints a local session for a user_id, skipping the real Auth0
|
||||
// OAuth round-trip. Only registered when devAuthEnabled is passed to Routes.
|
||||
//
|
||||
// Query params:
|
||||
// - user_id: identity to log in as (default "dev-user"); use different
|
||||
// values to test multiple accounts side by side.
|
||||
// - name: display name for the identity (default derived from user_id).
|
||||
// - target: where to redirect after login (default "/").
|
||||
func (s *loginSubrouter) devLoginPage(c *gin.Context) (response.Response, error) {
|
||||
r := c.Request
|
||||
ctx := r.Context()
|
||||
q := r.URL.Query()
|
||||
|
||||
userID := q.Get("user_id")
|
||||
if userID == "" {
|
||||
userID = "dev-user"
|
||||
}
|
||||
|
||||
name := q.Get("name")
|
||||
if name == "" {
|
||||
name = "Dev User (" + userID + ")"
|
||||
}
|
||||
|
||||
targetURI := q.Get("target")
|
||||
if targetURI == "" {
|
||||
targetURI = "/"
|
||||
}
|
||||
|
||||
accessToken, expiration, err := s.auth.DevLogin(ctx, userID, name)
|
||||
if err != nil {
|
||||
return nil, response.Errorf("failed to create dev session: %w", err)
|
||||
}
|
||||
|
||||
return response.TemporaryRedirect(targetURI).
|
||||
Cookie(cookies.AccessToken(accessToken, expiration)), nil
|
||||
}
|
||||
|
||||
func (s *loginSubrouter) logoutPage(c *gin.Context) (response.Response, error) {
|
||||
r := c.Request
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ func NewRouter(
|
||||
reps *reports.Store,
|
||||
etsy *etsy_platform.Platform,
|
||||
authr *authentication.Authenticator,
|
||||
devAuthEnabled bool,
|
||||
) *Router {
|
||||
authM := auth.NewService(
|
||||
logger.WithGroup("auth-middleware"),
|
||||
@@ -99,6 +100,7 @@ func NewRouter(
|
||||
unp,
|
||||
rawEvents,
|
||||
etsy,
|
||||
devAuthEnabled,
|
||||
)
|
||||
|
||||
return &Router{
|
||||
|
||||
@@ -137,8 +137,6 @@ func (p *UpdateNotificationPublisher) Push(ctx context.Context, acctID int64, ev
|
||||
wg.Wait()
|
||||
|
||||
return errors.Join(errs...)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getPathSegments(p string) []string {
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1 @@
|
||||
<html><body><svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="100" height="100" style="background: pink" viewBox="0 0 100 100" preserveAspectRatio="none"><g transform="translate(5 5) scale(0.9 0.9) scale(1 -1) translate(0 -100)"><polyline points="0,2.5 20,5 40,10 60,20 80,40 100,80" stroke-width="2px" vector-effect="non-scaling-stroke" stroke="purple" fill="none"/><ellipse cx="0" cy="2.5" rx="0.16666666666666666%" ry="0.16666666666666666%" stroke="purple" stroke-width="2px" vector-effect="non-scaling-stroke" fill="pink"/><text text-anchor="middle" dominant-baseline="middle" x="0" y="2.5" transform="translate(0 2.5) scale(1 -1) translate(-0 -2.5)" font-size="5px"></text><ellipse cx="20" cy="5" rx="0.16666666666666666%" ry="0.16666666666666666%" stroke="purple" stroke-width="2px" vector-effect="non-scaling-stroke" fill="pink"/><text text-anchor="middle" dominant-baseline="middle" x="20" y="5" transform="translate(20 5) scale(1 -1) translate(-20 -5)" font-size="5px"></text><ellipse cx="40" cy="10" rx="0.16666666666666666%" ry="0.16666666666666666%" stroke="purple" stroke-width="2px" vector-effect="non-scaling-stroke" fill="pink"/><text text-anchor="middle" dominant-baseline="middle" x="40" y="10" transform="translate(40 10) scale(1 -1) translate(-40 -10)" font-size="5px"></text><ellipse cx="60" cy="20" rx="0.16666666666666666%" ry="0.16666666666666666%" stroke="purple" stroke-width="2px" vector-effect="non-scaling-stroke" fill="pink"/><text text-anchor="middle" dominant-baseline="middle" x="60" y="20" transform="translate(60 20) scale(1 -1) translate(-60 -20)" font-size="5px"></text><ellipse cx="80" cy="40" rx="0.16666666666666666%" ry="0.16666666666666666%" stroke="purple" stroke-width="2px" vector-effect="non-scaling-stroke" fill="pink"/><text text-anchor="middle" dominant-baseline="middle" x="80" y="40" transform="translate(80 40) scale(1 -1) translate(-80 -40)" font-size="5px"></text><ellipse cx="100" cy="80" rx="0.16666666666666666%" ry="0.16666666666666666%" stroke="purple" stroke-width="2px" vector-effect="non-scaling-stroke" fill="pink"/><text text-anchor="middle" dominant-baseline="middle" x="100" y="80" transform="translate(100 80) scale(1 -1) translate(-100 -80)" font-size="5px"></text></g></svg></body></html>
|
||||
@@ -36,5 +36,5 @@ func ExampleLineChart() {
|
||||
output := []byte(`<html><body>` + c + `</body></html>`)
|
||||
os.WriteFile("./line_chart.html", []byte(output), 0666)
|
||||
fmt.Println(c)
|
||||
// Output: <svg version="1.1" xmlns="http://www.w3.org/2000/svg" style="height: auto; width: 100%" viewBox="0 0 100 100"></svg>
|
||||
// Output: <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="100" height="100" style="background: pink" viewBox="0 0 100 100" preserveAspectRatio="none"><g transform="translate(5 5) scale(0.9 0.9) scale(1 -1) translate(0 -100)"><polyline points="0,2.5 20,5 40,10 60,20 80,40 100,80" stroke-width="2px" vector-effect="non-scaling-stroke" stroke="purple" fill="none"/><ellipse cx="0" cy="2.5" rx="0.16666666666666666%" ry="0.16666666666666666%" stroke="purple" stroke-width="2px" vector-effect="non-scaling-stroke" fill="pink"/><text text-anchor="middle" dominant-baseline="middle" x="0" y="2.5" transform="translate(0 2.5) scale(1 -1) translate(-0 -2.5)" font-size="5px"></text><ellipse cx="20" cy="5" rx="0.16666666666666666%" ry="0.16666666666666666%" stroke="purple" stroke-width="2px" vector-effect="non-scaling-stroke" fill="pink"/><text text-anchor="middle" dominant-baseline="middle" x="20" y="5" transform="translate(20 5) scale(1 -1) translate(-20 -5)" font-size="5px"></text><ellipse cx="40" cy="10" rx="0.16666666666666666%" ry="0.16666666666666666%" stroke="purple" stroke-width="2px" vector-effect="non-scaling-stroke" fill="pink"/><text text-anchor="middle" dominant-baseline="middle" x="40" y="10" transform="translate(40 10) scale(1 -1) translate(-40 -10)" font-size="5px"></text><ellipse cx="60" cy="20" rx="0.16666666666666666%" ry="0.16666666666666666%" stroke="purple" stroke-width="2px" vector-effect="non-scaling-stroke" fill="pink"/><text text-anchor="middle" dominant-baseline="middle" x="60" y="20" transform="translate(60 20) scale(1 -1) translate(-60 -20)" font-size="5px"></text><ellipse cx="80" cy="40" rx="0.16666666666666666%" ry="0.16666666666666666%" stroke="purple" stroke-width="2px" vector-effect="non-scaling-stroke" fill="pink"/><text text-anchor="middle" dominant-baseline="middle" x="80" y="40" transform="translate(80 40) scale(1 -1) translate(-80 -40)" font-size="5px"></text><ellipse cx="100" cy="80" rx="0.16666666666666666%" ry="0.16666666666666666%" stroke="purple" stroke-width="2px" vector-effect="non-scaling-stroke" fill="pink"/><text text-anchor="middle" dominant-baseline="middle" x="100" y="80" transform="translate(100 80) scale(1 -1) translate(-100 -80)" font-size="5px"></text></g></svg>
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 7.1 KiB |
Reference in New Issue
Block a user