diff --git a/src/keboola/facebook/extractor/core.clj b/src/keboola/facebook/extractor/core.clj index 875d4f0..7ad99b8 100644 --- a/src/keboola/facebook/extractor/core.clj +++ b/src/keboola/facebook/extractor/core.clj @@ -11,6 +11,7 @@ [keboola.facebook.extractor.query :as query] [keboola.facebook.extractor.sync-actions :as sync-actions] [keboola.http.client :refer [fb-requests-count]] + [keboola.http.recording :refer [turn-log-responses-on]] [keboola.utils.json-to-csv :as csv] [slingshot.slingshot :refer [throw+ try+]])) @@ -64,6 +65,10 @@ app-access-token (docker-config/app-access-token datadir) out-dir-path (docker-config/out-dir-path datadir) credentials (docker-config/user-credentials datadir)] + (when (:debug-mode parameters) + (log "Running in debug mode") + (sync-actions/disable-log-token) + (turn-log-responses-on)) (cond (empty? credentials) (docker-runtime/user-error "Missing facebook credentials") (empty? (docker-config/get-fb-token credentials)) (docker-runtime/user-error "Missing facebook token")) diff --git a/src/keboola/http/recording.clj b/src/keboola/http/recording.clj index 72cad63..e554edf 100644 --- a/src/keboola/http/recording.clj +++ b/src/keboola/http/recording.clj @@ -4,12 +4,16 @@ (def recording (atom '())) (def do-recording? (atom false)) +(def do-log-responses? (atom false)) + (defn reset-recording [] (reset! recording '())) (defn turn-recording-on [] (reset! do-recording? true)) (defn turn-recording-off [] (reset! do-recording? false)) +(defn turn-log-responses-on [] (reset! do-log-responses? true)) + (def VALID-CHARS (map char (concat (range 48 58) ; 0-9 (range 66 91) ; A-Z @@ -36,8 +40,20 @@ (defn anonymize-map [m] (postwalk anonymize-item m)) + +(defn replace-token-by-regexp [item] + (if (string? item) + (clojure.string/replace item #"access_token=[^&]*" "access_token=TOKEN") + item)) + (defn record-request [response method url request-rest] - #_(println (pr-str request-rest)) + (when @do-log-responses? + (let [result-map {:method method + :url url + :response {:status (:status response) :body (:body response)}} + result (postwalk replace-token-by-regexp result-map)] + (println (generate-string result {:pretty true}))) + (Thread/sleep 350)) (if @do-recording? (let [request-base {:method method :address url} request (merge request-base (apply hash-map request-rest))