From 64a219e7da2ff55ee419b30d45fbec2cb9f54018 Mon Sep 17 00:00:00 2001 From: Suriya Date: Mon, 3 Aug 2026 17:56:09 +0530 Subject: [PATCH] Stop tracking .env MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It has been in the repository since the initial commit carrying the live database host, user and password. Removing it from the index stops that getting worse; the credentials are still in history and should be rotated, which needs coordinating with everything that reads them. Deployments should pass configuration as container environment rather than shipping a file — a file on disk is one `git add -f` away from being committed again. Also closes the last untested path: a shopper registration published over the broker rather than posted over HTTP. All three MQTT topics — order, customer and health — have now been fired against the live Mosquitto instance and acknowledged. Co-Authored-By: Claude Opus 5 --- .env | 21 --------------------- .gitignore | 8 ++++++++ scratch/dbinspect/cleanup.go | 28 +++++++++++++++++----------- scratch/mqttpub/main.go | 28 +++++++++++++++++++++++++++- 4 files changed, 52 insertions(+), 33 deletions(-) delete mode 100644 .env diff --git a/.env b/.env deleted file mode 100644 index 8a9f2fa..0000000 --- a/.env +++ /dev/null @@ -1,21 +0,0 @@ -APP_PORT=1009 -DB_HOST=66.116.207.225 -DB_PORT=5433 -DB_NAME=nearledb -DB_USER=admin -DB_PASSWORD="Package@123#" - -# --- Catalogue Postgres / pgvector (separate DB, read-only integration) --- -CATALOGUE_DB_HOST=31.97.228.132 -CATALOGUE_DB_PORT=6054 -CATALOGUE_DB_NAME=pgvector -CATALOGUE_DB_USER=admin -CATALOGUE_DB_PASSWORD="'Package@321#'" - -# --- DigitalOcean Spaces (S3-compatible), catalogue product images --- -USE_S3=true -S3_ACCESS_KEY=DO801G8Q8JAZKF49U3WJ -S3_SECRET_KEY=lBQExYfkVqH+ybmGVmQH5MkThBbrIohA/VQLgcPUvug -S3_ENDPOINT=https://nearle.sgp1.digitaloceanspaces.com -S3_BUCKET=nearle -S3_REGION=sgp1 diff --git a/.gitignore b/.gitignore index b24d71e..39cfaf9 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,11 @@ Thumbs.db *.mov *.wmv + +# Local configuration. Tracked until 2026-08-03, which put the database +# credentials in this repository's history — removing it from the index stops +# that getting worse, but the existing history still has them and the password +# should be rotated. +.env +.env.* +!.env.example diff --git a/scratch/dbinspect/cleanup.go b/scratch/dbinspect/cleanup.go index ca89829..6398520 100644 --- a/scratch/dbinspect/cleanup.go +++ b/scratch/dbinspect/cleanup.go @@ -15,7 +15,8 @@ import ( // The two test bills are named explicitly rather than deleted by date or by // "everything in pos_orders" — a table that will hold real takings tomorrow is // not one to run an unbounded DELETE against. -const probeMobile = "9840012345" +// Every mobile the probes registered, so a cleanup run leaves nothing behind. +var probeMobiles = []string{"9840012345", "9840099999", "9840077777"} var testOrderIDs = []string{ "11111111-2222-4333-8444-555555555555", // the HTTP probe @@ -70,16 +71,21 @@ func cleanup(db *gorm.DB) { // The shopper the probes created. Removed only when nothing references it — // a customer row attached to a real order is not test data any more. - var referenced int - db.Raw(`SELECT COUNT(*) FROM orders WHERE customerid = - (SELECT MIN(customerid) FROM customers WHERE contactno = ?)`, - probeMobile).Scan(&referenced) - if referenced > 0 { - fmt.Printf(" customer %s left in place — %d order(s) reference it\n", - probeMobile, referenced) - } else { - res := db.Exec(`DELETE FROM customers WHERE contactno = ?`, probeMobile) - fmt.Printf(" removed %d probe customer row(s)\n", res.RowsAffected) + for _, mobile := range probeMobiles { + // A customer row attached to a real order is not test data any more. + var referenced int + db.Raw(`SELECT COUNT(*) FROM orders WHERE customerid IN + (SELECT customerid FROM customers WHERE contactno = ?)`, + mobile).Scan(&referenced) + if referenced > 0 { + fmt.Printf(" customer %s left in place — %d order(s) reference it\n", + mobile, referenced) + continue + } + res := db.Exec(`DELETE FROM customers WHERE contactno = ?`, mobile) + if res.RowsAffected > 0 { + fmt.Printf(" removed probe customer %s\n", mobile) + } } var balance float64 diff --git a/scratch/mqttpub/main.go b/scratch/mqttpub/main.go index df9d1cf..562252b 100644 --- a/scratch/mqttpub/main.go +++ b/scratch/mqttpub/main.go @@ -118,5 +118,31 @@ func main() { log.Fatal("publish health:", t.Error()) } fmt.Println("\npublished a heartbeat to", healthTopic) - time.Sleep(2 * time.Second) + + // The registration uplink. Tested over HTTP early on; this is the same + // service reached over the broker, which is the path a real till uses. + custBatch, _ := json.Marshal(map[string]any{ + "schema": 1, "batch_id": "batch-cust-mqtt-0001", + "store_id": locationID, "terminal_id": terminalID, + "customers": []map[string]any{{ + "id": "3d7a0000-0000-4000-8000-000000000001", + "mobile": "9840077777", + "name": "MQTT Probe Shopper", + "registered_at": time.Now().UTC().Format(time.RFC3339), + "registered_by_terminal": terminalID, + }}, + }) + custTopic := fmt.Sprintf("nearle/pos/%s/%s/customer", locationID, terminalID) + if t := client.Publish(custTopic, 1, false, custBatch); t.Wait() && t.Error() != nil { + log.Fatal("publish customer:", t.Error()) + } + fmt.Println("published a registration to", custTopic) + + select { + case payload := <-acks: + fmt.Println(" registration ACK:", string(payload)) + case <-time.After(20 * time.Second): + fmt.Println(" NO ACK for the registration") + os.Exit(1) + } }