Skip to content

Commit 79c83ed

Browse files
authored
Merge pull request #21 from googlemaps-samples/update-rmi-cli-tools-20260206-170453
RMI CLI tools - initial
2 parents d1493c5 + b22127b commit 79c83ed

11 files changed

Lines changed: 2340 additions & 0 deletions
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# RMI Command-line Tools
2+
3+
This tool provides scriptable access to the Roads Management Insights (RMI) service. It includes ready-to-use workflows and standalone API clients designed for easy integration into data pipelines and development environments.
4+
5+
## Architecture & Workflow
6+
7+
The following diagram illustrates how these scripts interact with both Google-managed and customer-managed projects:
8+
9+
```mermaid
10+
graph TD
11+
subgraph Google ["Google-Managed Project (maps-platform-roads-management)"]
12+
DX[Analytics Hub Data Exchange]
13+
TOPIC[Pub/Sub Topics]
14+
end
15+
16+
subgraph RMI_PROJ ["Customer RMI Project"]
17+
RSA[Roads Selection API]
18+
S1[project_rmi_setup.sh]
19+
S3[rmi_verify_api_access.sh]
20+
end
21+
22+
subgraph DATA_PROJ ["Customer Data Project"]
23+
BQ[BigQuery Linked Dataset]
24+
SUB[Pub/Sub Subscription]
25+
S2[project_cloud_setup.sh]
26+
end
27+
28+
S1 -- "Configures" --> RSA
29+
S3 -- "Tests CRUD on" --> RSA
30+
31+
DX -- "Subscribe" --> BQ
32+
TOPIC -- "Subscribe" --> SUB
33+
34+
S2 -- "Configures APIs & Subscriptions" --> DATA_PROJ
35+
36+
subgraph Operations ["Maintenance & Security"]
37+
S4[rmi_data_backup.sh]
38+
S5[project_optional_vpcsc.sh]
39+
end
40+
41+
S4 -- "Backs up from" --> RSA
42+
S4 -- "Copies to" --> BQ
43+
S5 -- "Generates Rules for" --> Google
44+
S5 -- "Generates Rules for" --> DATA_PROJ
45+
```
46+
47+
## Getting Started
48+
49+
1. **Prerequisites**:
50+
* Ensure the [Google Cloud CLI (`gcloud`)](https://cloud.google.com/sdk/docs/install) is installed and in your PATH.
51+
* Ensure `jq` is installed for JSON processing.
52+
53+
2. **Authenticate**:
54+
```bash
55+
gcloud auth application-default login
56+
```
57+
58+
3. **Make Executable**:
59+
```bash
60+
chmod +x clients/*.sh scenarios/*.sh
61+
```
62+
63+
## Project Awareness
64+
65+
A typical RMI implementation involves two distinct Google Cloud projects. Throughout this tool and its documentation, we intentionally distinguish between them to ensure operations are performed in the correct context:
66+
67+
1. **RMI Project (`PROJECT_RMI_ID`)**: This is the project where you enable the **Roads Selection API** and register your **Routes of Interest**. It acts as the "Control Plane" for your RMI configuration.
68+
2. **Data Project (`PROJECT_CLOUD_ID`)**: This is the project where data is accumulated and consumed. It contains your **BigQuery linked datasets** (via Analytics Hub) and **Pub/Sub subscriptions** for real-time streams.
69+
70+
*Note: While these can be the same project, RMI's architecture allows them to be separate to satisfy different security, billing, or organizational requirements. Always verify you are using the intended Project ID for each command.*
71+
72+
---
73+
74+
## 1. Functional Scenarios (Recommended for Setup)
75+
76+
The most common tasks are bundled into "Scenarios" in the `scenarios/` directory. These scripts are modular; run them with `all` for a full run, or call individual `step_` functions for granular control. Call any script without arguments to see detailed usage.
77+
78+
### `project_rmi_setup.sh`
79+
Configures the primary Google Cloud project for RMI API access.
80+
* **Action:** Enables APIs and grants `roles/roads.roadsSelectionAdmin`.
81+
* **Usage:** `./scenarios/project_rmi_setup.sh all <PROJECT_RMI_ID> [MEMBER]`
82+
83+
### `project_cloud_setup.sh`
84+
Configures the project used for data accumulation (BigQuery) and real-time streams (Pub/Sub).
85+
* **Action:** Enables BigQuery/Analytics Hub APIs and provides modular helpers for subscriptions.
86+
* **Usage:** `./scenarios/project_cloud_setup.sh all <PROJECT_CLOUD_ID> [MEMBER]`
87+
88+
### `rmi_verify_api_access.sh`
89+
Performs a complete CRUD (Create, Read, List, Delete) cycle to verify API connectivity.
90+
* **Action:** Creates a temporary route, verifies it, and deletes it.
91+
* **Usage:** `./scenarios/rmi_verify_api_access.sh all <PROJECT_RMI_ID>`
92+
93+
### `rmi_data_backup.sh`
94+
Manages the preservation of your preview data.
95+
* **Action:** Backs up `SelectedRoutes` to JSON and copies BigQuery tables to a destination dataset or GCS.
96+
* **Usage:** `./scenarios/rmi_data_backup.sh all <PROJECT_RMI_ID> <PROJECT_CLOUD_ID> <SRC_DATASET_PROJ> <SRC_DATASET_NAME>`
97+
98+
### `project_optional_vpcsc.sh`
99+
Generates YAML snippets for VPC Service Controls.
100+
* **Action:** Creates Ingress and Egress rules to allow data flow through service perimeters.
101+
* **Usage:** `./scenarios/project_optional_vpcsc.sh all <PROJECT_CLOUD_ID> <MEMBER_LIST>`
102+
103+
---
104+
105+
## 2. Standalone API Clients
106+
107+
For custom integrations, use the bundled building blocks in the `clients/` directory.
108+
109+
### Core Clients (Wraps raw API 1-to-1)
110+
* **`analyticshub_v1.sh`**: Data Exchanges and Listings.
111+
* **`roadsselection_v1.sh`**: Roads Selection API.
112+
* **`routes_v2.sh`**: Directions and Distance Matrix.
113+
114+
### Utility Clients (Pagination helpers)
115+
* **`analyticshub_v1_util.sh`**
116+
* **`roadsselection_v1_util.sh`**
117+
118+
*Example (Sourcing a Utility):*
119+
```bash
120+
source clients/roadsselection_v1_util.sh
121+
# List all routes in your project
122+
roadsselection_v1_projects_selectedRoutes_list_all "projects/$PROJECT_RMI_ID" "100" "$PROJECT_RMI_ID"
123+
```
124+
125+
## License
126+
Apache 2.0

0 commit comments

Comments
 (0)