Skip to content

Commit

Permalink
chore: Integrate a sample REST API (using OpenAPI) into the local env…
Browse files Browse the repository at this point in the history
…ironment (#2482)

* chore: Integrate a sample REST API (using OpenAPI) into the local environment.

* chore: Download example-restapi from artifactory instead

* chore: Remove example-restapi sources as they've been moved to another repo
  • Loading branch information
andresrosenthal authored Dec 19, 2024
1 parent b202590 commit 0b27b27
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ansible/roles/xroad-hurl/files/hurl.env
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ example_service_address=http://xrd-is:8080/example-adapter/Endpoint
is_rest_url=http://xrd-is/integration/mock_1
is_rest_service_code=mock1

is_rest_openapi_url=http://xrd-is:8081/v3/api-docs
is_rest_openapi_service_code=restapi
3 changes: 2 additions & 1 deletion ansible/roles/xroad-is/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
- include_tasks: setup-nginx.yml
- include_tasks: setup-xrd4j.yml
- include_tasks: setup-xrd4j.yml
- include_tasks: setup-restapi.yml
49 changes: 49 additions & 0 deletions ansible/roles/xroad-is/tasks/setup-restapi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---

- name: Set architecture-specific variables
set_fact:
java_arch_path: "{{ ansible_architecture | regex_replace('x86_64', 'amd64') | regex_replace('aarch64', 'arm64') }}"

- name: Set Java home path
set_fact:
java_17_home: "/usr/lib/jvm/java-17-openjdk-{{ java_arch_path }}"

- name: Install required packages
apt:
name:
- openjdk-17-jdk-headless
update_cache: yes
state: present

- name: Get latest example-restapi version
shell: |
curl -s "https://artifactory.niis.org/api/storage/xroad-maven-releases/org/niis/example-restapi/" | \
jq -r '.children[] | select(.uri | match("/[0-9]+.[0-9]+.[0-9]+")) | .uri' | \
sort -V | tail -n1 | tr -d '/'
register: latest_version

- name: Get latest example-restapi artifact URL
shell: |
curl -s "https://artifactory.niis.org/api/storage/xroad-maven-releases/org/niis/example-restapi/{{ latest_version.stdout }}" | \
jq -r '.children[] | select(.uri | endswith("-boot.jar")) | .uri' | \
sort -V | tail -n1 | tr -d '/'
register: artifact_filename

- name: Download example-restapi
get_url:
url: "https://artifactory.niis.org/xroad-maven-releases/org/niis/example-restapi/{{ latest_version.stdout }}/{{ artifact_filename.stdout }}"
dest: /example-restapi.jar
mode: '0644'

- name: Create systemd service
template:
src: templates/example-restapi.service.j2
dest: /etc/systemd/system/example-restapi.service
mode: '0644'

- name: Start and enable example-restapi service
systemd:
name: example-restapi
state: started
enabled: yes
daemon_reload: yes
11 changes: 11 additions & 0 deletions ansible/roles/xroad-is/templates/example-restapi.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=Example REST API
After=network.target

[Service]
Environment="JAVA_HOME={{ java_17_home }}"
ExecStart={{ java_17_home }}/bin/java -jar -Dserver.port=8081 /example-restapi.jar
Restart=always

[Install]
WantedBy=multi-user.target
45 changes: 44 additions & 1 deletion development/hurl/scenarios/setup.hurl
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ HTTP 200



#Register REST service
# Register REST service
POST https://{{ss0_host}}:4000/api/v1/clients/{{ss0_test_service_id}}/service-descriptions
X-XSRF-TOKEN: {{ss0_xsrf_token}}
{
Expand Down Expand Up @@ -1085,3 +1085,46 @@ X-XSRF-TOKEN: {{ss0_xsrf_token}}
}
]
}

# Register OpenAPI REST service
POST https://{{ss0_host}}:4000/api/v1/clients/{{ss0_test_service_id}}/service-descriptions
X-XSRF-TOKEN: {{ss0_xsrf_token}}
{
"url": "{{is_rest_openapi_url}}",
"type": "OPENAPI3",
"rest_service_code": "{{is_rest_openapi_service_code}}"
}

HTTP 201

[Captures]
ss0_test_rest_openapi_service_service_id: jsonpath "$.id"

# Add TestClient access to OpenAPI REST service's "GET members" endpoint
GET https://{{ss0_host}}:4000/api/v1/services/{{ss0_test_service_id}}%3A{{is_rest_openapi_service_code}}
X-XSRF-TOKEN: {{ss0_xsrf_token}}

HTTP 200

[Captures]
# TODO: Currently, Hurl does not support combining multiple filters in JSONPath - https://github.com/Orange-OpenSource/hurl/issues/1697
# TODO: Once it does, replace the jsonpath below with following: "$.endpoints[?(@.path == '/api/members' && @.method == 'GET')].id" nth 0
ss0_test_rest_openapi_service_get_members_endpoint_id: jsonpath "$.endpoints[?(@.path == '/api/members')].id" nth 0

POST https://{{ss0_host}}:4000/api/v1/endpoints/{{ss0_test_rest_openapi_service_get_members_endpoint_id}}/service-clients
X-XSRF-TOKEN: {{ss0_xsrf_token}}
{
"items": [
{
"id": "DEV:COM:4321:TestClient",
"name": "Test client",
"service_client_type": "SUBSYSTEM"
}
]
}

HTTP 201

# Enable OpenAPI REST service
PUT https://{{ss0_host}}:4000/api/v1/service-descriptions/{{ss0_test_rest_openapi_service_service_id}}/enable
X-XSRF-TOKEN: {{ss0_xsrf_token}}
3 changes: 3 additions & 0 deletions development/hurl/scenarios/vars.env
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ example_service_address=http://issoap:8080/example-adapter/Endpoint
is_rest_url=http://isrest:8080/integration/mock_1
is_rest_service_code=mock1

is_rest_openapi_url=http://isrest:8081/v3/api-docs
is_rest_openapi_service_code=restapi

is_rest_payloadgen_url=http://payloadgen:8080
is_rest_payloadgen_service_code=payloadgen

0 comments on commit 0b27b27

Please sign in to comment.