Skip to content

Commit f8d5811

Browse files
authored
Lrs 30 reaction version (#494)
* configurable reaction version * send supported version and reaction version to FE * update lrs-reactions to 2.0.0 compat version * reaction version dispatch * release version of lrs-admin-ui for xAPI 2.0.0
1 parent 02e0dbe commit f8d5811

File tree

10 files changed

+56
-34
lines changed

10 files changed

+56
-34
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Version of LRS Admin UI to use
44

5-
LRS_ADMIN_UI_VERSION ?= v0.2.5
5+
LRS_ADMIN_UI_VERSION ?= v0.2.6
66
LRS_ADMIN_UI_LOCATION ?= https://github.com/yetanalytics/lrs-admin-ui/releases/download/${LRS_ADMIN_UI_VERSION}/lrs-admin-ui.zip
77
LRS_ADMIN_ZIPFILE ?= lrs-admin-ui-${LRS_ADMIN_UI_VERSION}.zip
88

deps.edn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
:exclusions [org.clojure/clojure
7373
buddy/buddy-sign]}
7474
com.yetanalytics/lrs-reactions
75-
{:mvn/version "0.0.1"
75+
{:mvn/version "0.0.3"
7676
:exclusions [org.clojure/clojure]}
7777
com.yetanalytics/gen-openapi
7878
{:mvn/version "0.0.4"

doc/env_vars.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ The following options are used for advanced database performance tuning and may
110110
| `LRSQL_STMT_RETRY_BUDGET` | `stmtRetryBudget` | The max amount of time allowed for statement POST transaction retries before failing (ms). | `1000` |
111111
| `LRSQL_ENABLE_REACTIONS` | `enableReactions` | Whether or not to enable statement reactions. | `false` |
112112
| `LRSQL_REACTION_BUFFER_SIZE` | `reactionBufferSize` | Number of pending reactions to allow. Additional reactions will be dropped with a warning message. | `10000` |
113+
| `LRSQL_REACTION_VERSION` | `reactionVersion` | The xAPI version used when the reactor emits statements. Must be either `1.0.3` or `2.0.0`. | `1.0.3` |
113114
| `LRSQL_SUPPORTED_VERSIONS` | `supportedVersions` | A comma-separated list of supported LRS versions. This is used to validate incoming requests and ensure compatibility. | `1.0.3,2.0.0` |
114115
| `LRSQL_ENABLE_STRICT_VERSION` | `enableStrictVersion` | Whether or not to enable strict versioning. When enabled, GET requests for statements using a 1.0.3 header will convert 2.0.0 statements by removing or normalizing fields. | `false` |
115116

resources/lrsql/config/prod/default/lrs.edn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
:stmt-retry-budget #or [#env LRSQL_STMT_RETRY_BUDGET 1000]
1515
:enable-reactions #boolean #or [#env LRSQL_ENABLE_REACTIONS false]
1616
:reaction-buffer-size #long #or [#env LRSQL_REACTION_BUFFER_SIZE 10000]
17+
:reaction-version #or [#env LRSQL_REACTION_VERSION "1.0.3"]
1718
:supported-versions #or [#env LRSQL_SUPPORTED_VERSIONS "1.0.3,2.0.0"]
1819
:enable-strict-version #boolean #or [#env LRSQL_ENABLE_STRICT_VERSION false]}

resources/lrsql/config/test/default/lrs.edn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
:stmt-retry-budget 10000
1515
:enable-reactions true
1616
:reaction-buffer-size 10000
17+
:reaction-version "1.0.3"
1718
:supported-versions "1.0.3,2.0.0"
1819
:enable-strict-version false}

src/main/lrsql/admin/interceptors/reaction.clj

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
[lrsql.admin.protocol :as adp]
66
[lrsql.spec.reaction :as rs]
77
[lrsql.util.reaction :as ru]
8-
[lrsql.util :as u]))
8+
[lrsql.util :as u]
9+
[xapi-schema.spec :as xs]))
910

1011
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1112
;; Validation Interceptors
@@ -21,16 +22,19 @@
2122
(get-in ctx [:request :json-params])
2223
params (cond-> raw-params
2324
ruleset
24-
(update :ruleset ru/json->ruleset))]
25-
(if-some [err (s/explain-data rs/create-reaction-params-spec params)]
26-
;; Invalid parameters - Bad Request
27-
(assoc (chain/terminate ctx)
28-
:response
29-
{:status 400
30-
:body {:error (format "Invalid parameters:\n%s"
31-
(-> err s/explain-out with-out-str))}})
32-
;; Valid params - continue
33-
(assoc ctx ::data params))))}))
25+
(update :ruleset ru/json->ruleset))
26+
lrs (:com.yetanalytics/lrs ctx)
27+
xapi-version (get-in lrs [:config :reaction-version] "1.0.3")]
28+
(binding [xs/*xapi-version* xapi-version]
29+
(if-some [err (s/explain-data rs/create-reaction-params-spec params)]
30+
;; Invalid parameters - Bad Request
31+
(assoc (chain/terminate ctx)
32+
:response
33+
{:status 400
34+
:body {:error (format "Invalid parameters:\n%s"
35+
(-> err s/explain-out with-out-str))}})
36+
;; Valid params - continue
37+
(assoc ctx ::data params)))))}))
3438

3539
(def validate-update-reaction-params
3640
"Validate valid params for reaction update."
@@ -44,17 +48,20 @@
4448
ru/json->input
4549
(update :reaction-id u/str->uuid)
4650
(cond->
47-
ruleset
48-
(update :ruleset ru/json->ruleset)))]
49-
(if-some [err (s/explain-data rs/update-reaction-params-spec params)]
50-
;; Invalid parameters - Bad Request
51-
(assoc (chain/terminate ctx)
52-
:response
53-
{:status 400
54-
:body {:error (format "Invalid parameters:\n%s"
55-
(-> err s/explain-out with-out-str))}})
56-
;; Valid params - continue
57-
(assoc ctx ::data params))))}))
51+
ruleset
52+
(update :ruleset ru/json->ruleset)))
53+
lrs (:com.yetanalytics/lrs ctx)
54+
xapi-version (get-in lrs [:config :reaction-version] "1.0.3")]
55+
(binding [xs/*xapi-version* xapi-version]
56+
(if-some [err (s/explain-data rs/update-reaction-params-spec params)]
57+
;; Invalid parameters - Bad Request
58+
(assoc (chain/terminate ctx)
59+
:response
60+
{:status 400
61+
:body {:error (format "Invalid parameters:\n%s"
62+
(-> err s/explain-out with-out-str))}})
63+
;; Valid params - continue
64+
(assoc ctx ::data params)))))}))
5865

5966
(def validate-delete-reaction-params
6067
"Validate valid params for reaction delete."

src/main/lrsql/admin/interceptors/ui.clj

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
:enter
4747
(fn get-env [ctx]
4848
(let [{url-prefix ::i/path-prefix
49-
oidc-env ::oidc-i/admin-env} ctx]
49+
oidc-env ::oidc-i/admin-env
50+
lrs :com.yetanalytics/lrs} ctx]
5051
(assoc ctx
5152
:response
5253
{:status 200
@@ -63,7 +64,9 @@
6364
:admin-language-code admin-language-code
6465
:custom-language (custom-language-map)
6566
:stmt-get-max stmt-get-max
66-
:auth-by-cred-id auth-by-cred-id}
67+
:auth-by-cred-id auth-by-cred-id
68+
:supported-versions (:supported-versions lrs)
69+
:reaction-version (get-in lrs [:config :reaction-version])}
6770
(and no-val?
6871
(not-empty no-val-logout-url))
6972
(assoc :no-val-logout-url no-val-logout-url))

src/main/lrsql/spec/config.clj

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133

134134
(s/def ::enable-reactions boolean?)
135135
(s/def ::reaction-buffer-size pos-int?)
136+
(s/def ::reaction-version #{"1.0.3" "2.0.0"})
136137

137138
(s/def ::supported-versions
138139
(s/and
@@ -162,13 +163,19 @@
162163
::oidc-scope-prefix
163164
::enable-reactions
164165
::reaction-buffer-size
166+
::reaction-version
165167
::supported-versions
166168
::enable-strict-version]
167169
:opt-un [::admin-user-default
168170
::admin-pass-default
169171
::api-key-default
170172
::api-secret-default
171-
::stmt-get-max-csv])))
173+
::stmt-get-max-csv])
174+
(fn reaction-version-supported?
175+
[{:keys [reaction-version supported-versions]}]
176+
(let [supported-set (s/conform ::supported-versions supported-versions)]
177+
(and (not= ::s/invalid supported-set)
178+
(contains? supported-set reaction-version))))))
172179

173180
(s/def ::enable-http boolean?)
174181
(s/def ::enable-http2 boolean?)

src/main/lrsql/system/lrs.clj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@
7070
sup-versions :supported-versions}
7171
config
7272
;; Authority function
73-
auth-fn (make-authority-fn auth-tp)
74-
oidc-auth-fn (oidc-init/make-authority-fn oidc-auth-tp)]
73+
auth-fn (make-authority-fn auth-tp)
74+
oidc-auth-fn (oidc-init/make-authority-fn oidc-auth-tp)
75+
supported-version-set (s/conform ::cs/supported-versions
76+
sup-versions)]
7577
;; Combine all init ops into a single txn, since the user would expect
7678
;; such actions to happen as a single unit. If init-backend! succeeds
7779
;; but insert-default-creds! fails, this would constitute a partial
@@ -85,8 +87,7 @@
8587
:authority-fn auth-fn
8688
:oidc-authority-fn oidc-auth-fn
8789
:reaction-channel (react-init/reaction-channel config)
88-
:supported-versions (s/conform ::cs/supported-versions
89-
sup-versions)))))
90+
:supported-versions supported-version-set))))
9091
(stop
9192
[lrs]
9293
(log/info "Stopping LRS...")

src/main/lrsql/system/reactor.clj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,17 @@
4646
[]
4747
(:result
4848
(react-q/query-statement-reactions
49-
backend tx {:trigger-id statement-id}))))]
50-
;; Submit statements one at a time with varying authority
49+
backend tx {:trigger-id statement-id}))))
50+
reaction-version (get-in lrs [:config :reaction-version] "1.0.3")]
51+
;; Submit statements one at a time with varying authority
5152
{:statement-ids
5253
(reduce
5354
(fn [acc {:keys [statement authority]}]
5455
(into acc
5556
(:statement-ids
5657
(lrsp/-store-statements
5758
lrs
58-
{:com.yetanalytics.lrs/version "1.0.3"}
59+
{:com.yetanalytics.lrs/version reaction-version}
5960
{:agent authority
6061
:scopes #{:scope/statements.write}}
6162
[statement]

0 commit comments

Comments
 (0)