Artwork

Content provided by Christoph Neumann and Nate Jones, Christoph Neumann, and Nate Jones. All podcast content including episodes, graphics, and podcast descriptions are uploaded and provided directly by Christoph Neumann and Nate Jones, Christoph Neumann, and Nate Jones or their podcast platform partner. If you believe someone is using your copyrighted work without your permission, you can follow the process outlined here https://player.fm/legal.
Player FM - Podcast App
Go offline with the Player FM app!

Episode 011: The Convention of Configuration

28:47
 
Share
 

Manage episode 224930934 series 2463849
Content provided by Christoph Neumann and Nate Jones, Christoph Neumann, and Nate Jones. All podcast content including episodes, graphics, and podcast descriptions are uploaded and provided directly by Christoph Neumann and Nate Jones, Christoph Neumann, and Nate Jones or their podcast platform partner. If you believe someone is using your copyrighted work without your permission, you can follow the process outlined here https://player.fm/legal.

Nate is worried about the hardcoded credentials in the code.

  • It's episode 011 on 01/11. It's binary!
  • "As a developer, you quickly learn what's under your control and what's not. Very little is under your control."
  • Don't accidentally check in the credentials.
  • "We need a configuration management system. Oh wait! That's a totally different problem."
  • What about putting the configuration into an EDN file?
  • Let's call it config.edn
  • Why EDN? Isn't JSON the "one, true format for config information"?
  • Pros of EDN:
    • native to Clojure
    • can have comments
    • is extensible
  • Why not environment variables?
  • Environment variables are great for production, but in development files are better.
  • Have to restart the REPL to change env variables.
  • Make a component that reads the config. That will reload config when you reset with component.repl.
  • Two main considerations:
    1. Dynamically reloading configuration during development
    2. Plumbing the configuration values through the app
  • Make a namespace for app.config
  • "Files are way more fungible than the environment."
  • We want both options: env for production and a file for dev.
  • Make two functions in app.config: from-env and from-file.
  • Use schema to make sure both functions return the same config map.
  • "A thing I have done before...you decide if it's clever."
  • Define a default configuration and then merge the config maps with that.
  • Better yet, from-env handles defaults and we merge the map from dev.edn into that.
  • Can use environ with Leiningen profiles. Still requires restarting the REPL.
  • Defaults should make sense for development, so you can just check out and run.
  • For bad config, we want helpful error messages, not stack traces.
  • What goes in configuration?
    • Items under your control
    • Items that vary
  • Twitter API URL does not vary.
  • Even if Twitter provided sandbox URLs, those URLs don't vary. The config option should be "production" and "sandbox", not the URL. The wrapper code will select the right URL.
  • Avoid the nonsense of trying to infer "sandbox" from reading the URL.
  • "The hallmark of good design is: the less thinking you have to do, the better."
  • "The more semantic the config, the less thinking you have to do."
  • It's important to think about the data first, where it comes from, and where it goes.

Clojure in this episode:

  • merge
  • try, catch
  • slurp
  • clojure.edn/read-string
  • environ.core/env
  • component.repl/reset

Related projects:

Code sample from this episode:

(ns app.config (:require [clojure.edn :as edn] [environ.core :refer [env]])) (defn from-env [] {:twitter-key (or (env :twitter-key) "") :twitter-secret (or (env :twitter-secret) "") :initial-tweets (or (env :initial-tweets) 20)) (defn config [] (merge (from-env) (edn/read-string (try (slurp "dev.edn") (catch Throwable e "{}"))))) 
  continue reading

113 episodes

Artwork
iconShare
 
Manage episode 224930934 series 2463849
Content provided by Christoph Neumann and Nate Jones, Christoph Neumann, and Nate Jones. All podcast content including episodes, graphics, and podcast descriptions are uploaded and provided directly by Christoph Neumann and Nate Jones, Christoph Neumann, and Nate Jones or their podcast platform partner. If you believe someone is using your copyrighted work without your permission, you can follow the process outlined here https://player.fm/legal.

Nate is worried about the hardcoded credentials in the code.

  • It's episode 011 on 01/11. It's binary!
  • "As a developer, you quickly learn what's under your control and what's not. Very little is under your control."
  • Don't accidentally check in the credentials.
  • "We need a configuration management system. Oh wait! That's a totally different problem."
  • What about putting the configuration into an EDN file?
  • Let's call it config.edn
  • Why EDN? Isn't JSON the "one, true format for config information"?
  • Pros of EDN:
    • native to Clojure
    • can have comments
    • is extensible
  • Why not environment variables?
  • Environment variables are great for production, but in development files are better.
  • Have to restart the REPL to change env variables.
  • Make a component that reads the config. That will reload config when you reset with component.repl.
  • Two main considerations:
    1. Dynamically reloading configuration during development
    2. Plumbing the configuration values through the app
  • Make a namespace for app.config
  • "Files are way more fungible than the environment."
  • We want both options: env for production and a file for dev.
  • Make two functions in app.config: from-env and from-file.
  • Use schema to make sure both functions return the same config map.
  • "A thing I have done before...you decide if it's clever."
  • Define a default configuration and then merge the config maps with that.
  • Better yet, from-env handles defaults and we merge the map from dev.edn into that.
  • Can use environ with Leiningen profiles. Still requires restarting the REPL.
  • Defaults should make sense for development, so you can just check out and run.
  • For bad config, we want helpful error messages, not stack traces.
  • What goes in configuration?
    • Items under your control
    • Items that vary
  • Twitter API URL does not vary.
  • Even if Twitter provided sandbox URLs, those URLs don't vary. The config option should be "production" and "sandbox", not the URL. The wrapper code will select the right URL.
  • Avoid the nonsense of trying to infer "sandbox" from reading the URL.
  • "The hallmark of good design is: the less thinking you have to do, the better."
  • "The more semantic the config, the less thinking you have to do."
  • It's important to think about the data first, where it comes from, and where it goes.

Clojure in this episode:

  • merge
  • try, catch
  • slurp
  • clojure.edn/read-string
  • environ.core/env
  • component.repl/reset

Related projects:

Code sample from this episode:

(ns app.config (:require [clojure.edn :as edn] [environ.core :refer [env]])) (defn from-env [] {:twitter-key (or (env :twitter-key) "") :twitter-secret (or (env :twitter-secret) "") :initial-tweets (or (env :initial-tweets) 20)) (defn config [] (merge (from-env) (edn/read-string (try (slurp "dev.edn") (catch Throwable e "{}"))))) 
  continue reading

113 episodes

All episodes

×
 
Loading …

Welcome to Player FM!

Player FM is scanning the web for high-quality podcasts for you to enjoy right now. It's the best podcast app and works on Android, iPhone, and the web. Signup to sync subscriptions across devices.

 

Quick Reference Guide