APIs to create users and devices

Are there any API(s) to create users and devices in-order to automate the process?

@remy The REST API is still under development, but for the time being you can create Users and Devices by rpc’ing into the functions directly like so:

Create user

/opt/firezone/embedded/service/firezone/bin/firezone rpc 'FzHttp.Users.create_user(%{"email" => "foobar@example.com", "password" => "password_here", "password_confirmation" => "password_here"})'

Create device for user (must know user_id and generate psk and keypair beforehand)

/opt/firezone/embedded/service/firezone/bin/firezone rpc 'FzHttp.Devices.create_device(%{"user_id" => 36, "public_key" => "H4P2H2LvtVWa+MZw/GD6dUkjF1HstCdr2HXxqMzY=", "preshared_key" => "dHN1zuRd/PemzBDeYQqMsVTyHSNoTsmJQ=", "name" => "DEVICE_NAME"})'
1 Like

@jamil, is it possible to provide the command to check if the user and the device exists before they are created?

I tried with /opt/firezone/embedded/service/firezone/bin/firezone rpc 'FzHttp.Users.get_by_email("user@localhost.local")' but it give no output, actual user dose exists.

Yep, Try IO.inspect(FzHttp.Users.get_by_email(…)) in order to format the output :slight_smile:

@jamil, thanks thats working

/opt/firezone/embedded/service/firezone/bin/firezone rpc 'IO.inspect(FzHttp.Users.get_by_email("user@localhost.local"))'
/opt/firezone/embedded/service/firezone/bin/firezone rpc 'IO.inspect(FzHttp.Devices.list_devices(<device_id>))'

@jamil , is it possible to add validation when adding device from CLI command to check if the public key and pre-shared keys are valid? I added wrong key add Phoenix crashed, had to delete the user from database and then restart firezone

@remy Thanks for the suggestion! Yeah, we’re changing the way keys are stored in the DB as part of 0.4.0 and this will be fixed then.

1 Like