This guide helps you verify that your Fleet Engine authorization setup is
complete, and that you can create a trial vehicle. This guide uses
the gcloud
command line utility to test
authorization token signing and vehicle creation.
To complete this process, do the following:
- Replace the fields below with the data you created as part of the setup:
Field | Replace with |
---|---|
Your Cloud project ID. | |
The email address of a service account you've created with the Admin role. See Mobility service account roles for details. | |
OR |
A random ID for the vehicle. The ID can contain a maximum of 64 characters. |
Use the
gcloud
utility to log into the Google Cloud account and set the active project on your workstation:gcloud auth login gcloud config set project
PROJECT_ID Create a JSON Web Token (JWT) claim for the vehicle creation:
cat > claim.jwt << EOM { "iss": "
SERVICE_ACCOUNT_EMAIL_ADDRESS ", "sub": "SERVICE_ACCOUNT_EMAIL_ADDRESS ", "aud": "https://fleetengine.googleapis.com/", "iat": $(date +%s), "exp": $((`date +%s` + 3600)), "authorization": { "vehicleid": "VEHICLE_ID " } } EOMcat > claim.jwt << EOM { "iss": "
SERVICE_ACCOUNT_EMAIL_ADDRESS ", "sub": "SERVICE_ACCOUNT_EMAIL_ADDRESS ", "aud": "https://fleetengine.googleapis.com/", "iat": $(date +%s), "exp": $((`date +%s` + 3600)), "authorization": { "deliveryvehicleid": "DELIVERY_VEHICLE_ID " } } EOMUse
gcloud
to sign this JWT with the appropriate IAM permissions. :gcloud iam service-accounts sign-jwt claim.jwt output.jwt \ --iam-account=
SERVICE_ACCOUNT_EMAIL_ADDRESS The signed JWT is stored in
output.jwt
.For details, see Provide required permissions and the
gcloud
command line guide in the Google Cloud documentation.Use
curl
to create a test vehicle on Fleet Engine:curl -X POST "https://fleetengine.googleapis.com/v1/providers/
PROJECT_ID /vehicles?vehicleId=VEHICLE_ID " \ -H "Content-type: application/json" \ -H "Authorization: Bearer $(cat output.jwt)" \ --data-binary @- << EOM { "name": "providers/PROJECT_ID /vehicles/VEHICLE_ID " } EOM { "vehicleState": "OFFLINE", "supportedTripTypes": ["EXCLUSIVE"], "maximumCapacity": 4, "vehicleType": {"category": "AUTO"}, "attributes": [{"key": "on_trip", "value": "false"}] }This command should print the name of the vehicle as output. If you see the following text, your setup is successful.
{ "name": "providers/
PROJECT_ID /vehicles/VEHICLE_ID " }curl -X POST "https://fleetengine.googleapis.com/v1/providers/
PROJECT_ID /deliveryVehicles?deliveryVehicleId=DELIVERY_VEHICLE_ID " \ -H "Content-type: application/json" \ -H "Authorization: Bearer $(cat output.jwt)" \ --data-binary @- << EOM { "name": "providers/PROJECT_ID /deliveryVehicles/DELIVERY_VEHICLE_ID " } EOMThis command should print the name of the delivery vehicle as output. If you see the following text, your setup is successful.
{ "name": "providers/
PROJECT_ID /deliveryVehicles/DELIVERY_VEHICLE_ID " }