Enable setting config securely in firmware/config/secrets.exs

This commit is contained in:
Pim Kunis 2019-07-14 23:54:06 +02:00
parent fe172f018a
commit 8f99154259
7 changed files with 17 additions and 15 deletions

View file

@ -12,6 +12,7 @@ If you have found the source code before finding the geocache, consider it a hin
Building: Building:
```bash ```bash
export MIX_ENV=prod && export MIX_TARGET=<device>
cd ui/assets && npm install cd ui/assets && npm install
cd ../ && mix phx.digest cd ../ && mix phx.digest
cd ../firmware && mix deps.get cd ../firmware && mix deps.get
@ -20,12 +21,9 @@ mix firmware.burn # After inserting SD card
``` ```
## Setting morse code ## Setting morse code
Still have to find out how to correctly set secrets... so I have to do it manually now. To set the morse code, create a new file under firmware/config, called secrets.exs:
```bash
ssh nerves.local
```
```elixir ```elixir
System.set_env("MORSE_MESSAGE", "...---...") use Mix.Config
config :morse, :morse_message, "...---..."
``` ```

View file

@ -0,0 +1,3 @@
use Mix.Config
config :morse, :morse_message, "................"

View file

@ -37,6 +37,10 @@ config :nerves_init_gadget,
node_name: node_name, node_name: node_name,
node_host: :mdns_domain node_host: :mdns_domain
if File.exists?("config/secrets.exs") do
import_config "secrets.exs"
end
# Import target specific config. This must remain at the bottom # Import target specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above. # of this file so it overrides the configuration defined above.
# Uncomment to use target specific configurations # Uncomment to use target specific configurations

1
morse/.gitignore vendored
View file

@ -21,4 +21,3 @@ erl_crash.dump
# Ignore package tarball (built via "mix hex.build"). # Ignore package tarball (built via "mix hex.build").
morse-*.tar morse-*.tar

View file

@ -21,12 +21,7 @@ defmodule Morse do
""" """
def signal do def signal do
case System.get_env("MORSE_MESSAGE") do signal(Application.fetch_env!(:morse, :morse_message))
nil ->
# Signal for SOS if the env variable wasn't found :)
signal("...---...")
message -> signal(message)
end
end end
def signal(symbols) do def signal(symbols) do

View file

@ -14,7 +14,8 @@ defmodule Morse.MixProject do
# Run "mix help compile.app" to learn about applications. # Run "mix help compile.app" to learn about applications.
def application do def application do
[ [
extra_applications: [:logger] extra_applications: [:logger],
env: [morse_message: "...---..."]
] ]
end end

2
ui/.gitignore vendored
View file

@ -32,3 +32,5 @@ npm-debug.log
# we ignore priv/static. You may want to comment # we ignore priv/static. You may want to comment
# this depending on your deployment strategy. # this depending on your deployment strategy.
/priv/static/ /priv/static/
config/secrets.exs