# Use the admin

> What the broker's web admin shows and changes, how to create an API key for the CLI and CI, what the read and write permissions allow, and how the admin invites and manages users.

The broker serves its admin at its `BIDIREKT_PUBLIC_URL`, such as http://localhost:8080 for the [local broker](https://bidirekt.com/docs/start/run-the-broker.md#local). The first access creates the admin, as in [Admin and users](https://bidirekt.com/docs/start/run-the-broker.md#admin-and-users); everyone else signs in with the invite the admin sends them. A session ends after 8 hours without use, or 7 days after sign-in.

The CLI and the admin are two ways into the same broker. Publishing, can-i-deploy and recording deployments run from the CLI, in your pipeline; the admin shows what they stored, creates the API keys the CLI signs in with, manages users, and creates, renames and reorders participants and environments. The screenshots on this page come from the [petstore example](https://bidirekt.com/docs/start/demo.md).

## API keys

The CLI and CI sign in to the broker with an API key. Every user, the admin included, creates their own on the Profile page (`/profile`), with **New API key**:

![Create an API key: Profile, New API key, name, permission and expiry, then copy the key](/media/admin/create-api-key.mp4)

- **Name**: where the key runs, such as `laptop` or `payments CI`, up to 100 characters.
- **Permission**: `read` or `write`, as in [Permissions](#permissions). A key never does more than its user: a `read` user only gets `read`. The admin's keys are `read` or `write` too, since users are managed only on the pages.
- **Expires**: in 30, 90 or 365 days, or never. 90 days is chosen at first.

The broker shows the key once, right after it is created: copy it then, and paste it into [`bidirekt login`](https://bidirekt.com/docs/reference/cli.md#login) or into the CI secret for `BIDIREKT_API_KEY`. Every key starts with `bdk_`. The broker keeps only a hash of it, so a lost key can't be shown again: revoke it and create another.

![The Profile page, with the password form and the list of API keys](/media/admin/profile.png)

The Profile page lists your keys with their name, the start of the key (`bdk_` and 8 more characters), the permission, when each was created, last used and expires. **Revoke** stops a key at once; the CLI then gets `not signed in to <broker> — run "bidirekt login" or set BIDIREKT_BROKER_URL and BIDIREKT_API_KEY`. An expired key stops working at that moment and shows as `expired` until the broker deletes it on its next start. When the admin lowers a user's permission, the user's keys act with the lower one, and the list shows it next to the key's own, such as `write · acts as read`.

The admin sees the keys of every other user on the Users page, with **API keys** on each user's row: the same list, and **Revoke** on each key. The admin's own keys appear only on the admin's Profile.

**Deactivate** revokes every key of the user, and **Reactivate** does not bring them back: the user creates new ones. Changing your password on the Profile page, or setting a new one from a reset link, does not revoke your keys.

## Permissions

Every user and every API key has a permission:

- `read` sees every page of the admin, lists participants and environments, validates contracts and asks can-i-deploy.
- `write` adds publishing contracts, recording deployments, creating participants and environments, and renaming and reordering environments.
- `admin` belongs to the admin only: everything `write` does, plus managing users.

## Pages

Signed in, the admin's pages show everything the broker stores. Every user, `read` included, sees every page below; the forms that change something appear only to `write` and `admin` users.

The menu is Overview, Compatibility, Participants, Environments, Users (admin only) and Profile. Pages that list many rows show 25 per page, with numbered pages.

### Overview

![The Overview: one newest version can't move on, the environments in order, the 14-day charts and the cards](/media/admin/overview.png)

The Overview (`/`) headline says how many participants have a newest version that can't move on, or that every newest version can move on. Below it, the environments in their order, each with how many participants run there, and between two environments how many newest versions are blocked from entering the next one and how many are ready to enter it. Two charts cover the last 14 days, the can-i-deploy answers (yes and no) and the deployments per day, each with a **View as table** toggle. Three cards show the number of participants, the deployments and can-i-deploy answers of the last 7 days, and how many running participants a blocked newest version would break. An empty broker shows the steps to start: create an API key on your Profile and run `bidirekt login`, then `create-participant`, `create-environment`, `publish`, `can-i-deploy`, deploy and `record-deployment`.

**Activity** (`/activity`, from **See all activity** on the Overview) lists every deployment and can-i-deploy answer, newest first, grouped by day. It filters by type (everything, deployments, checks or blocked only), by environment and by participant name.

### Compatibility

![Compatibility: petstore_api 2.0.0 blocked in dev, opened to show it was checked against petstore_web](/media/admin/compatibility.png)

Compatibility (`/compatibility`) shows every participant as a row and every environment as a column. Each cell says where the participant's newest version stands in that environment, with a short reason: **Up to date** (it is deployed there), **Blocked** (its last can-i-deploy there said no, and which participants it breaks), **Ready** (its last can-i-deploy there said yes, but it is not deployed yet) or **Not asked** (no can-i-deploy there yet). The tabs are Needs attention, the default, with the participants that have a Blocked or Ready cell, then Blocked, Ready to deploy and All. An environment filter and a name filter narrow the list. Opening a row lists the participants its newest version was checked against, with each one's result per environment.

### Check

![A check: petstore_api 2.0.0 can't go to dev, because petstore_web reads Pet.status, with the fix for each side](/media/admin/check.png)

A check (`/checks/<id>`) is one [can-i-deploy report](https://bidirekt.com/docs/ship/can-i-deploy.md#the-report), with the same lines the CLI prints: the answer, the breaks grouped by field, and each fix, side by side when both participants have one, the participant being deployed marked. A yes lists what it was compared with, or that nothing was deployed in the environment. A graph counterpart links to its graph page.

### Participants

![The participant petstore_web: up to date in dev, ready for staging, not asked in production, and the participants it calls](/media/admin/participant.png)

Participants (`/participants`) lists every participant, with how many participants it calls, how many call it and when its newest version was published. A tab lists those that never published, and a filter finds one by name. Each participant has four tabs:

- **Overview**: whether its newest version can go to each environment, with the same states as Compatibility, then the participants it calls (its providers) and the participants that call it (its consumers). A GraphQL subgraph deployed in an environment has a link to its graph on that environment's row, as `graph petstore_graph`.
- **Versions**: every published version, the newest marked, with the environments where each one runs now.
- **Deployments**: every deployment, for all environments or one, with a note when it was a rollback.
- **Checks**: every can-i-deploy answer, or only the blocked ones, each linking to its check page.

A version (`/participants/<name>/versions/<version>`) shows where it stands in each environment (deployed now, blocked, ready, not deployed or not asked), and the contract files exactly as they were published.

A graph (`/graphs/<name>`) shows a GraphQL graph, with the subgraphs deployed in each environment and whether they compose, with every composition error ([The graph page](https://bidirekt.com/docs/graphql/graphs.md#the-graph-page)).

### Environments

![The environment staging: its header and the participants running there now](/media/admin/environment.png)

Environments (`/environments`) lists every environment in its configured order, the order a version goes through them, with how many participants run there and its last deployment. Compatibility and the Overview follow this order. A `write` user moves an environment with ↑ and ↓. Each environment has a header with how many participants run there, its last deployment and how many newest versions are blocked from coming in, linking to Compatibility. It has three tabs:

- **Running now**: each participant running there, with its version and when it was deployed.
- **Deployments**: every deployment to it, with a note when it was a rollback.
- **Checks**: every can-i-deploy answer about it, or only the blocked ones, each linking to its check page.

### Create and change

A `write` user also creates participants and environments, and renames and reorders environments, from these pages:

- **Create participant** and **Create environment** work as [`create-participant`](https://bidirekt.com/docs/reference/cli.md#create-participant) and [`create-environment`](https://bidirekt.com/docs/reference/cli.md#create-environment) do, except that a name already in use is an error: `participant already exists` or `environment already exists`. **Comes after** places a new environment as [`--after`](https://bidirekt.com/docs/reference/cli.md#create-environment) does. A participant can't take the name of a GraphQL graph either ([create-participant](https://bidirekt.com/docs/reference/cli.md#create-participant)).
- **Rename** an environment at any time, from its page or with `POST /api/environments/rename` and `{"oldName":"production","newName":"prod"}`. Its deployments and checks stay with it, and each stored check keeps the name the environment had when it was asked. A pipeline that still passes the old name gets `environment not found` until it is updated.

## Users

![The Users page: the admin and an invited write user, with Edit, API keys, New invite link and Deactivate](/media/admin/users.png)

The admin is the only one who manages users, on the Users page (`/users`):

- **Invite a user** with an email and a [permission](#permissions), `read` or `write`. The broker shows an invite link once: send it to them. It works once, for 24 hours.
- The user opens the link, sets a password of 8 to 128 characters, and signs in with their email.
- **Edit** changes a user's email or permission. **Deactivate** ends their sessions at once, revokes their API keys and stops their link; **Reactivate** lets them in again, with no API keys. Users are never deleted.
- **New reset link** gives an active user a link to set a new password, **New invite link** gives an invited user a new invite. Each new link stops the previous one.
- **API keys** lists the user's keys, as in [API keys](#api-keys).
