mirror of
https://github.com/usetrmnl/terminus.git
synced 2026-08-13 14:29:27 -07:00
Removed device friendly ID and API implementation
These attributes were originally used for the Core proxy feature (and device provisioning) but are no longer needed. These changes completely remove these attributes (including the migration for removing from the `device` table). Issue: 326 Milestone: minor
This commit is contained in:
@@ -36,16 +36,12 @@ module Terminus
|
||||
:model_name
|
||||
|
||||
provisioner.call(model_id: find_model_id(model_name), mac_address:, firmware_version:)
|
||||
.either -> device { render_success device, response },
|
||||
.either proc { response.with body: payload.welcome.to_json },
|
||||
-> error { not_found error, response }
|
||||
end
|
||||
|
||||
def find_model_id(name) = model_repository.find_by(name:).then { it.id if it }
|
||||
|
||||
def render_success device, response
|
||||
response.body = payload.for(device).to_json
|
||||
end
|
||||
|
||||
def not_found error, response
|
||||
payload = petail[
|
||||
type: "/problem_details#device_setup",
|
||||
|
||||
@@ -14,10 +14,8 @@ module Terminus
|
||||
|
||||
def call
|
||||
{
|
||||
api_key: randomizer.alphanumeric(20),
|
||||
mac_address: mac_address_builder.call,
|
||||
firmware_update: true,
|
||||
friendly_id: randomizer.hex(3).upcase,
|
||||
image_timeout: 0,
|
||||
label: "TRMNL",
|
||||
refresh_rate: 900
|
||||
|
||||
@@ -7,7 +7,6 @@ module Terminus
|
||||
module Firmware
|
||||
module Headers
|
||||
KEY_MAP = {
|
||||
HTTP_ACCESS_TOKEN: :api_key,
|
||||
HTTP_BATTERY_VOLTAGE: :battery_voltage,
|
||||
HTTP_FW_VERSION: :firmware_version,
|
||||
HTTP_HEIGHT: :height,
|
||||
|
||||
@@ -5,11 +5,9 @@ module Terminus
|
||||
module Firmware
|
||||
module Models
|
||||
# Models data for API setup responses.
|
||||
Setup = Struct.new :api_key, :friendly_id, :image_url, :message do
|
||||
def self.for device
|
||||
new api_key: device.api_key,
|
||||
friendly_id: device.friendly_id,
|
||||
image_url: %(#{Hanami.app[:settings].api_uri}/assets/setup.bmp),
|
||||
Setup = Struct.new :image_url, :message do
|
||||
def self.welcome
|
||||
new image_url: %(#{Hanami.app[:settings].api_uri}/assets/setup.bmp),
|
||||
message: "Welcome to Terminus!"
|
||||
end
|
||||
|
||||
|
||||
@@ -26,13 +26,7 @@ module Terminus
|
||||
attr_reader :environment, :resolver, :id
|
||||
|
||||
def add_filters
|
||||
cogger.add_filters :api_key,
|
||||
:csrf,
|
||||
:HTTP_ACCESS_TOKEN,
|
||||
:HTTP_ID,
|
||||
:mac_address,
|
||||
:password,
|
||||
:password_confirmation
|
||||
cogger.add_filters :csrf, :HTTP_ID, :mac_address, :password, :password_confirmation
|
||||
end
|
||||
|
||||
def build_instance
|
||||
|
||||
@@ -9,9 +9,7 @@ module Terminus
|
||||
optional(:model_id).filled :integer
|
||||
optional(:playlist_id).filled :integer
|
||||
optional(:label).filled :string
|
||||
optional(:friendly_id).filled :string
|
||||
optional(:mac_address).filled Types::MACAddress
|
||||
optional(:api_key).filled :string
|
||||
optional(:refresh_rate).filled :integer, gt?: 0
|
||||
optional(:image_cached).maybe :bool
|
||||
optional(:image_timeout).filled :integer, gteq?: 0
|
||||
|
||||
@@ -9,9 +9,7 @@ module Terminus
|
||||
required(:model_id).filled :integer
|
||||
required(:playlist_id).maybe :integer
|
||||
optional(:label).filled :string
|
||||
optional(:friendly_id).filled :string
|
||||
optional(:mac_address).filled Types::MACAddress
|
||||
optional(:api_key).filled :string
|
||||
optional(:refresh_rate).filled :integer, gt?: 0
|
||||
optional(:image_cached).maybe :bool
|
||||
optional(:image_timeout).filled :integer, gteq?: 0
|
||||
|
||||
@@ -5,7 +5,6 @@ module Terminus
|
||||
module Firmware
|
||||
# Validates request headers.
|
||||
Header = Dry::Schema.Params do
|
||||
optional(:HTTP_ACCESS_TOKEN).maybe :string
|
||||
optional(:HTTP_BATTERY_VOLTAGE).filled :float
|
||||
optional(:HTTP_FW_VERSION).filled Types::Version
|
||||
optional(:HTTP_HEIGHT).filled :integer
|
||||
|
||||
@@ -9,10 +9,8 @@ module Terminus
|
||||
id
|
||||
model_id
|
||||
playlist_id
|
||||
friendly_id
|
||||
label
|
||||
mac_address
|
||||
api_key
|
||||
firmware_profile
|
||||
firmware_update
|
||||
firmware_version
|
||||
|
||||
@@ -30,19 +30,6 @@
|
||||
autocomplete: :off %>
|
||||
<% end %>
|
||||
|
||||
<%= scope(:form_field, key: :friendly_id, errors:).render do %>
|
||||
<label class="key" for="device_friendly_id">
|
||||
Friendly ID
|
||||
<%= render "shared/popovers/triggers/default", name: :friendly_id %>
|
||||
</label>
|
||||
|
||||
<%= form.text_field :friendly_id,
|
||||
id: :device_friendly_id,
|
||||
value: field_for(:friendly_id, fields, device),
|
||||
class: :value,
|
||||
autocomplete: :off %>
|
||||
<% end %>
|
||||
|
||||
<%= scope(:form_field, key: :mac_address, errors:).render do %>
|
||||
<label class="key" for="device_mac_address">
|
||||
MAC Address
|
||||
@@ -61,24 +48,6 @@
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= scope(:form_field, key: :api_key, errors:).render do %>
|
||||
<label class="key" for="device_api_key">
|
||||
API Key
|
||||
<%= render "shared/popovers/triggers/default", name: :api_key %>
|
||||
</label>
|
||||
|
||||
<div class="input-group" x-data="{ show: false }">
|
||||
<%= form.text_field :api_key,
|
||||
id: :device_api_key,
|
||||
value: field_for(:api_key, fields, device),
|
||||
class: "value value-cap",
|
||||
autocomplete: :off,
|
||||
"x-bind:type" => "show ? 'text' : 'password'"%>
|
||||
|
||||
<%= render "shared/visibility_button" %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<%= scope(:form_field, key: :refresh_rate, errors:).render do %>
|
||||
<label class="key" for="device_refresh_rate">
|
||||
Refresh Rate
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
<%= render "devices/shared/popovers/api_key" %>
|
||||
<%= render "devices/shared/popovers/display_compatibility" %>
|
||||
<%= render "devices/shared/popovers/display_profile" %>
|
||||
<%= render "devices/shared/popovers/firmware_update" %>
|
||||
<%= render "devices/shared/popovers/firmware_profile" %>
|
||||
<%= render "devices/shared/popovers/friendly_id" %>
|
||||
<%= render "devices/shared/popovers/image_cached" %>
|
||||
<%= render "devices/shared/popovers/image_timeout" %>
|
||||
<%= render "devices/shared/popovers/mac_address" %>
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
<%= scope(:popover_default_content, name: :api_key, label: "API Key").render do %>
|
||||
<p>Used for API requests to authenticate between server and device.</p>
|
||||
<% end %>
|
||||
@@ -1,4 +0,0 @@
|
||||
<%= scope(:popover_default_content, name: :friendly_id, label: "Friendly ID").render do %>
|
||||
<p>Provides a way to uniquely identify your device.</p>
|
||||
<% end %>
|
||||
|
||||
@@ -43,24 +43,12 @@
|
||||
<%= device.playlist ? link_to(device.playlist.label, routes.path(:playlist, id: device.playlist_id)) : nil %>
|
||||
</dd>
|
||||
|
||||
<dt class="key">
|
||||
Friendly ID
|
||||
<%= render "shared/popovers/triggers/default", name: :friendly_id %>
|
||||
</dt>
|
||||
<dd class="value"><%= device.friendly_id %></dd>
|
||||
|
||||
<dt class="key">
|
||||
MAC Address
|
||||
<%= render "shared/popovers/triggers/default", name: :mac_address %>
|
||||
</dt>
|
||||
<dd class="value bit-secret"><%= device.mac_address %></dd>
|
||||
|
||||
<dt class="key">
|
||||
API Key
|
||||
<%= render "shared/popovers/triggers/default", name: :api_key %>
|
||||
</dt>
|
||||
<dd class="value bit-secret"><%= device.api_key %></dd>
|
||||
|
||||
<dt class="key">
|
||||
Refresh Rate
|
||||
<%= render "shared/popovers/triggers/default", name: :refresh_rate %>
|
||||
|
||||
@@ -39,12 +39,6 @@
|
||||
<dt class="key">playlist_id</dt>
|
||||
<dd class="value">The playlist ID. The current device playlist. Default: <code>nil</code>.</dd>
|
||||
|
||||
<dt class="key">friendly_id</dt>
|
||||
<dd class="value">The friendly ID. Defaults to an uppercase six character hex value.</dd>
|
||||
|
||||
<dt class="key">api_key</dt>
|
||||
<dd class="value">The API Key. The unique API key for making API requests. Defaults to an auto-generated value when not supplied.</dd>
|
||||
|
||||
<dt class="key">refresh_rate</dt>
|
||||
<dd class="value">The refresh rate in seconds. Must be greater than <code>10</code>. Default: <code>900</code>.</dd>
|
||||
|
||||
@@ -67,9 +61,7 @@
|
||||
"device": {
|
||||
"playlist_id": "1",
|
||||
"model_id": 1,
|
||||
"friendly_id": "AFCA5B",
|
||||
"label": "Demo",
|
||||
"api_key": "QubEY53CZCW9QxJbDNNA",
|
||||
"mac_address": "A1:B2:C3:D4:E5:F6",
|
||||
"firmware_update": true,
|
||||
"refresh_rate": "500",
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
ROM::SQL.migration do
|
||||
up do
|
||||
drop_column :device, :api_key
|
||||
drop_column :device, :friendly_id
|
||||
end
|
||||
|
||||
down do
|
||||
add_column :device, :api_key, String
|
||||
add_column :device, :friendly_id, String
|
||||
end
|
||||
end
|
||||
@@ -275,10 +275,8 @@ ALTER TABLE public.account ALTER COLUMN id ADD GENERATED BY DEFAULT AS IDENTITY
|
||||
|
||||
CREATE TABLE public.device (
|
||||
id integer CONSTRAINT devices_id_not_null NOT NULL,
|
||||
friendly_id text,
|
||||
label text,
|
||||
mac_address text,
|
||||
api_key text,
|
||||
firmware_version text,
|
||||
wifi_signal integer DEFAULT 0 CONSTRAINT devices_wifi_not_null NOT NULL,
|
||||
battery_voltage double precision DEFAULT 0 CONSTRAINT devices_battery_not_null NOT NULL,
|
||||
@@ -1716,4 +1714,5 @@ INSERT INTO schema_migrations (filename) VALUES
|
||||
('20260601143521_add_device_columns.rb'),
|
||||
('20260602112926_add_device_profile_and_compatibility_columns.rb'),
|
||||
('20260608161124_add_device_wifi_band_column.rb'),
|
||||
('20260609142235_add_screen_device_id_and_kind_columns.rb');
|
||||
('20260609142235_add_screen_device_id_and_kind_columns.rb'),
|
||||
('20260610103052_remove_device_api_key_and_friendly_id_columns.rb');
|
||||
|
||||
@@ -37,7 +37,6 @@ curl "https://localhost:2443/api/display" \
|
||||
|
||||
The {trmnl_firmware_link} will include the following headers in each HTTP request. All are optional except for the `ID` header. Here's the full list:
|
||||
|
||||
* `ACCESS_TOKEN`: The API key (or an empty string if not present).
|
||||
* `BATTERY_CAPACITY`: Ratio of current and max battery capacity. Example: `11300/11420`.
|
||||
* `BATTERY_CHARGING`: Boolean for if the battery is charging or not. Example: `0` or `1`.
|
||||
* `BATTERY_COUNT`: The number batteries avaiable. Example: `2`.
|
||||
@@ -153,8 +152,6 @@ curl "https://localhost:2443/api/setup/" \
|
||||
[source,json]
|
||||
----
|
||||
{
|
||||
"api_key": "<redacted>",
|
||||
"friendly_id": "ABC123",
|
||||
"image_url": "https://localhost:2443/assets/setup.bmp",
|
||||
"message": "Welcome to TRMNL BYOS"
|
||||
}
|
||||
@@ -264,10 +261,8 @@ curl "https://localhost:2443/api/devices/1" \
|
||||
"id": 1,
|
||||
"model_id": 11,
|
||||
"playlist_id": 1,
|
||||
"friendly_id": "DEMO11",
|
||||
"label": "Demo",
|
||||
"mac_address": "02:A1:B2:C3:D4:E5",
|
||||
"api_key": "OScdcN0kFbKjFcid9Kz6Cx",
|
||||
"firmware_profile": true,
|
||||
"firmware_update": true,
|
||||
"firmware_version": "1.8.6",
|
||||
@@ -301,10 +296,8 @@ curl "https://localhost:2443/api/devices/1" \
|
||||
"id": 1,
|
||||
"model_id": 11,
|
||||
"playlist_id": 1,
|
||||
"friendly_id": "DEMO11",
|
||||
"label": "Demo",
|
||||
"mac_address": "02:A1:B2:C3:D4:E5",
|
||||
"api_key": "OScdcN0kFbKjFcid9Kz6Cx",
|
||||
"firmware_profile": true,
|
||||
"firmware_update": true,
|
||||
"firmware_version": "1.8.6",
|
||||
@@ -362,10 +355,8 @@ curl -X "POST" "https://localhost:2443/api/devices" \
|
||||
"device": {
|
||||
"model_id": 11,
|
||||
"playlist_id": 1,
|
||||
"friendly_id": "DEMO11",
|
||||
"label": "Demo",
|
||||
"mac_address": "02:A1:B2:C3:D4:E5",
|
||||
"api_key": "OScdcN0kFbKjFcid9Kz6Cx",
|
||||
"firmware_profile": true,
|
||||
"firmware_update": true,
|
||||
"firmware_version": "1.8.6",
|
||||
@@ -408,10 +399,8 @@ curl -X "POST" "https://localhost:2443/api/devices" \
|
||||
"id": 1,
|
||||
"model_id": 11,
|
||||
"playlist_id": 1,
|
||||
"friendly_id": "DEMO11",
|
||||
"label": "Demo",
|
||||
"mac_address": "02:A1:B2:C3:D4:E5",
|
||||
"api_key": "OScdcN0kFbKjFcid9Kz6Cx",
|
||||
"firmware_profile": true,
|
||||
"firmware_update": true,
|
||||
"firmware_version": "1.8.6",
|
||||
@@ -470,10 +459,8 @@ You can change a single attribute or multiple attributes at once. All attributes
|
||||
"id": 1,
|
||||
"model_id": 11,
|
||||
"playlist_id": 1,
|
||||
"friendly_id": "DEMO11",
|
||||
"label": "Demo",
|
||||
"mac_address": "02:A1:B2:C3:D4:E5",
|
||||
"api_key": "OScdcN0kFbKjFcid9Kz6Cx",
|
||||
"firmware_profile": true,
|
||||
"firmware_update": true,
|
||||
"firmware_version": "1.8.6",
|
||||
@@ -524,10 +511,8 @@ curl -X "DELETE" "https://localhost:2443/api/devices/1" \
|
||||
"id": 1,
|
||||
"model_id": 11,
|
||||
"playlist_id": 1,
|
||||
"friendly_id": "DEMO11",
|
||||
"label": "Demo",
|
||||
"mac_address": "02:A1:B2:C3:D4:E5",
|
||||
"api_key": "OScdcN0kFbKjFcid9Kz6Cx",
|
||||
"firmware_profile": true,
|
||||
"firmware_update": true,
|
||||
"firmware_version": "1.8.6",
|
||||
|
||||
@@ -13,7 +13,6 @@ RSpec.describe Terminus::Actions::API::Log::Create, :db do
|
||||
{
|
||||
"HTTP_BASE64" => "true",
|
||||
"HTTP_FW_VERSION" => "0.0.0",
|
||||
"HTTP_ACCESS_TOKEN" => "abc123",
|
||||
"HTTP_HEIGHT" => 480,
|
||||
"HTTP_HOST" => "test.io",
|
||||
"HTTP_ID" => device.mac_address,
|
||||
|
||||
@@ -14,9 +14,7 @@ RSpec.describe Terminus::Actions::Devices::Create, :db do
|
||||
model_id: model.id,
|
||||
playlist_id: nil,
|
||||
label: "Test",
|
||||
friendly_id: "ABC123",
|
||||
mac_address: "AA:BB:CC:11:22:33",
|
||||
api_key: "abc",
|
||||
refresh_rate: 100,
|
||||
image_timeout: 100
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user