Skip to content

Commit 9551e65

Browse files
committed
Merge branch 'main' into LRS-30_xapi_2_0_0
2 parents 697a958 + 7472d41 commit 9551e65

File tree

3 files changed

+33
-21
lines changed

3 files changed

+33
-21
lines changed

doc/env_vars.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ _NOTE:_ `LRSQL_STMT_RETRY_LIMIT` and `LRSQL_STMT_RETRY_BUDGET` are used to mitig
129129
| `LRSQL_SSL_PORT` | `sslPort` | The HTTPS port that the webserver will be open on. | `8443` |
130130
| `LRSQL_URL_PREFIX` | `urlPrefix` | The prefix of the webserver URL path, e.g. the prefix in `http://0.0.0.0:8080/xapi` is `/xapi`. Used when constructing the `more` value for multi-statement queries. Cannot start with `/admin`. *(Note: Only applies to LRS xapi endpoints, not admin/ui endpoints)* | `/xapi` |
131131
| `LRSQL_PROXY_PATH` | `proxyPath` | This path modification is exclusively for use with a proxy, such as apache or nginx or a load balancer, where a path is added to prefix the entire application (such as `https://www.mysystem.com/mylrs/xapi/statements`). This does not actually change the routes of the application, it informs the admin frontend where to look for the server endpoints based on the proxied setup, and thus must be used in conjunction with a third party proxy. If used, the value must start with a leading `/` but not end with one (e.g. `/mylrs` is valid, as is `/mylrs/b` but `/mylrs/` is not). Use with caution. | Not Set |
132-
| `LRSQL_AUTH_BY_CRED_ID` | `authByCredId` | Allows a call to the xAPI endpoints to use the admin account credentials/authorization instead of a call with raw xAPI credentials. Necessary when the xAPI endpoint is behind additional security/SSO and cannot have custom credentials in Authorization header. | false |
132+
| `LRSQL_AUTH_BY_CRED_ID` | `authByCredId` | Allows a call to some xAPI endpoints (GET and POST) to use the admin account credentials/authorization instead of a call with raw xAPI credentials. Necessary when the xAPI endpoint is behind additional security/SSO and cannot have custom credentials in Authorization header. | false |
133133

134134
#### TLS/SSL Certificate
135135

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

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,29 @@
5656
true (conj v)))
5757
(empty coll) coll))
5858

59+
;; Paths which will also allow admin credentials override
60+
(def override-paths
61+
#{["statements" :get]
62+
["statements" :post]})
63+
5964
(defn add-credentials-override [routes validate-jwt oidc]
6065
(let [[decode validate _authorize ensure req] oidc
61-
[_ _ interceptors :as statements-route]
62-
(->> routes (some (fn [[path method :as r]]
63-
(when (= ["statements" :get]
64-
[(last (string/split path #"/")) method])
65-
r))))
6666
payload-interceptors (conj
6767
;;oidc interceptors, minus _authorize
6868
(filterv identity [decode
6969
validate
7070
ensure
7171
req])
72-
validate-jwt
72+
validate-jwt
7373
replace-auth)
74-
75-
new-interceptors (splice-before #(= (:name %) ::ai/lrs-authenticate)
76-
(check-for-credential-id payload-interceptors)
77-
interceptors)
78-
79-
new-route (assoc statements-route 2 new-interceptors)]
80-
(-> routes
81-
(disj statements-route)
82-
(conj new-route))))
74+
inject (fn [interceptors]
75+
(splice-before #(= (:name %) ::ai/lrs-authenticate)
76+
(check-for-credential-id payload-interceptors)
77+
interceptors))
78+
match? (fn [[path method & _]]
79+
(override-paths [(last (string/split path #"/")) method]))
80+
update-route (fn [r]
81+
(if (match? r)
82+
(update r 2 inject)
83+
r))]
84+
(into (empty routes) (map update-route routes))))

src/test/lrsql/admin/route_test.clj

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
[com.yetanalytics.lrs.protocol :as lrsp]
1010
[lrsql.backend.protocol :as bp]
1111
[lrsql.test-support :as support]
12-
[lrsql.lrs-test :as lt]
1312
[lrsql.test-constants :as tc]
1413
[lrsql.util :as u]
1514
[lrsql.util.headers :as h]
@@ -123,6 +122,13 @@
123122
{"Accept" "application/json"
124123
"X-Experience-API-Version" "1.0.3"})}))
125124

125+
(defn- post-statements-via-url-param [headers credential-id body]
126+
(curl/post (str "http://0.0.0.0:8080/xapi/statements?credentialID=" credential-id)
127+
{:headers (merge headers
128+
{"Accept" "application/json"
129+
"X-Experience-API-Version" "1.0.3"})
130+
:body body}))
131+
126132
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
127133
;; Tests
128134
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -678,7 +684,6 @@
678684
[:webserver :jwt-no-val-role] "/domain/app/ADMIN"
679685
[:webserver :auth-by-cred-id] true})
680686
sys' (component/start sys)
681-
lrs (:lrs sys')
682687
ds (get-in sys' [:lrs :connection :conn-pool])
683688
backend (:backend sys')
684689
;; proxy jwt auth
@@ -720,9 +725,14 @@
720725
(jdbc/with-transaction [tx ds]
721726
(bp/-query-credential-ids backend tx {:api-key api-key
722727
:secret-key secret-key}))
723-
724-
_ (lrsp/-store-statements lrs tc/ctx auth-ident [lt/stmt-0] [])
725-
{:keys [status body]} (get-statements-via-url-param headers credential-id)]
728+
stmt-body
729+
(u/write-json-str
730+
(assoc stmt-0 :id "00000000-0000-4000-8000-000000000007"))
731+
post-resp
732+
(post-statements-via-url-param headers credential-id stmt-body)
733+
{:keys [status body]}
734+
(get-statements-via-url-param headers credential-id)]
735+
(is (= (:status post-resp) 200))
726736
(is (= status 200))
727737
(is (seq ((u/parse-json body) "statements")))))
728738

0 commit comments

Comments
 (0)