added suggestions

This commit is contained in:
2022-07-26 07:01:18 -07:00
parent 96c80853ef
commit 84f7e734f0
65 changed files with 130 additions and 1140 deletions

View File

@@ -10,6 +10,7 @@
(def google-client-id "264081895820-0nndcfo3pbtqf30sro82vgq5r27h8736.apps.googleusercontent.com")
(def google-client-secret "OC-WemHurPXYpuIw5cT-B90g")
#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn make-api-token []
(jwt/sign {:user "API"
:exp (time/plus (time/now) (time/days 1000))

View File

@@ -1,6 +1,5 @@
(ns auto-ap.routes.utils
(:require [buddy.auth :refer [authenticated?]]
[clojure.spec.alpha :as s]))
(:require [buddy.auth :refer [authenticated?]]))
(defn wrap-secure [handler]
(fn [request]
@@ -8,11 +7,3 @@
(handler request)
{:status 401
:body "not authenticated"})))
(defn wrap-spec [handler spec]
(fn [request]
(if (not (s/valid? spec (:edn-params request)))
{:status 400
:body (pr-str (s/explain-data spec (:edn-params request)))
:headers {"Content-Type" "application/edn"}}
(handler request))))

View File

@@ -1,83 +0,0 @@
(ns auto-ap.routes.yodlee
(:require
[auto-ap.graphql.utils :refer [assert-admin]]
[auto-ap.routes.utils :refer [wrap-secure]]
[auto-ap.yodlee.core :as yodlee]
[clojure.tools.logging :as log]
[compojure.core :refer [context defroutes GET POST wrap-routes]]
[config.core :refer [env]]))
(defroutes routes
(wrap-routes
(context "/yodlee" []
(GET "/fastlink" {:keys [identity]}
(assert-admin identity)
(let [[session token] (yodlee/get-access-token)]
{:status 200
:headers {"Content-Type" "application/edn"}
:body (pr-str {:session session
:token token
:app (:yodlee-app env)
:url (:yodlee-fastlink env)})}))
(GET "/accounts" {:keys [identity]}
(assert-admin identity)
{:status 200
:headers {"Content-Type" "application/edn"}
:body (pr-str (yodlee/get-accounts (yodlee/get-auth-header)))})
(GET "/provider-accounts" {:keys [identity]}
(assert-admin identity)
(log/info "working on provider accounts...")
{:status 200
:headers {"Content-Type" "application/edn"}
:body (pr-str @yodlee/in-memory-cache)})
(POST "/reauthenticate/:id" {:keys [identity] {:keys [id]} :route-params
data :edn-params}
(assert-admin identity)
(try
{:status 200
:headers {"Content-Type" "application/edn"}
:body (pr-str (yodlee/reauthenticate-and-recache (Long/parseLong id) data (yodlee/get-auth-header)))}
(catch Exception e
(log/error e)
{:status 500
:headers {"Content-Type" "application/edn"}
:body (pr-str {:message (.getMessage e)
:error (.toString e)})})))
(POST "/provider-accounts/refresh/:id" {:keys [identity] {:keys [id]} :route-params}
(assert-admin identity)
(try
(yodlee/refresh-provider-account (Long/parseLong id) (yodlee/get-auth-header))
{:status 200
:headers {"Content-Type" "application/edn"}
:body (pr-str @yodlee/in-memory-cache)}
(catch Exception e
{:status 400
:headers {"Content-Type" "application/edn"}
:body (pr-str {:message (.getMessage e)
:error (.toString e)})})))
(POST "/provider-accounts/delete/:id" {:keys [identity] {:keys [id]} :route-params}
(assert-admin identity)
(try
(yodlee/delete-and-uncache-provider-account (Long/parseLong id) (yodlee/get-auth-header))
{:status 200
:headers {"Content-Type" "application/edn"}
:body (pr-str @yodlee/in-memory-cache)}
(catch Exception e
{:status 400
:headers {"Content-Type" "application/edn"}
:body (pr-str {:message (.getMessage e)
:error (.toString e)})})))
(POST "/provider-accounts/:id" {:keys [identity] {:keys [id]} :route-params}
(assert-admin identity)
(try
{:status 200
:headers {"Content-Type" "application/edn"}
:body (pr-str (yodlee/update-yodlee (Long/parseLong id) (yodlee/get-auth-header)))}
(catch Exception e
{:status 400
:headers {"Content-Type" "application/edn"}
:body (pr-str e)}))))
wrap-secure))