Skip to content

BE-M2-01 · Easygo pulls on staging

Why: a provider is pulled only once it is configured: its base_url is set and its key is in Vault (R-GPS-12). The migrations ship easygo unconfigured, so no environment pulls until zuki configures it by hand (L0). The shape of Easygo's answer and how it takes the key are assumed in app.easygo_normalize and app.gps_pull (an Authorization: Bearer header, an answer {"data": [{"device_id", "gps_time", "lat", "lon", "speed"}]}): this step's Check confirms or corrects that, without pasting any position (D113, draft).

ID BE-M2-01 · Level L0 · Issue #466

Staging pulls easygo every 15 seconds, and one gps_pulls row shows how Easygo answered. No file in the repository changes, and the key is in Vault only.

  • #466's pull request is merged and staging holds its migrations (BE-M0-33 run after the merge), so staging has public.gps_providers, public.gps_pulls and the extensions pg_cron, pg_net and supabase_vault.
  • You have Easygo's API key and the URL that lists the latest positions (<EASYGO_API_KEY>, <EASYGO_POSITIONS_URL>), from Easygo's portal or the password manager.
  • The Supabase dashboard is open on the staging project (<STAGING_PROJECT_REF>).

Run block 1 before block 2: the schedule is made when base_url is set, and only if the key is already in Vault.

Dashboard → Integrations → Vault → Secrets → Add new secret. Name easygo_api_key, secret <EASYGO_API_KEY>, description Easygo API key (BE-M2-01). Save. Don't put the key in the SQL editor: its history keeps what you type.

2 · Set the base URL and the account's organization, and read the schedule (dashboard, SQL editor)

Section titled “2 · Set the base URL and the account's organization, and read the schedule (dashboard, SQL editor)”

The Easygo account belongs to one organization; its pulls store positions only for that organization's devices (R-GPS-41). <STAGING_ORG_SLUG> is the slug of the staging organization whose cars carry the Easygo devices.

update public.gps_providers
set base_url = '<EASYGO_POSITIONS_URL>',
organization_id = (select id from public.organizations where slug = '<STAGING_ORG_SLUG>')
where code = 'easygo';
select jobname, schedule, active from cron.job where jobname like 'gps_%' order by jobname;

3 · Wait a minute, then read the last pull (dashboard, SQL editor)

Section titled “3 · Wait a minute, then read the last pull (dashboard, SQL editor)”

It prints only statuses, counts, the error text and the names of the answer's keys: never a key, a position or a device id.

select status, rows_ingested, rows_skipped, rows_rejected, left(error, 120) as error,
jsonb_typeof(body) as body_type,
(select string_agg(k, ',' order by k) from jsonb_object_keys(case when jsonb_typeof(body) = 'object' then body else '{}' end) k) as body_keys,
(select string_agg(k, ',' order by k) from jsonb_object_keys(case when jsonb_typeof(body -> 'data' -> 0) = 'object' then body -> 'data' -> 0 else '{}' end) k) as element_keys,
(select count(*) from public.gps_pulls) as pulls
from public.gps_pulls order by id desc limit 1;
  • Block 1: the secret easygo_api_key is listed; its value is hidden.

  • Block 2: UPDATE 1, then exactly two rows:

    gps_purge | 0 20 * * * | true
    gps_pull_easygo | 15 seconds | true
  • Block 3: one row with pulls above 1, status succeeded, body_type object, body_keys containing data, element_keys device_id,gps_time,lat,lon,speed. rows_ingested counts positions of devices linked and active on staging; with none linked yet, everything is counted as skipped.

Paste block 3's row on #466. It confirms the assumed shape when status is succeeded and element_keys reads device_id,gps_time,lat,lon,speed. Any other element_keys, or an error, is what be needs to change the adapter: paste it as it is.

  • Block 2 shows no gps_pull_easygo row: the key wasn't in Vault when base_url was set, its name differs, or the slug matched no organization (organization_id is null). Check the secret's name is exactly easygo_api_key and the slug, then run block 2 again: setting base_url again schedules the job.
  • status failed, error HTTP 401 or HTTP 403: Easygo doesn't take the key as a bearer token, or the key is wrong. Paste the row; don't try other headers on staging. be changes app.gps_pull.
  • status failed, error HTTP 404: the URL is wrong. Check it in Easygo's documentation and run block 2 again with the right one.
  • status failed with the answer is not JSON, or another adapter error, or element_keys other than expected: paste the row; be changes app.easygo_normalize. Stop the pulls meanwhile with Undo block 1.
  • status pending for over 5 minutes, or no answer after 5 minutes: staging can't reach Easygo. Paste the row and stop.
  1. Stop the pulls (SQL editor): update public.gps_providers set base_url = null where code = 'easygo'; removes the job gps_pull_easygo. The rows already pulled stay until the 90-day purge (R-GPS-13).
  2. To remove the key too: Dashboard → Integrations → Vault → Secrets → easygo_api_key → Delete.

Log each run as a comment on #466: the date, block 2's two rows and block 3's row. Never paste the key, the URL's credentials if it has any, a position or a device id.