Browse Source

Home prefix filtering.

Frederic G. MARAND 1 year ago
parent
commit
5a2c03fbdf
5 changed files with 12 additions and 7 deletions
  1. 1 1
      .run/Redriver.run.xml
  2. 3 0
      back/services/services.go
  3. 3 2
      back/web/home.go
  4. 4 3
      back/web/routes.go
  5. 1 1
      front/templates/home.gohtml

+ 1 - 1
.run/Redriver.run.xml

@@ -2,7 +2,7 @@
   <configuration default="false" name="Redriver" type="GoApplicationRunConfiguration" factoryName="Go Application">
     <module name="sqs_demo" />
     <working_directory value="$PROJECT_DIR$" />
-    <parameters value="-profile=sqs-tutorial -addr :81 -wait 3" />
+    <parameters value="-profile=sqs-tutorial -addr :81 -wait 3 -prefix test" />
     <EXTENSION ID="net.ashald.envfile">
       <option name="IS_ENABLED" value="false" />
       <option name="IS_SUBST" value="false" />

+ 3 - 0
back/services/services.go

@@ -13,6 +13,7 @@ import (
 const (
 	// Flags
 	PAddr        = "addr"
+	PPrefix      = "prefix"
 	PProfile     = "profile"
 	PQName       = "queue-name"
 	PRegion      = "region"
@@ -50,6 +51,7 @@ func FlagsService(dic *izidic.Container) (any, error) {
 	region := fs.String(PRegion, "eu-west-3", "The AWS region to connect to")
 	qName := fs.String(PQName, "dummy-queue", "The queue name")
 	csrfSecret := fs.String(PCSRFSecret, "csrfSecret", "The CSRF secret")
+	prefix := fs.String(PPrefix, "", "The queue prefix to filter the main list")
 	storeSecret := fs.String(PStoreSecret, "storeSecret", "The session store secret")
 	sqsURL := fs.String(PURL, "http://localhost:4566", "The SQS endpoint URL")
 	ttl := fs.Duration(PTTL, 10*time.Minute, "The message store TTL")
@@ -67,6 +69,7 @@ func FlagsService(dic *izidic.Container) (any, error) {
 	dic.Store(PQName, *qName)
 	dic.Store(PRegion, *region)
 	dic.Store(PCSRFSecret, []byte(*csrfSecret))
+	dic.Store(PPrefix, *prefix)
 	dic.Store(PStoreSecret, []byte(*storeSecret))
 	dic.Store(PTTL, *ttl)
 	dic.Store(PURL, *sqsURL)

+ 3 - 2
back/web/home.go

@@ -91,7 +91,7 @@ type queueCell struct {
 
 type QueueRow [2]queueCell
 
-func makeHomeHandler(rd redriver.Redriver) gin.HandlerFunc {
+func makeHomeHandler(rd redriver.Redriver, prefix string) gin.HandlerFunc {
 	return func(c *gin.Context) {
 		ctx := c.Request.Context()
 		sess := sessions.Default(c)
@@ -99,7 +99,7 @@ func makeHomeHandler(rd redriver.Redriver) gin.HandlerFunc {
 		defer func() { _ = sess.Save() }()
 
 		t0 := time.Now()
-		qURLs, err := rd.ListQueues(ctx, "")
+		qURLs, err := rd.ListQueues(ctx, prefix)
 		latency := time.Since(t0)
 		if err != nil {
 			log.Printf("failed listing queues: %v", err)
@@ -138,6 +138,7 @@ func makeHomeHandler(rd redriver.Redriver) gin.HandlerFunc {
 		c.HTML(http.StatusOK, "home", gin.H{
 			"flashes": flashes,
 			"latency": latency,
+			"prefix":  prefix,
 			"rows":    rows,
 		})
 

+ 4 - 3
back/web/routes.go

@@ -21,7 +21,7 @@ import (
 	"code.osinet.fr/fgm/sqs_demo/front"
 )
 
-func SetupRoutes(rd redriver.Redriver, ms redriver.MessageStore, renderer *template.Template, storeSecret, csrfSecret []byte) *gin.Engine {
+func SetupRoutes(rd redriver.Redriver, ms redriver.MessageStore, renderer *template.Template, storeSecret, csrfSecret []byte, prefix string) *gin.Engine {
 	const assetsPrefix = "/assets/"
 	r := gin.Default()
 	r.SetHTMLTemplate(renderer)
@@ -46,7 +46,7 @@ func SetupRoutes(rd redriver.Redriver, ms redriver.MessageStore, renderer *templ
 	r.GET("/queue/:name", makeQueueHandler(rd, ms))
 
 	// JSON done
-	r.GET("/", makeHomeHandler(rd))
+	r.GET("/", makeHomeHandler(rd, prefix))
 
 	// TODO
 	r.POST("/queue/:name/delete", mw, makeDeleteHandler(rd))       // Needs mw to check token.
@@ -57,13 +57,14 @@ func SetupRoutes(rd redriver.Redriver, ms redriver.MessageStore, renderer *templ
 
 func HttpService(dic *izidic.Container) (any, error) {
 	csrfSecret := dic.MustParam(services.PCSRFSecret).([]byte)
+	prefix := dic.MustParam(services.PPrefix).(string)
 	storeSecret := dic.MustParam(services.PStoreSecret).([]byte)
 
 	rd := dic.MustService(services.SvcRedriver).(redriver.Redriver)
 	re := dic.MustService(services.SvcRenderer).(*template.Template)
 	ms := dic.MustService(services.SvcMessageStore).(redriver.MessageStore)
 
-	return SetupRoutes(rd, ms, re, storeSecret, csrfSecret), nil
+	return SetupRoutes(rd, ms, re, storeSecret, csrfSecret, prefix), nil
 }
 
 func RendererService(_ *izidic.Container) (any, error) {

+ 1 - 1
front/templates/home.gohtml

@@ -73,7 +73,7 @@
                 {{ end }}
             </ul>
             {{ if index .Links 2 }}
-                <p class="lead">Allowed source queues not declaring a DLQ</p>
+                <p class="lead">Allowed source queues not declaring a DLQ or with another prefix</p>
             {{ end}}
             <ul>
                 {{ range index .Links 2 }}