@stacc/services-ambita-realty
v2.8.0
Published
An API that proxies the Ambita Realty API
Readme
Stacc Ambita Realty Proxy API
An API that proxies the Ambita Realty API
Requirements
To run and try out this API locally, a .env file must be included with the correct credentials:
API_URL=<API_URL>
AUTH_URL=<AUTH_URL
AMBITA_CLIENT_ID=<AMBITA_CLIENT_ID>
AMBITA_CLIENT_SECRET=<AMBITA_CLIENT_SECRET>
AMBITA_USERNAME=<AMBITA_USERNAME>
AMBITA_PASSWORD=<AMBITA_PASSWORD>After this is setup, run the following command at the project's root:
$ npm install && npm run dev
Try out the API locally with REST client (Visual Studio Code)
- Install a REST client for your IDE
- VSCode: https://marketplace.visualstudio.com/items?itemName=humao.rest-client
- Add a settings.json file to your .vscode folder and include the following:
{ "rest-client.environmentVariables": { "$shared":{ "nin1": "<enter your nin here>", "nin2": "<enter your nin here>" }, "local": { }, "production": { } } }- !! Always make sure to not commit sensitive personal data to the VCS !!
$ npm run dev- You should now be abvle to run the requests in the src/requests folder.
For other IDE's, follow the documentation and makes sure to .gitignore any files containing sensitive information:
- Webstorm: https://www.jetbrains.com/help/webstorm/exploring-http-syntax.html#using_request_vars
Blocc
Deployment paths
This repo ships two, side by side, from the same source and the same release tag:
- Helm —
helm/, built and pushed bybuild-and-publish.yamlon a published release. The chart, its values, the image name and that workflow are unchanged. Two changes reach the helm image as well, both inert for it; see What differs from helm. - Blocc module —
module.yaml, published asstacc-classic/ambita-realty, with one component,api(Backend), which lives at the repo root (path: .) and builds from the same Dockerfile. It is published to the blocc registry bypublish-blocc-module.yamlon the same release. The leadingvis stripped, so tagv2.7.0becomes module version2.7.0.
version.yaml cuts a release on every push to
main, so both workflows fire together.
The old root module.yaml (the legacy stacc-registry manifest, name:
services-ambita) and backend.yaml are gone. The manifest pointed at a
backends/my-backend that never existed, so nothing could have been published
from it. The npm SDK (@stacc/services-ambita-realty, lib/) is unaffected.
Helm values → module schema
| Helm value (values.yaml) | Module property | Env var | Note |
| --- | --- | --- | --- |
| authUrl | authUrl | AUTH_URL | same default: Ambita BETA |
| apiUrl | apiUrl | API_URL | same default: Ambita BETA |
| credentials.clientId (STACC_BETA_TOS_1) | credentials.clientId | AMBITA_CLIENT_ID | same default |
| credentials.username (STACC_BANK) | credentials.username | AMBITA_USERNAME | same default |
| Secret <secretName>, key client-secret | credentials.clientSecret | AMBITA_CLIENT_SECRET | secret: true, required |
| Secret <secretName>, key password | credentials.password | AMBITA_PASSWORD | secret: true, required |
| — (app default 25000) | timeout ("25000") | TIMEOUT | new; string, milliseconds |
| port (6060) | fixed in component.yaml | PORT | ports.internal: 6060; not configurable |
| resourceProfile (large) | resourceProfiles.small / large | — | same figures; pick with spec.resourceProfile |
| secretName | — | — | replaced by the two secret: true properties |
| deployment.env | — | — | no equivalent; the service reads nothing else |
| image.* | — | — | blocc builds and addresses the image |
Both URLs default to Ambita's BETA environment, as they do in the chart. A
production solution must set authUrl and apiUrl to
https://api.ambita.com/authentication/v2/token and
https://api.ambita.com/realty/v1. A beta token is not valid against production,
and the reverse.
credentials.clientId and credentials.username default to Stacc's beta
account, as in the chart. If you supply secrets for any other account, set both
alongside them. A mismatch fails the token request, which currently crashes the
service (see Known issues).
What differs from helm
- The Dockerfile's
USER nodeis nowUSER 1000:1000. It is the same user. blocc's pod security context setsrunAsNonRootwithout arunAsUser, and the kubelet refuses a named user under that rule because it cannot prove the user is not root. The chart already forcesrunAsUser: 1000/runAsGroup: 1000, so the helm pod is unchanged. This keepsenableSecurityContexton, so the blocc pod is at least as locked down as the helm one. - A root
.dockerignorenow bounds the build context, for both paths. It keeps.git,helm/,examples/,.envand the blocc YAML out of the builder stage. The runtime image only ever tookdist/andpackage*.jsonfrom that stage, so its contents do not change. - Probes. The chart declares none; the module probes
/livezand/readyz. Both are bare 200s and say nothing about Ambita or the credentials. - Autoscaling is off, matching the chart's fixed
replicas: 1. loggingdoes nothing. The service logs with bareconsole.*andmorgan('dev'), and ignoresLOG_LEVEL/LOG_FORMAT.
Known issues (both paths, pre-existing)
These are in src/, not the packaging, and behave the same under helm:
- Wrong credentials kill the process.
authorizeMiddlewareis an async Express 4 middleware with notry/catch. When Ambita refuses the token request, the rejection is unhandled and Node exits on the first/apicall. The caller seessocket hang up/ECONNRESET, not a 401, and the pod restarts. The probes don't catch this: they never touch Ambita. - That crash prints the credentials. The unhandled
AxiosErroris dumped to stdout with its request body, which is the form-encodedclient_secretandpassword. - Every request logs the bearer token.
console.debug("Token is active. Reusing", cachedToken)runs on each/apicall.console.debugis not level-gated in Node. - Request paths carry national identity numbers
(
/api/persons/<nin>/...), andmorganlogs every path.
Reaching the service in-cluster
Both paths expose the same API the same way: a ClusterIP Service on port
80, forwarding to the container's 6060. Only the Service name differs:
| Path | Service | Name comes from |
| ----- | ------------------- | --------------- |
| Helm | <release name> | {{ .Release.Name }} — often services-ambita-realty, but whatever the release was called |
| Blocc | ambita-realty-api | <module alias>-<component> |
curl http://services-ambita-realty/api/persons/<nin>/properties # helm, release "services-ambita-realty"
curl http://ambita-realty-api/api/persons/<nin>/properties # bloccThe blocc name is not fixed by this repo either. ambita-realty-api is what
you get with the conventional alias. A solution installs the module under a key
in spec.modules, and blocc names every resource <that key>-<component>:
spec:
modules:
realty: # → Service `realty-api`
org: stacc-classic
name: ambita-realtySo module.yaml's metadata.name does not determine the address. The
consuming solution's alias does. Callers should treat the host as configuration.
The example solution's handler hardcodes it only because it owns the solution it
runs in.
Never give the api an apps entry in a solution. It has no inbound
authentication and answers with Stacc's Ambita credentials, so an app would
publish property ownership by national identity number on a public hostname, at
Stacc's expense per lookup. From a laptop, port-forward the Service instead:
kubectl -n <namespace> port-forward svc/<release name> 6060:80 # helm
kubectl -n <namespace> port-forward svc/ambita-realty-api 6060:80 # bloccPort 6060 locally means the .rest files under src/requests work unchanged.
Breaking changes
From helm: the service moves
http://<release name> → http://ambita-realty-apiThe paths (/api/persons, /api/cadastres, /api/shares, the /api/*
pass-through to Ambita, /livez, /readyz), the responses and the port are
identical. The configuration changes:
- the two secrets become module properties instead of a Kubernetes Secret named
by
secretName; deployment.envhas no equivalent.
Nothing routes between the two, so during a migration both can run side by side and each caller has to be pointed at one explicitly.
From an earlier blocc module
There is none. The blocc registry has no ambita or ambita-realty module
under stacc or stacc-classic, so stacc-classic/ambita-realty is the first.
There are no old keys to migrate and no removed components.
Trying the blocc module
examples/test-solution runs the module
with a small Flow process and a Case Manager around it. It needs Stacc's Ambita
beta secrets in your shell:
export AMBITA_CLIENT_SECRET='...' AMBITA_PASSWORD='...'
cd examples/test-solution
blocc config set # build-context, deploy-context, environment=dev
blocc syncSee its README for port-forwarding, the
process, and a working curl.
