# Customer Hosted ER Creation in V8

Supports similar path to retrieving a registration key for an edge router in v3 as in v2.  Difference is that in v2, the MOP edge router already
exists and the URI for the api uses the MOP edgeRouterId.  For v3, need to utilize the networkId + zitiId instead.

There is an alternate flow in the sequence diagram with the calls to `/register` can come from
either the ER installer or the ER install script itself.  Some customers may not utilize this feature
of the installation script (registration-key).  In either case, the call to `/register` is required
in order to trigger the records required by the Salt Master minion registration.

Additionally, the unauthenticated `POST /register/{key}` request from the edge router install script will trigger the creation (first time) of the
MOP edge router and host records.  This is needed for the subsequent calls from the Salt Master when registering the salt minion endpoint.
Note also that this is common with the v2 edge router installation.


```mermaid
sequenceDiagram 
    title Customer Hosted ER Creation in V8
    actor Creator as ER Creator; 
    participant Core
    participant Ziti
    actor Installer as ER Installer
    participant CER as CER<br/>w/Salt
    participant Salt as Salt<br/>Master

    Note over Creator,Salt: ER created in ziti before<br/>calls to get registration key
    Creator-->>Ziti: Create ER

    Creator->>+Core: POST /registration-key<br/>(authenticated)
    note right of Core: lazy create<br/>verify ER state in DB (if exists)<br/>params: network & zitiId
    Core->>Ziti: Verify exists
    Core->>-Creator: registrationKey
    
    alt normal flow
    Installer->>CER: Create<br/>(using key)
    CER->>+Core: POST /edge-router-registrations/{key} (unauthenticated)
    Core->>+Ziti: Get ER from Ziti
    Ziti->>-Core: JWT + ER
    note right of Core: Generates ER record<br/>Generates Host record
    Core->>-CER: JWT + ER Stuff
    else Island gets JWT data separately from the key?

    Installer->>+Core: POST /edge-router-registrations/{key} (unauthenticated)
    note right of Core: (+ the ziti and record<br/>creation stuf above)
    Core->>-Installer: JWT + ER Stuff
    Installer->>CER: Create<br/>(using JWT + ER Stuff)
    end
    CER->>Salt: activate
    note right of Core: ER and Host records must<br/>exist in core before this
    Salt->>Core: read ER+host data (authenticated)
    CER->>Core: DELETE /edge-router-registrations/{key} (unauthenticated)
```
