checkpoint

This commit is contained in:
Jamil Bou Kheir
2020-12-29 08:44:56 -08:00
parent 67e97e06c8
commit ded4d3dae3
8 changed files with 69 additions and 3 deletions

View File

@@ -52,14 +52,31 @@ You'll need recent versions of the following tools installed:
With the above installed, you should be able to navigate into the project root
and just run:
```
$ vagrant up
```bash
vagrant up
```
This will download the VM base box, provision it with dependencies, bootstrap
the FireGuard DB, launch the FireGuard Services, and print instructions for
connecting to the Web UI.
## Creating Additional Users
FireGuard creates the first user for you upon installation and prints the
credentials after `vagrant up` completes in the step above.
You may create additional users with the following command:
```bash
sudo -u fireguard /opt/fireguard/bin/fireguard rpc 'FgHttp.Users.create_user(
email: "USER_EMAIL",
password: "USER_PASSWORD",
password_confirmation: "USER_PASSWORD"
)'
```
This will create a user you can use to log into the Web UI.
## Contributing
See [CONTRIBUTING.md](CONTRIBUTING.md).

View File

@@ -82,3 +82,11 @@
shell: |
cd /home/vagrant/fireguard
dpkg -i fireguard_amd64.deb
- name: Create user
become: fireguard
shell: |
cd /home/vagrant/fireguard
scripts/create_user.sh
register: create_user
- name: Display user credentials
debug: msg="{{ create_user.stdout }}"

View File

@@ -14,7 +14,13 @@ defmodule FgHttp.Users do
def get_user!(id), do: Repo.get!(User, id)
def create_user(attrs \\ %{}) do
def create_user(attrs) when is_list(attrs) do
attrs
|> Enum.into(%{})
|> create_user()
end
def create_user(attrs) when is_map(attrs) do
%User{}
|> User.create_changeset(attrs)
|> Repo.insert()

View File

@@ -0,0 +1,18 @@
defmodule FgHttp.UsersTest do
use FgHttp.DataCase
alias FgHttp.Users
alias FgHttp.Users.User
describe "users" do
@valid_user [
email: "admin@fireguard.dev",
password: "test-password",
password_confirmation: "test-password"
]
test "create_user" do
assert {:ok, %User{} = _user} = Users.create_user(@valid_user)
end
end
end

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env bash
set -e
od=$(pwd)
mkdir -p pkg/debian/opt

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env bash
set -e
od=$(pwd)
mix local.hex --force && mix local.rebar --force

14
scripts/create_user.sh Executable file
View File

@@ -0,0 +1,14 @@
#!/usr/bin/env bash
set -e
email="$(openssl rand -hex 2)@fireguard.local"
password="$(openssl rand -base64 12)"
/opt/fireguard/bin/fireguard eval "FgHttp.Users.create_user(
email: \"${email}\",
password: \"${password}\",
password_confirmation: \"${password}\"
)"
echo "FireGuard user created! Save this information becasue it will NOT be shown again."
echo "Email: ${email}"
echo "Password: ${password}"

View File

@@ -1,4 +1,5 @@
#!/usr/bin/env sh
set -e
# migrate DB
fg_http/bin/fg_http eval "FgHttp.Release.migrate"