Skip to content

Instantly share code, notes, and snippets.

@rodolfo42
Created July 19, 2023 17:19
Show Gist options
  • Save rodolfo42/7fe5d48aa182b04a3c5a5f7d494c8a92 to your computer and use it in GitHub Desktop.
Save rodolfo42/7fe5d48aa182b04a3c5a5f7d494c8a92 to your computer and use it in GitHub Desktop.
Import users into Lightdash from Okta CSV dump (Clojure)
user.id user.firstName user.lastName user.email user.status
00u5vogndju36975tn First Last [email protected] ACTIVE
(ns okta-lightdash
(:require [clj-http.client :as http]
[clojure.data.csv :as csv]
[cheshire.core :as json]))
(def lightdash-host "lightdash-host")
(def api-key "api-key")
(def base (str "https://" lightdash-host "/api/v1"))
(defn req [method url params]
(try
(:body (http/request (merge params {:method method :url url})))
(catch Exception e
(prn (ex-info "request error" (some-> e ex-data :body json/decode) e)))))
(defn params [x]
(-> {:headers {:Authorization (str "ApiKey " api-key)}
:content-type :json
:as :json}
(assoc :form-params x)))
(defn create-invite [user]
(->> (params {:expiresAt "2024-12-31T00:00:00Z" :email (:user.email user)})
(req :post (str base "/invite-links"))
:results
:inviteCode))
(defn create-user [user invite-code]
(->> (params {:inviteCode invite-code
:firstName (:user.firstName user)
:lastName (:user.lastName user)
:email (:user.email user)
:password (:user.id user)})
(req :post (str base "/user"))))
(def users
(let [data (csv/read-csv (slurp "okta.csv"))]
(map (partial apply hash-map) (map (partial interleave (map keyword (first data))) (rest data)))))
(def active-users (filter (comp #(= "ACTIVE" %) :user.status) users))
(comment
(for [user active-users]
(let [invite-code (create-invite user)]
(create-user user invite-code))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment