JM-Lemmi / ical-relay

Relay ical urls and edit them on the fly with different modules.
GNU Affero General Public License v3.0
9 stars 2 forks source link

Multiple filters are not loaded in the config struct #237

Closed frereit closed 9 months ago

frereit commented 9 months ago

This might be a user error but I am trying to create a simple profile with a single rule with multiple filters:

        rules:
            - filters:
                - type: "regex"
                  regex: "testentry"
                  target: "summary"
                - type: "regex"
                  regex: "testentry2"
                  target: "description"
              action:
                type: "delete"
              expires: "2022-12-31T00:00:00Z"

I added the following debug logging to the calendarViewHandler in handlers.go L192:

    // Log out all rules
    for i, rule := range profile.Rules {
        log.Debug("Rule ", i)
        for j, filter := range rule.Filters {
            log.Debug("Filter ", j, filter)
        }
        log.Debug("Action ", rule.Action)
    }

Starting the server and accessing the calender gives the following log:

DEBU[0003] Rule 0                                       
DEBU[0003] Filter 0 map[regex:testentry target:summary type:regex] 
DEBU[0003] Action map[type:delete]

It seems like only the first filter was loaded into the Rules struct? I started the binary with a clean database and ran ./relay --import-data.

JM-Lemmi commented 9 months ago

Yes, I can reproduce this bug. The existing Trace logs also show this issue, both for the config and for the dbRule.

time="2024-02-13T12:46:01Z" level=info msg="calendar view request" client="172.18.0.1:38090" profile=TINF21CS1
time="2024-02-13T12:46:01Z" level=debug msg="Exec'dSELECT EXISTS (SELECT * FROM profile WHERE name = TINF21CS1)"
time="2024-02-13T12:46:01Z" level=trace msg="true\n"
time="2024-02-13T12:46:01Z" level=trace msg="[]main.dbRule{main.dbRule{Id:1, Operator:\"\", ActionType:\"delete\", ActionParameters:\"{}\", Expiry:<nil>}}\n"
time="2024-02-13T12:46:01Z" level=trace msg="[]main.Rule{main.Rule{Filters:[]map[string]string{map[string]string{\"regex\":\"testentry\", \"target\":\"summary\", \"type\":\"regex\"}}, Operator:\"\", Action:map[string]string{\"type\":\"delete\"}, Expiry:\"\"}}\n"

In the initial unmarshal of the config file, its seems to be represented correctly:

Rules:[
        {Filters:[map[regex:testentry target:summary type:regex]
                  map[regex:testentry2 target:description type:regex]
      ]
      Operator: Action:map[type:delete] Expiry:}]}

Maybe the import to the db is faulty? It does seem to throw an error

time="2024-02-13T12:45:30Z" level=debug msg="Connecting to db using postgresql://dbuser:password@postgres/ical_relay?sslmode=disable"
time="2024-02-13T12:45:30Z" level=debug msg="Connected to db"
time="2024-02-13T12:45:30Z" level=info msg="Initially creating tables..."
time="2024-02-13T12:45:30Z" level=info msg="DB is now at version 4"
time="2024-02-13T12:45:30Z" level=trace msg="sqlx.DB{DB:(*sql.DB)(0xc00007f380), driverName:\"postgres\", unsafe:false, Mapper:(*reflectx.Mapper)(0xc000025f50)}"
time="2024-02-13T12:45:30Z" level=debug msg="Importing profile TINF21CS1"
time="2024-02-13T12:45:30Z" level=trace msg="rule not found with pN:'TINF21CS1' rOp:' 'aT:'delete' aP:{} rE:''"
time="2024-02-13T12:45:30Z" level=debug msg="Adding rule delete"
JM-Lemmi commented 9 months ago

@robske110 do you have an idea where this could come from?

The import code looks fine to me.

https://github.com/JM-Lemmi/ical-relay/blob/e9a3d5ba8b7e2591a610d4dc970d47fcb649f639/cmd/ical-relay/database.go#L337-L366

JM-Lemmi commented 9 months ago

issue also persists in #230 and #235 branches

JM-Lemmi commented 9 months ago

Das scheint schon in der Datenbank anzukommen und auch der regel zugeordnet zu sein

image