Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cassandra Configuration Does Not Work With Given Readers #108

Open
briprowe opened this issue Jan 10, 2019 · 0 comments
Open

Cassandra Configuration Does Not Work With Given Readers #108

briprowe opened this issue Jan 10, 2019 · 0 comments

Comments

@briprowe
Copy link
Contributor

briprowe commented Jan 10, 2019

The cassandra configuration requires there be a vector of hosts:

{:migrators {:cass "migrations/migrators/cass"}
 :seeds {:cass "migrations.seeds.cass/run"}
 :databases {:cass-dev {:type :cass :hosts ["localhost"] :keyspace "foo"}
             :cass-stage {:type :cass :hosts ["10.10.10.10", "10.10.10.11", "10.10.10.12"]
                          :keyspace "foo"
                          :credentials {:user "something"
                                        :password "maybe-something-else?"}}}
 :environments {:dev [{:db :cass-dev :migrator :cass :seed :cass}]
                :stage [{:db :cass-stage :migrator :cass :seed :cass}]}}

But the readers for the tagged literals #env and #envf can only return strings.

This makes it hard to define migrations that need to discover the IPs dynamically (eg. when cassandra's running in a kubernetes cluster).

A possible solution would be to create a reader that lets client code supply a function that can fill in the data necessary. Suppose that reader's tag is #foo. Then the configuration data might look like:

{:migrators {:cass "migrations/migrators/cass"}
 :seeds {:cass "migrations.seeds.cass/run"}
 :databases {:cass-dev {:type :cass :hosts #foo my.dev.namespace/minikube-config :keyspace "foo"}
             :cass-stage {:type :cass :hosts #foo my.stage.namespace/lookup-cassandra-endpoints
                          :keyspace "foo"
                          :credentials {:user "something"
                                        :password "maybe-something-else?"}}}
 :environments {:dev [{:db :cass-dev :migrator :cass :seed :cass}]
                :stage [{:db :cass-stage :migrator :cass :seed :cass}]}}

The joplin reader function would then look something like:

(defn load-config [r]
  (edn/read {:readers {'env (fn [x] (System/getenv (str x)))
                       'envf (fn [[fmt & args]]
                               (apply format fmt
                                      (map #(System/getenv (str %)) args)))
                       'foo (fn [fn-symbol]
                              (require (symbol (namespace fn-symbol)))
                              ((ns-resolve *ns* fn-symbol)))}}
(PushbackReader. (io/reader r))))

Of course, #foo's not the best tag for this reader, but I can't think of a great one at the moment.

Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant