Skip to content

Commit

Permalink
Add cross-origin resource sharing for Orion (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisuda committed Jun 13, 2024
1 parent 1bc3828 commit fe810ab
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ ORION=orion
# Expose port 1026 (none, local, all) Default: none
ORION_EXPOSE_PORT=

# Enable cross-origin resource sharing (CORS) Default: false
ORION_CORS=

# Docker image for Orion
IMAGE_ORION=telefonicaiot/fiware-orion:4.0.0

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## FIWARE Big Bang v0.39.0-next

- Add cross-origin resource sharing for Orion (#394)
- Fix maintenance script (#393)

## FIWARE Big Bang v0.39.0 - 09 June, 2024
Expand Down
3 changes: 3 additions & 0 deletions config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ ORION=orion
# Expose port 1026 (none, local, all) Default: none
ORION_EXPOSE_PORT=

# Enable cross-origin resource sharing (CORS) Default: false
ORION_CORS=

# Docker image for Orion
IMAGE_ORION=telefonicaiot/fiware-orion:4.0.0

Expand Down
9 changes: 5 additions & 4 deletions docs/en/installation/orion.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@

You can specify configurations by editing the `config.sh` file.

| Variable name | Description | Default value |
| ------------------- | ------------------------------------- | ------------- |
| ORION | A sub-domain name of Orion. | orion |
| ORION\_EXPOSE\_PORT | Expose port 1026. (none, local, all) | none |
| Variable name | Description | Default value |
| ------------------- | ------------------------------------------- | ------------- |
| ORION | A sub-domain name of Orion. | orion |
| ORION\_EXPOSE\_PORT | Expose port 1026. (none, local, all) | none |
| ORION\_CORS | Enable cross-origin resource sharing (CORS) | false |

## How to setup

Expand Down
1 change: 1 addition & 0 deletions docs/ja/installation/orion.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
| ------------------- | ---------------------------------------------------- | ------ |
| ORION | Orion のサブドメイン名 | orion |
| ORION\_EXPOSE\_PORT | Orion のポート 1026 を公開。(none, local または all) | none |
| ORION\_CORS | Cross-origin resource sharing (CORS) を有効化 | false |

<a name="how-to-setup"></a>

Expand Down
11 changes: 10 additions & 1 deletion lets-fiware.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ set_default_values() {
ORION_EXPOSE_PORT=none
fi

if [ -z "${ORION_CORS=}" ]; then
ORION_CORS=false
fi

if [ -z "${ORION_LD_EXPOSE_PORT}" ]; then
ORION_LD_EXPOSE_PORT=none
fi
Expand Down Expand Up @@ -1958,6 +1962,11 @@ EOF

create_nginx_conf "${ORION}" "nginx-orion"

if "${ORION_CORS}"; then
sed -i "/__NGINX_ORION_CORS_HEADERS__/r ${SETUP_DIR}/template/nginx/nginx-orion-cors-headers" "${NGINX_SITES}/${ORION}"
sed -i "/__NGINX_ORION_CORS_REQUEST_METHOD__/r ${SETUP_DIR}/template/nginx/nginx-orion-cors-request-method" "${NGINX_SITES}/${ORION}"
fi

add_nginx_depends_on "orion"

add_rsyslog_conf "orion"
Expand Down Expand Up @@ -3648,7 +3657,7 @@ setup_end() {
sed -i -e "/# __NGINX_KEYROCK__/d" "${NGINX_SITES}/${KEYROCK}"
fi
if [ -n "${ORION}" ]; then
sed -i -e "/# __NGINX_ORION__/d" "${NGINX_SITES}/${ORION}"
sed -i -e "/# __NGINX_ORION_/d" "${NGINX_SITES}/${ORION}"
fi
if [ -n "${ORION_LD}" ]; then
sed -i -e "/# __NGINX_ORION_LD__/d" "${NGINX_SITES}/${ORION_LD}"
Expand Down
2 changes: 2 additions & 0 deletions setup/template/nginx/nginx-orion
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ server {
add_header Front-End-Https on;
add_header Strict-Transport-Security 'max-age=15768000; includeSubdomains; always';

# __NGINX_ORION_CORS_HEADERS__
location / {
# __NGINX_ORION_CORS_REQUEST_METHOD__
set $req_uri "$uri";
auth_request /_check_oauth2_token;

Expand Down
6 changes: 6 additions & 0 deletions setup/template/nginx/nginx-orion-cors-headers
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Add CORS Headers
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, DELETE, PUT, PATCH' always;
add_header 'Access-Control-Allow-Headers' 'Origin, Content-Type, Accept, Authorization, X-Requested-With, fiware-service, fiware-servicepath' always;
add_header 'Access-Control-Expose-Headers' 'location, fiware-correlator' always;

11 changes: 11 additions & 0 deletions setup/template/nginx/nginx-orion-cors-request-method
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, DELETE, PUT, PATCH' always;
add_header 'Access-Control-Allow-Headers' 'Origin, Content-Type, Accept, Authorization, X-Requested-With, fiware-service, fiware-servicepath' always;
add_header 'Access-Control-Expose-Headers' 'location, fiware-correlator' always;
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}

1 change: 1 addition & 0 deletions tests/script/coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ install_test1() {
sudo apt remove -y rsyslog

sed -i -e "s/^\(ORION_EXPOSE_PORT=\).*/\1local/" config.sh
sed -i -e "s/^\(ORION_CORS=\).*/\1true/" config.sh
sed -i -e "s/^\(CYGNUS=\).*/\1cygnus/" config.sh
sed -i -e "s/^\(COMET=\).*/\1comet/" config.sh
sed -i -e "s/^\(QUANTUMLEAP=\).*/\1quantumleap/" config.sh
Expand Down

0 comments on commit fe810ab

Please sign in to comment.