-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6fac4ee
commit 4bf743d
Showing
37 changed files
with
4,152 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
prototype/1. Technical_ EU STR - Code Single Digital Entry Point/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# str-ap-internal | ||
Development repository used for https://github.com/SEMICeu/STR-AP | ||
|
||
## Setup notes | ||
To generate a local certificate use: https://github.com/FiloSottile/mkcert | ||
|
||
For testing the endpoints | ||
* provided notebook | ||
* [collection.http](collection.http) | ||
|
||
### Swagger | ||
Swagger ui: https://str.local/swagger/index.html | ||
Update of the swagger documentation, can be done by running the following command from the project root: | ||
``` | ||
swag fmt -g ./cmd/str/main.go | ||
swag init -g ./cmd/str/main.go -o docs | ||
``` | ||
|
||
### helm chart setup notes | ||
|
||
``` | ||
cd chart/str | ||
# Create a chart name sparse | ||
helm create str | ||
# Uninstall | ||
helm uninstall str -n str | ||
# Create or update | ||
helm upgrade -i str . --namespace str --create-namespace --set image.password=ghp*** | ||
helm upgrade -i str . --namespace str --create-namespace \ | ||
--set image.password=ghp_*** \ | ||
--set tls.key=$(base64 -i ../../str.local-key.pem) \ | ||
--set tls.crt=$(base64 -i ../../str.local.pem) \ | ||
--set kafka.boostrapServers=pkc-***:9092 \ | ||
--set kafka.username=*** \ | ||
--set kafka.password=*** \ | ||
-f values-local.yaml | ||
``` |
21 changes: 21 additions & 0 deletions
21
... Code Single Digital Entry Point/str-ap-internal-0.0.28/str-ap-internal-0.0.28/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
FROM alpine | ||
|
||
# Create a new user 'str' with user ID 1001 | ||
RUN adduser -D -u 1001 str | ||
|
||
# Copy files | ||
# todo check the naming of the binary | ||
COPY str-ap-internal /opt/str | ||
COPY docs/ /opt/docs/ | ||
|
||
RUN touch /opt/.env | ||
|
||
# Change ownership of the /opt directory to the new user | ||
RUN chown -R str:str /opt | ||
|
||
WORKDIR /opt | ||
|
||
# Switch user | ||
USER str | ||
|
||
ENTRYPOINT ["/opt/str"] |
228 changes: 228 additions & 0 deletions
228
...gle Digital Entry Point/str-ap-internal-0.0.28/str-ap-internal-0.0.28/EU-STR.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
## Setup | ||
This notebook is a collection of `curl` commands that can be executed in the terminal to validate the API endpoints\. | ||
Besides `curl` also `jq` is used for formatting purposes\. | ||
### client credentials | ||
The `bw` command is the Bitwarden password manager CLI command\. | ||
Replace the CLIENT\_ID value\, with your personal CLIENT\_ID\. And provison your CLIENT\_SECRET | ||
```warp-runnable-command | ||
CLIENT_ID=[Your-ID] \ | ||
CLIENT_SECRET=[Your-Secret] | ||
``` | ||
The client SECRET can also be captured via CLI read\: | ||
```warp-runnable-command | ||
read CLIENT_SECRET | ||
``` | ||
Get an OAUTH token \( from the `/token` endpoint\) | ||
```warp-runnable-command | ||
# Compose the JSON string using jq | ||
DATA=$(jq -n \ | ||
--arg client_id "$CLIENT_ID" \ | ||
--arg client_secret "$CLIENT_SECRET" \ | ||
--arg audience "https://str.eu" \ | ||
--arg grant_type "client_credentials" \ | ||
'{client_id: $client_id, client_secret: $client_secret, audience: $audience, grant_type: $grant_type}') | ||
# Get the token | ||
TOKEN=$(curl -s --request POST \ | ||
--url https://tt-dp-dev.eu.auth0.com/oauth/token \ | ||
--header 'content-type: application/json' \ | ||
--data $DATA | jq -r .access_token ) | ||
``` | ||
### API host | ||
```warp-runnable-command | ||
HOST=eu-str.sdep-pilot.eu | ||
``` | ||
## Test API | ||
### Unauthenticated health endpoint | ||
```warp-runnable-command | ||
curl -s https://$HOST/api/v0/ping | jq -r . | ||
``` | ||
This should return\: | ||
```json | ||
{ | ||
"status": "ok" | ||
} | ||
``` | ||
## Activity data | ||
### Submit of activity data | ||
Multiple records can be posted at ounce\, but will be stored as individual records\. | ||
For demo purposes\, we can set an invalid country code\. | ||
```warp-runnable-command | ||
curl -s -X POST https://$HOST/api/v0/str/activity-data \ | ||
--header "Authorization: Bearer $TOKEN" \ | ||
--header "Content-Type: application/json" \ | ||
--data '{ | ||
"data": [ | ||
{ | ||
"numberOfGuests": 10, | ||
"countryOfGuests": [ | ||
"ITZ", | ||
"NLD" | ||
], | ||
"temporal": { | ||
"startDateTime": "2024-07-21T17:32:28Z", | ||
"endDateTime": "2024-07-25T17:32:28Z" | ||
}, | ||
"address": { | ||
"street": "123 Main St", | ||
"city": "Brussels", | ||
"postalCode": "1000", | ||
"country": "BEL" | ||
}, | ||
"hostId": "placeholder-host-id", | ||
"unitId": "placeholder-unit-id", | ||
"areaId": "placeholder-area-id" | ||
}, | ||
{ | ||
"numberOfGuests": 2, | ||
"countryOfGuests": [ | ||
"BEL" | ||
], | ||
"temporal": { | ||
"startDateTime": "2024-07-21T17:32:28Z", | ||
"endDateTime": "2024-07-25T17:32:28Z" | ||
}, | ||
"address": { | ||
"street": "123 Main St", | ||
"city": "Brussels", | ||
"postalCode": "1000", | ||
"country": "BEL" | ||
}, | ||
"hostId": "placeholder-host-id", | ||
"unitId": "placeholder-unit-id", | ||
"areaId": "placeholder-area-id" | ||
}, | ||
{ | ||
"numberOfGuests": 3, | ||
"countryOfGuests": [ | ||
"BEL" | ||
], | ||
"temporal": { | ||
"startDateTime": "2024-07-21T17:32:28Z", | ||
"endDateTime": "2024-07-25T17:32:28Z" | ||
}, | ||
"address": { | ||
"street": "123 Main St", | ||
"city": "Brussels", | ||
"postalCode": "1000", | ||
"country": "BEL" | ||
}, | ||
"hostId": "placeholder-host-id", | ||
"unitId": "placeholder-unit-id", | ||
"areaId": "placeholder-area-id" | ||
} | ||
], | ||
"metadata": { | ||
"platform": "booking.com", | ||
"submissionDate": "2024-07-21T17:32:28Z", | ||
"additionalProp1": {} | ||
} | ||
} | ||
' \ | ||
| jq . | ||
``` | ||
Data has been pushed to the Kafka topic\: `activity-data` | ||
|
||
### Only for demonstration purposes\, and if you have an own deployment | ||
We can use `kcat` to list kafka topics and kafka topics content | ||
```warp-runnable-command | ||
kcat -L | ||
``` | ||
```warp-runnable-command | ||
kcat -C -t activity-data -c 20 -f 'Headers: %h || Message value: %s\n' | ||
``` | ||
Confluent Kafka also allows to views data in the topics\: [https\:\/\/confluent\.cloud\/environments\/env\-d19ry\/clusters\/lkc\-1dm6dj\/topics\/activity\-data\/message\-viewer](https://confluent.cloud/environments/env-d19ry/clusters/lkc-1dm6dj/topics/activity-data/message-viewer) | ||
Note also the header data contains the OAUTH2 app name\. | ||
|
||
### Retrieve activity data submitted to the SDEP | ||
```warp-runnable-command | ||
curl -s https://$HOST/api/v0/ca/activity-data \ | ||
--header "Authorization: Bearer $TOKEN" \ | ||
| jq . | ||
``` | ||
Note each consumer has it\'s offset and will only get \"new\" published data\. | ||
|
||
## Listings | ||
### Submit of listings data | ||
```warp-runnable-command | ||
curl -s -X POST https://$HOST/api/v0/str/listings \ | ||
--header "Authorization: Bearer $TOKEN" \ | ||
--header "Content-Type: application/json" \ | ||
--data ' | ||
{ | ||
"data": [ | ||
{ | ||
"registrationNumber": "1234", | ||
"Unit": { | ||
"description": "string", | ||
"floorLevel": "string", | ||
"address": { | ||
"street": "Culliganlaan 5", | ||
"city": "Diegem", | ||
"postalCode": "1831", | ||
"country": "BEL" | ||
}, | ||
"obtainedAuth": true, | ||
"subjectToAuth": true, | ||
"numberOfRooms": 0, | ||
"occupancy": 0, | ||
"purpose": "string", | ||
"type": "string", | ||
"url": "STR-Platform.com/1234" | ||
} | ||
} | ||
], | ||
"metadata": { | ||
"platform": "STR-Platform" | ||
} | ||
} | ||
'\ | ||
| jq . | ||
``` | ||
### Only for demonstration purposes\, and if you have an own deployment | ||
Consuming data from the kafka topic `listings` | ||
```warp-runnable-command | ||
kcat -C -t listings -c 20 -f 'Headers: %h || Message value: %s\n' | ||
``` | ||
### Retrieving listing data | ||
The limit parameter is optional\. | ||
This data retrieval is also incremental and will only return \"new\" data\. | ||
```warp-runnable-command | ||
curl -s https://$HOST/api/v0/ca/listings \ | ||
--header "Authorization: Bearer $TOKEN" \ | ||
| jq . | ||
``` | ||
## Area | ||
### Shape file upload | ||
```warp-runnable-command | ||
curl -s -X POST https://$HOST/api/v0/ca/area \ | ||
--header "Authorization: Bearer $TOKEN" \ | ||
-F "file=@/Users/thierryturpin/GolandProjects/str-ap-internal/BELGIUM_-_Regions.shp" | ||
``` | ||
### List shape files | ||
```warp-runnable-command | ||
curl -s https://$HOST/api/v0/str/area \ | ||
--header "Authorization: Bearer $TOKEN" \ | ||
| jq . | ||
``` | ||
### Download of a shape file | ||
Set the ID returned by the previous command | ||
```warp-runnable-command | ||
curl -s https://$HOST/api/v0/str/area/01J0R0GC700000000000000000 \ | ||
--header "Authorization: Bearer $TOKEN" \ | ||
-o downloaded_shape_file.shp | ||
``` | ||
Verify the downloaded file | ||
```warp-runnable-command | ||
file downloaded_shape_file.shp | ||
``` | ||
### Verify SSL certificate | ||
Only relevant for own deployments\: | ||
```warp-runnable-command | ||
export SERVER_NAME=$HOST | ||
export PORT=443 | ||
openssl s_client -servername $SERVER_NAME -connect $SERVER_NAME:$PORT | openssl x509 -noout -dates | ||
``` |
24 changes: 24 additions & 0 deletions
24
...le Digital Entry Point/str-ap-internal-0.0.28/str-ap-internal-0.0.28/chart/str/Chart.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
apiVersion: v2 | ||
name: str | ||
description: A Helm chart for Kubernetes | ||
|
||
# A chart can be either an 'application' or a 'library' chart. | ||
# | ||
# Application charts are a collection of templates that can be packaged into versioned archives | ||
# to be deployed. | ||
# | ||
# Library charts provide useful utilities or functions for the chart developer. They're included as | ||
# a dependency of application charts to inject those utilities and functions into the rendering | ||
# pipeline. Library charts do not define any templates and therefore cannot be deployed. | ||
type: application | ||
|
||
# This is the chart version. This version number should be incremented each time you make changes | ||
# to the chart and its templates, including the app version. | ||
# Versions are expected to follow Semantic Versioning (https://semver.org/) | ||
version: 0.1.0 | ||
|
||
# This is the version number of the application being deployed. This version number should be | ||
# incremented each time you make changes to the application. Versions are not expected to | ||
# follow Semantic Versioning. They should reflect the version the application is using. | ||
# It is recommended to use it with quotes. | ||
appVersion: "v0.0.27" |
8 changes: 8 additions & 0 deletions
8
...l Entry Point/str-ap-internal-0.0.28/str-ap-internal-0.0.28/chart/str/templates/NOTES.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{{- if .Values.ingress.enabled }} | ||
{{- range $host := .Values.ingress.hosts }} | ||
{{- range .paths }} | ||
Application is exposed via ingress on: | ||
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} | ||
{{- end }} | ||
{{- end }} | ||
{{- end }} |
62 changes: 62 additions & 0 deletions
62
...ntry Point/str-ap-internal-0.0.28/str-ap-internal-0.0.28/chart/str/templates/_helpers.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{{/* | ||
Expand the name of the chart. | ||
*/}} | ||
{{- define "str.name" -}} | ||
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} | ||
{{- end }} | ||
|
||
{{/* | ||
Create a default fully qualified app name. | ||
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). | ||
If release name contains chart name it will be used as a full name. | ||
*/}} | ||
{{- define "str.fullname" -}} | ||
{{- if .Values.fullnameOverride }} | ||
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} | ||
{{- else }} | ||
{{- $name := default .Chart.Name .Values.nameOverride }} | ||
{{- if contains $name .Release.Name }} | ||
{{- .Release.Name | trunc 63 | trimSuffix "-" }} | ||
{{- else }} | ||
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} | ||
{{- end }} | ||
{{- end }} | ||
{{- end }} | ||
|
||
{{/* | ||
Create chart name and version as used by the chart label. | ||
*/}} | ||
{{- define "str.chart" -}} | ||
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} | ||
{{- end }} | ||
|
||
{{/* | ||
Common labels | ||
*/}} | ||
{{- define "str.labels" -}} | ||
helm.sh/chart: {{ include "str.chart" . }} | ||
{{ include "str.selectorLabels" . }} | ||
{{- if .Chart.AppVersion }} | ||
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} | ||
{{- end }} | ||
app.kubernetes.io/managed-by: {{ .Release.Service }} | ||
{{- end }} | ||
|
||
{{/* | ||
Selector labels | ||
*/}} | ||
{{- define "str.selectorLabels" -}} | ||
app.kubernetes.io/name: {{ include "str.name" . }} | ||
app.kubernetes.io/instance: {{ .Release.Name }} | ||
{{- end }} | ||
|
||
{{/* | ||
Create the name of the service account to use | ||
*/}} | ||
{{- define "str.serviceAccountName" -}} | ||
{{- if .Values.serviceAccount.create }} | ||
{{- default (include "str.fullname" .) .Values.serviceAccount.name }} | ||
{{- else }} | ||
{{- default "default" .Values.serviceAccount.name }} | ||
{{- end }} | ||
{{- end }} |
Oops, something went wrong.