The Autoupdate Service is part of the OpenSlides environment. It is a http endpoint where the clients can connect to get the actual data and also get updates, when the requested data changes.
IMPORTANT: The data are sent via an open http-connection. All browsers limit the amount of open http1.1 connections to a domain. For this service to work, the browser has to connect to the service with http2 and therefore needs https.
go build ./cmd/autoupdate
./autoupdate
The docker build uses the redis messaging service, the auth token and the real datastore service as default. Either configure it to use the fake services (see environment variables below) or make sure the service inside the docker container can connect to redis and the datastore-reader. For example with the docker argument --network host. The auth-secrets have to given as a file.
docker build . --tag openslides-autoupdate
printf "my_token_key" > auth_token_key
printf "my_cookie_key" > auth_cookie_key
docker run --network host -v $PWD/auth_token_key:/run/secrets/auth_token_key -v $PWD/auth_cookie_key:/run/secrets/auth_cookie_key openslides-autoupdate
It uses the host network to connect to redis.
To restart the service when ever a source file has shanged, the tool CompileDaemon can help.
go install github.com/githubnemo/CompileDaemon@latest
CompileDaemon -log-prefix=false -build "go build ./cmd/autoupdate" -command "./autoupdate"
The make target build-dev
creates a docker image that uses this tool. The
environment varialbe OPENSLIDES_DEVELOPMENT
is used to use default auth keys.
make build-dev
docker run --network host --env OPENSLIDES_DEVELOPMENT=true openslides-autoupdate-dev
go test ./...
There is a make target, that creates and runs the docker-test-container:
make run-tests
Curl needs the flag -N / --no-buffer
or it can happen, that the output is not
printed immediately.
When the server is started, clients can listen for keys to do so, they have to send a keyrequest in the body of the request. An example request is:
curl -N localhost:9012/system/autoupdate -d '[{"ids": [1], "collection": "user", "fields": {"username": null}}]'
To see a list of possible json-strings see the file internal/autoupdate/keysbuilder/keysbuilder_test.go
There is a simpler method to request keys:
curl -N localhost:9012/system/autoupdate/keys?user/1/username,user/2/username
With this simpler method, it is not possible to request related keys.
After the request is send, the values to the keys are returned as a json-object without a newline:
{"user/1/name":"value","user/2/name":"value"}
When redis is installed, it can be used to update keys. Start the autoupdate
service with the envirnmentvariable MESSAGING_SERVICE=redis
. Afterwards it is
possible to update keys by sending the following command to redis:
xadd field_changed * updated user/1/username updated user/1/password
The data for a projector can be accessed with autoupdate requests. For example use:
curl -N localhost:9012/system/autoupdate -d '
[
{
"ids": [1],
"collection": "projector",
"fields": {
"current_projection_ids": {
"type": "relation-list",
"collection": "projection",
"fields": {
"content": null,
"content_object_id": null,
"stable": null,
"type": null,
"options": null
}
}
}
}
]'
The Service uses the following environment variables:
AUTOUPDATE_PORT
: Lets the service listen on port 9012. The default is9012
.AUTOUPDATE_HOST
: The device where the service starts. The default is am empty string which starts the service on any device.DATASTORE_READER_HOST
: Host of the datastore reader. The default islocalhost
.DATASTORE_READER_PORT
: Port of the datastore reader. The default is9010
.DATASTORE_READER_PROTOCOL
: Protocol of the datastore reader. The default ishttp
.MESSAGING
: Sets the type of messaging service.fake
(default) orredis
.MESSAGE_BUS_HOST
: Host of the redis server. The default islocalhost
.MESSAGE_BUS_PORT
: Port of the redis server. The default is6379
.REDIS_TEST_CONN
: Test the redis connection on startup. Disable on the cloud if redis needs more time to start then this service. The default istrue
.AUTH
: Sets the type of the auth service.fake
(default) orticket
.AUTH_HOST
: Host of the auth service. The default islocalhost
.AUTH_PORT
: Port of the auth service. The default is9004
.AUTH_PROTOCOL
: Protocol of the auth servicer. The default ishttp
.DEACTIVATE_PERMISSION
: Deactivate requests to the permission service. The result is, that every user can see everything. The default isfalse
.OPENSLIDES_DEVELOPMENT
: If set, the service starts, even when secrets (see below) are not given. The default isfalse
.
Secrets are filenames in /run/secrets/
. The service only starts if it can find
each secret file and read its content. The default values are only used, if the
environment variable OPENSLIDES_DEVELOPMENT
is set.
auth_token_key
: Key to sign the JWT auth tocken. Defaultauth-dev-key
.auth_cookie_key
: Key to sign the JWT auth cookie. Defaultauth-dev-key
.