Skip to content

Commit

Permalink
Changed input format of the dummy datastore (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
ostcar committed Oct 13, 2020
1 parent 6bf27c5 commit 12af349
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
21 changes: 19 additions & 2 deletions cmd/datastore/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
# ExampleDatastore

Datastore server that serves the example data.
Development Datastore server that serves the example data.

Also listens on stdin for changed data.
This tool can be used as dropin replacement for the
openslides-datastore-service. The autoupdate-service can connect to it, like to
the real datastore-service. It uses the example data.

It listens to stdin for changed data. Changed data has to be given as a
json-object. For example:

```
{"topic/10/meeting_id": 1, "topic/10/title": "ZZ", "topic/10/text": ""}
```

Changed data is sent to the autoupdate-service via redis.

To connect the autoupdate-service to this service, use

```
DATASTORE=service MESSAGING=redis ./autoupdate
```
21 changes: 11 additions & 10 deletions cmd/datastore/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,22 @@ func updater(r io.Reader) {

scanner := bufio.NewScanner(r)
for scanner.Scan() {
input := strings.Split(strings.TrimSpace(scanner.Text()), " ")
args := []interface{}{redisKey, "*"}
for _, d := range input {
keyValue := strings.SplitN(d, "=", 2)
if len(keyValue) != 2 {
continue
}
args = append(args, keyValue[0], keyValue[1])
exampleData[keyValue[0]] = []byte(keyValue[1])
if len(scanner.Text()) == 0 {
continue
}

if len(args) == 2 {
var data map[string]json.RawMessage
if err := json.Unmarshal(scanner.Bytes(), &data); err != nil {
log.Printf("Invalid json input: %v", err)
continue
}

args := []interface{}{redisKey, "*"}
for key, value := range data {
args = append(args, key, string(value))
exampleData[key] = value
}

if _, err := conn.Do("XADD", args...); err != nil {
log.Fatalf("Can not send command to redis: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/restrict/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type relationList struct {
func (r *relationList) Check(uid int, key string, value json.RawMessage) (json.RawMessage, error) {
var ids []int
if err := json.Unmarshal(value, &ids); err != nil {
return nil, fmt.Errorf("decoding %s: %w", key, err)
return nil, fmt.Errorf("decoding %s=%s: %w", key, value, err)
}

keys := make([]string, len(ids))
Expand Down

0 comments on commit 12af349

Please sign in to comment.