📎 Adapt nitrate module to auth changes

This commit is contained in:
Andrey Antukh 2026-01-27 10:16:16 +01:00
parent f5996a7235
commit 50a4cf8b99
2 changed files with 15 additions and 31 deletions

View File

@ -340,7 +340,8 @@
::email/whitelist (ig/ref ::email/whitelist)} ::email/whitelist (ig/ref ::email/whitelist)}
:app.nitrate/client :app.nitrate/client
{::http.client/client (ig/ref ::http.client/client)} {::http.client/client (ig/ref ::http.client/client)
::setup/shared-keys (ig/ref ::setup/shared-keys)}
:app.rpc/management-methods :app.rpc/management-methods
{::http.client/client (ig/ref ::http.client/client) {::http.client/client (ig/ref ::http.client/client)

View File

@ -1,9 +1,3 @@
;; This Source Code Form is subject to the terms of the Mozilla Public
;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) KALEIDOS INC
(ns app.nitrate (ns app.nitrate
"Module that make calls to the external nitrate aplication" "Module that make calls to the external nitrate aplication"
(:require (:require
@ -17,18 +11,17 @@
[clojure.core :as c] [clojure.core :as c]
[integrant.core :as ig])) [integrant.core :as ig]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; HELPERS ;; HELPERS
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn- request-builder (defn- request-builder
[cfg method uri management-key profile-id] [cfg method uri shared-key profile-id]
(fn [] (fn []
(http/req! cfg {:method method (http/req! cfg {:method method
:headers {"content-type" "application/json" :headers {"content-type" "application/json"
"accept" "application/json" "accept" "application/json"
"x-shared-key" management-key "x-shared-key" shared-key
"x-profile-id" (str profile-id)} "x-profile-id" (str profile-id)}
:uri uri :uri uri
:version :http1.1}))) :version :http1.1})))
@ -54,9 +47,9 @@
(defn- with-validate [handler uri schema] (defn- with-validate [handler uri schema]
(fn [] (fn []
(let [coercer-http (sm/coercer schema (let [coercer-http (sm/coercer schema
:type :validation :type :validation
:hint (str "invalid data received calling " uri))] :hint (str "invalid data received calling " uri))]
(try (try
(coercer-http (-> (handler) :body json/decode)) (coercer-http (-> (handler) :body json/decode))
(catch Exception e (catch Exception e
@ -65,8 +58,9 @@
nil))))) nil)))))
(defn- request-to-nitrate (defn- request-to-nitrate
[{:keys [::management-key] :as cfg} method uri schema {:keys [::rpc/profile-id] :as params}] [cfg method uri schema {:keys [::rpc/profile-id] :as params}]
(let [full-http-call (-> (request-builder cfg method uri management-key profile-id) (let [shared-key (-> cfg ::setup/shared-keys :nitrate)
full-http-call (-> (request-builder cfg method uri shared-key profile-id)
(with-retries 3) (with-retries 3)
(with-validate uri schema))] (with-validate uri schema))]
(full-http-call))) (full-http-call)))
@ -103,26 +97,15 @@
(let [baseuri (cf/get :nitrate-backend-uri)] (let [baseuri (cf/get :nitrate-backend-uri)]
(request-to-nitrate cfg :get (str baseuri "/api/users/" (str profile-id)) schema:user params))) (request-to-nitrate cfg :get (str baseuri "/api/users/" (str profile-id)) schema:user params)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; INITIALIZATION ;; INITIALIZATION
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defmethod ig/init-key ::client (defmethod ig/init-key ::client
[_ {:keys [::setup/props] :as cfg}] [_ cfg]
(if (contains? cf/flags :nitrate) (when (contains? cf/flags :nitrate)
(let [management-key (or (cf/get :management-api-key) {:get-team-org (partial get-team-org cfg)
(get props :management-key)) :is-valid-user (partial is-valid-user cfg)}))
cfg (assoc cfg ::management-key management-key)]
{:get-team-org (partial get-team-org cfg)
:is-valid-user (partial is-valid-user cfg)})
{}))
(defmethod ig/halt-key! ::client
[_ {:keys []}]
(do :stuff))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; UTILS ;; UTILS