Modular logistics and supply chain operating system (LSOS)
JavaScript driver-appfleet-managementfreight-managementinfrastructureinventory-managementlast-mile-deliverylogisticsondemandopen-sourceorder-managementroute-optimizationsupply-chain-managementtracking-and-monitoringtransport-management-systemtransportationwarehouse-management
ci: seed a public inspection link for the contract run
Ronald A. Richardsond49b708ed32f
diff --git a/.github/actions/postman-contract/action.yml b/.github/actions/postman-contract/action.ymlindex b5fc74e9..722ffe86 100644--- a/.github/actions/postman-contract/action.yml+++ b/.github/actions/postman-contract/action.yml@@ -153,6 +153,13 @@ runs:-e "CI_STRIPE_PUBLISHABLE_KEY=${STRIPE_PUBLISHABLE_KEY}" \-e "CI_STRIPE_SECRET_KEY=${STRIPE_SECRET_KEY}" \application php artisan tinker --execute="eval(base64_decode('${CODE}'));" 2>&1 || true)"+ # The inspection link token is the whole credential for the public inspection+ # routes, and the line below prints every SEEDED_ value to the job log. A mask+ # only hides what is written after it, so this one is registered first.+ INSPECTION_LINK_TOKEN="$(printf '%s\n' "$OUT" | grep -oE 'SEEDED_INSPECTION_LINK_TOKEN=[A-Za-z0-9]+' | tail -1 | cut -d= -f2 || true)"+ if [[ -n "$INSPECTION_LINK_TOKEN" ]]; then+ echo "::add-mask::$INSPECTION_LINK_TOKEN"+ fi# Always surface what the seed produced, not only when a step later fails.## The mint runs one PHP snippet inside a single try, so the FIRST fixture that@@ -176,6 +183,7 @@ runs:NETWORK_KEY="$(printf '%s\n' "$OUT" | grep -oE 'MINTED_NETWORK_KEY=network_[A-Za-z0-9]+' | tail -1 | cut -d= -f2 || true)"SECONDARY_ORG_ID="$(printf '%s\n' "$OUT" | grep -oE 'SEEDED_SECONDARY_ORGANIZATION_ID=company_[A-Za-z0-9]+' | tail -1 | cut -d= -f2 || true)"MULTI_ORG_DRIVER_ID="$(printf '%s\n' "$OUT" | grep -oE 'SEEDED_DRIVER_ID=driver_[A-Za-z0-9]+' | tail -1 | cut -d= -f2 || true)"+ INSPECTION_LINK_FORM_ID="$(printf '%s\n' "$OUT" | grep -oE 'SEEDED_INSPECTION_LINK_FORM_ID=[A-Za-z0-9_]+' | tail -1 | cut -d= -f2 || true)"if [[ -z "$KEY" ]]; thenecho "::error::Could not mint an API key from the running stack. Tinker output:"printf '%s\n' "$OUT"@@ -250,6 +258,15 @@ runs:if [[ -n "$MULTI_ORG_DRIVER_ID" ]]; thenecho "multi_org_driver_id=$MULTI_ORG_DRIVER_ID" >> "$GITHUB_OUTPUT"fi+ # The public inspection requests authenticate with a link token alone, and a link+ # can only be minted from the console. Absent only means the FleetOps release on+ # this stack predates inspection links. The token was masked above.+ if [[ -n "$INSPECTION_LINK_TOKEN" && -n "$INSPECTION_LINK_FORM_ID" ]]; then+ echo "inspection_link_token=$INSPECTION_LINK_TOKEN" >> "$GITHUB_OUTPUT"+ echo "inspection_link_form_id=$INSPECTION_LINK_FORM_ID" >> "$GITHUB_OUTPUT"+ else+ echo "::warning::No inspection link seeded; the public inspection requests will 403."+ fiif [[ -n "$PLATFORM_TOKEN" ]]; thenecho "::add-mask::$PLATFORM_TOKEN"echo "platform_token=$PLATFORM_TOKEN" >> "$GITHUB_OUTPUT"@@ -345,6 +362,8 @@ runs:NETWORK_KEY: ${{ steps.key.outputs.network_key }}SECONDARY_ORG_ID: ${{ steps.key.outputs.secondary_organization_id }}MULTI_ORG_DRIVER_ID: ${{ steps.key.outputs.multi_org_driver_id }}+ INSPECTION_LINK_TOKEN: ${{ steps.key.outputs.inspection_link_token }}+ INSPECTION_LINK_FORM_ID: ${{ steps.key.outputs.inspection_link_form_id }}COLLECTIONS: ${{ inputs.collections }}BASE_URL: ${{ inputs.base-url }}NAMESPACE: ${{ inputs.namespace }}@@ -440,6 +459,8 @@ runs:' --env-var "network_key=${NETWORK_KEY}" \' \' --env-var "secondary_organization_id=${SECONDARY_ORG_ID}" \' \' --env-var "multi_org_driver_id=${MULTI_ORG_DRIVER_ID}" \' \+ ' --env-var "inspection_link_token=${INSPECTION_LINK_TOKEN}" \' \+ ' --env-var "inspection_link_form_id=${INSPECTION_LINK_FORM_ID}" \' \' --env-var "payment_reference=ci-contract-payment-reference" \' \' --env-var "push_token=ci-contract-push-token" \' \' "${@:2}"' > "$RUNNER"@@ -565,6 +586,12 @@ runs:-e 's/((sk|rk|pk)_(live|test)_)[A-Za-z0-9]+/\1<redacted>/g' \"$f"done+ # The inspection link token travels in a query string and a form field, not an+ # Authorization header, so the scrub above misses it. It is alphanumeric, so it+ # is safe to use as a pattern as it stands.+ if [[ -n "${INSPECTION_LINK_TOKEN:-}" ]]; then+ sed -i "s/${INSPECTION_LINK_TOKEN}/<redacted>/g" "$ansi" "$log"+ fi# Read executed/failed out of the reporter's summary table. Each row is# "| <label> | <executed> | <failed> |", so match the label plus two numbersdiff --git a/scripts/ci/mint-api-key.php b/scripts/ci/mint-api-key.phpindex 91621396..3513ec59 100644--- a/scripts/ci/mint-api-key.php+++ b/scripts/ci/mint-api-key.php@@ -366,6 +366,66 @@ try {echo 'SEEDED_INSPECTION_FORM_ID=' . $inspectionForm->fresh()->public_id . PHP_EOL;+ /* --------------------------------------------------------+ | Inspection link (public, tokenised form)+ * -------------------------------------------------------- */++ // The public inspection requests (Retrieve a Public Inspection Form, Upload a+ // Public Inspection Photo, Submit a Public Inspection) authenticate with nothing+ // but a link token. Links are minted from the console, and a public request is+ // resolved through the token's hash, so the plaintext can only come from here.+ //+ // Multi-use and a day long, so the retrieve, the upload and the submit can all+ // use it in one run. One link per form for the CI user, reused on reruns; the+ // token is rotated every run, like the platform token above, and used_at cleared+ // so a reused link never reads as spent.+ //+ // Guarded on the `token` column rather than the class alone: the column arrived+ // after the table, and a stack between the two would throw on insert — which,+ // inside this single try, would abort every fixture after it.+ if (class_exists(\Fleetbase\FleetOps\Models\InspectionLink::class)+ && \Illuminate\Support\Facades\Schema::hasColumn('inspection_links', 'token')) {+ $inspectionLink = \Fleetbase\FleetOps\Models\InspectionLink::withoutGlobalScopes()+ ->where([+ 'company_uuid' => $company->uuid,+ 'inspection_form_uuid' => $inspectionForm->uuid,+ 'created_by_uuid' => $user->uuid,+ ])+ // withoutGlobalScopes() drops the soft-delete scope too, and the public+ // lookup would never find a trashed link.+ ->whereNull('deleted_at')+ ->first();++ if (!$inspectionLink) {+ $inspectionLink = new \Fleetbase\FleetOps\Models\InspectionLink();+ $inspectionLink->company_uuid = $company->uuid;+ $inspectionLink->inspection_form_uuid = $inspectionForm->uuid;+ $inspectionLink->created_by_uuid = $user->uuid;+ }++ $inspectionLinkToken = \Fleetbase\FleetOps\Models\InspectionLink::generateToken();++ // The seeded driver, so the public read's identity carries a driver and its+ // "no phone number" assertion has something to check. No vehicle: none has+ // been seeded yet at this point in the script.+ $inspectionLink->driver_uuid = isset($driverRecord) ? $driverRecord->uuid : null;+ $inspectionLink->vehicle_uuid = null;+ $inspectionLink->token_hash = \Fleetbase\FleetOps\Models\InspectionLink::hashToken($inspectionLinkToken);+ $inspectionLink->token = $inspectionLinkToken;+ $inspectionLink->status = 'active';+ $inspectionLink->single_use = false;+ $inspectionLink->expires_at = \Illuminate\Support\Carbon::now()->addDay();+ $inspectionLink->used_at = null;+ $inspectionLink->save();++ echo 'SEEDED_INSPECTION_LINK_TOKEN=' . $inspectionLinkToken . PHP_EOL;+ echo 'SEEDED_INSPECTION_LINK_FORM_ID=' . $inspectionForm->fresh()->public_id . PHP_EOL;+ } else {+ echo '::warning::Inspection links unavailable; the public inspection requests will 403.' . PHP_EOL;+ echo 'SEEDED_INSPECTION_LINK_TOKEN=' . PHP_EOL;+ echo 'SEEDED_INSPECTION_LINK_FORM_ID=' . PHP_EOL;+ }+/* --------------------------------------------------------| Inspection form field groups (custom-field system)* -------------------------------------------------------- */@@ -552,6 +612,8 @@ try {}} else {echo 'SEEDED_INSPECTION_FORM_ID=' . PHP_EOL;+ echo 'SEEDED_INSPECTION_LINK_TOKEN=' . PHP_EOL;+ echo 'SEEDED_INSPECTION_LINK_FORM_ID=' . PHP_EOL;echo 'SEEDED_INSPECTION_FORM_GROUP_IDS=' . PHP_EOL;}