Skip to content

Commit

Permalink
Check for valid keys and update datastore (#198)
Browse files Browse the repository at this point in the history
fixes #194
  • Loading branch information
ostcar committed Apr 26, 2021
1 parent 4defc18 commit 2bc8827
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 139 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ curl -N localhost:9012/system/autoupdate -d '
]'
```

## Configuration

### Environment variables

The Service uses the following environment variables:
Expand Down
13 changes: 13 additions & 0 deletions cmd/datastore/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log"
"net/http"
"os"
"regexp"
"strings"
"time"

Expand Down Expand Up @@ -78,6 +79,10 @@ func exampleHandler(w http.ResponseWriter, r *http.Request) {

responceData := make(map[string]map[string]map[string]json.RawMessage)
for _, key := range data.Keys {
if !validKey(key) {
http.Error(w, "Key is invalid: "+key, 400)
}

value, ok := models.ExampleData[key]

if !ok {
Expand All @@ -98,3 +103,11 @@ func exampleHandler(w http.ResponseWriter, r *http.Request) {

json.NewEncoder(w).Encode(responceData)
}

func validKey(key string) bool {
match, err := regexp.MatchString(`^([a-z]+|[a-z][a-z_]*[a-z])/[1-9][0-9]*/[a-z][a-z0-9_]*\$?[a-z0-9_]*$`, key)
if err != nil {
panic(err)
}
return match
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.16

require (
github.com/OpenSlides/openslides-models-to-go v0.3.1-0.20210328145126-7822f69c1663
github.com/OpenSlides/openslides-permission-service v0.0.0-20210326165411-d3cb6d504f51
github.com/OpenSlides/openslides-permission-service v0.0.0-20210422132938-c40703f752e7
github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1
github.com/gomodule/redigo v1.8.4
github.com/ostcar/topic v0.3.4-0.20200613094955-61bb28837a98
Expand Down
5 changes: 5 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ github.com/OpenSlides/openslides-models-to-go v0.3.1-0.20210328145126-7822f69c16
github.com/OpenSlides/openslides-models-to-go v0.3.1-0.20210328145126-7822f69c1663/go.mod h1:CriCefW5smTixhFfVLiuA8NgyMX4PAU5e3YpJHnaZx8=
github.com/OpenSlides/openslides-permission-service v0.0.0-20210326165411-d3cb6d504f51 h1:jCWiTbw/XRyYXYGdaqGcF7212Z1Ekhq6pD/8qqwk/Ac=
github.com/OpenSlides/openslides-permission-service v0.0.0-20210326165411-d3cb6d504f51/go.mod h1:5IL8lKaUSdk54Wp2YRjNMKGKPIgJXiDep6yO+NB7YQw=
github.com/OpenSlides/openslides-permission-service v0.0.0-20210415165713-26f9fece39bf h1:+6fNRq8eEOYai/hKSG6h0nKQ9QPchAijVGuW202IBL8=
github.com/OpenSlides/openslides-permission-service v0.0.0-20210415165713-26f9fece39bf/go.mod h1:5IL8lKaUSdk54Wp2YRjNMKGKPIgJXiDep6yO+NB7YQw=
github.com/OpenSlides/openslides-permission-service v0.0.0-20210422132938-c40703f752e7 h1:dxA5XFeSI5/JVeUw098XOJuk4aNbzF3ntVQMbXGG710=
github.com/OpenSlides/openslides-permission-service v0.0.0-20210422132938-c40703f752e7/go.mod h1:5IL8lKaUSdk54Wp2YRjNMKGKPIgJXiDep6yO+NB7YQw=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go/v4 v4.0.0-preview1 h1:CaO/zOnF8VvUfEbhRatPcwKVWamvbYd8tQGRWacE9kU=
Expand All @@ -13,6 +17,7 @@ github.com/ostcar/topic v0.3.4-0.20200613094955-61bb28837a98 h1:F/nJ78OVR6ELrcXF
github.com/ostcar/topic v0.3.4-0.20200613094955-61bb28837a98/go.mod h1:61PcAdinfpVwmQTjP2W0rZoEJqnKku7zvGS9Ag4Si18=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
Expand Down
Loading

0 comments on commit 2bc8827

Please sign in to comment.