Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,22 @@ npx nx run api-contract:generate:go # regenerate Go models
Codegen runs automatically as a dependency of the `dev`, `build` and `serve` targets — run it
manually only when you want to inspect the output.

### Checking DOKU credentials

```bash
make -C apps/api doku-check # asks DOKU for an access token with apps/api/.env
```

The same check ships as a release binary, so it can be run against the live credentials on the VPS
without a Go toolchain or a build there:

```bash
cd /root/projects/gatherloop-pos/apps/api && ./dist/release/dokucheck
```

It redacts the identifiers it prints so its output is safe to paste or to leave in a CI log; pass
`-show-credentials` to see them in full.

In CI, a pull request runs the `libs/ui` and `apps/api` unit tests, and only the ones whose area it
touches (`.github/workflows/pr-tests.yml`). The end-to-end suites are too slow for that loop, so
they run after the merge, against a MySQL service, the real API binary and a real Next.js server
Expand Down
5 changes: 3 additions & 2 deletions apps/api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@ dev:
build:
go build -o dist/api main.go

## build-release: Build the three static release binaries for the VPS
## build-release: Build the static release binaries for the VPS
build-release:
mkdir -p $(RELEASE_DIR)
$(RELEASE_BUILD) -o $(RELEASE_DIR)/api main.go
$(RELEASE_BUILD) -o $(RELEASE_DIR)/dokucheck ./cmd/dokucheck

## test: Run all tests
test:
go test ./...

## doku-check: Ask DOKU for an access token with the configured credentials
doku-check:
go run ./cmd/dokucheck
go run ./cmd/dokucheck -show-credentials
21 changes: 18 additions & 3 deletions apps/api/cmd/dokucheck/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ import (
"apps/api/data/doku"
"apps/api/utils"
"context"
"flag"
"fmt"
"os"
"time"
)

func main() {
showCredentials := flag.Bool("show-credentials", false, "print credential values in full instead of redacting them")
flag.Parse()

_ = utils.LoadEnv()
env := utils.GetEnv()

Expand All @@ -33,9 +37,9 @@ func main() {
}

fmt.Printf("baseUrl: %s\n", config.BaseURL)
fmt.Printf("clientId: %s\n", config.ClientId)
fmt.Printf("merchantId: %s\n", config.MerchantId)
fmt.Printf("channelId: %s\n", config.ChannelId)
fmt.Printf("clientId: %s\n", format(config.ClientId, *showCredentials))
fmt.Printf("merchantId: %s\n", format(config.MerchantId, *showCredentials))
fmt.Printf("channelId: %s\n", format(config.ChannelId, *showCredentials))

ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
Expand All @@ -51,3 +55,14 @@ func main() {

fmt.Println("\naccess token granted: credentials are valid")
}

// Redacted by default because this output can end up in a public CI log.
func format(value string, show bool) string {
if show {
return value
}
if len(value) <= 8 {
return fmt.Sprintf("<redacted, %d chars>", len(value))
}
return fmt.Sprintf("%s...%s (%d chars)", value[:4], value[len(value)-4:], len(value))
}
Loading