Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cors settings #103

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
12 changes: 11 additions & 1 deletion roles/artemis/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,18 @@ node_display_name: Unnamed Artemis Node

##############################################################################
# CORS Configuration
# This is the default config to work with scorpio and theia
##############################################################################
#artemis_CORS_allowed_origins: "*"

# artemis_cors:
# allowed_methods: "*"
# allowed_headers: "*"
# exposed_headers: "Authorization,Link,X-Total-Count,Set-Cookie"
# allow_credentials: true
# max_age: 1800
# allowed_origins:
# - "vscode-file://vscode-app"
# - "vscode-webview://*"
Comment on lines +278 to +286
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it makes sense to have this as a default if theia is defined?


##############################################################################
# Auto-generated Variables - No not alter!
Expand Down
8 changes: 5 additions & 3 deletions roles/artemis/templates/application-prod.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -360,9 +360,11 @@ jhipster:
token-validity-in-seconds-for-remember-me: 2592000 # Token is valid 30 days
{% endif %}

{% if artemis_CORS_allowed_origins is defined and artemis_CORS_allowed_origins is not none %}
cors:
allowed-origins: {{ artemis_CORS_allowed_origins }}
{% if artemis_cors is defined and artemis_cors is not none %}
artemis_cors:
{% for key, value in cors.items() %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably should be artemis_cors instead of cors

Suggested change
{% for key, value in cors.items() %}
{% for key, value in artemis_cors.items() %}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also why do you iterate through the dict and then convert each entry to yaml instead of just converting the entire dict directly to yaml?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another question: I see the point of not hard coding the keys and having the option of the dynamic configuration, but in the artemis.env.j2 file the keys are hard coded.

Therefore, I would prefer an homogeneous approach and that the keys are hard coded here as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I reiterated over that because I need a similar approach for something else (Theia configuration). Thus, I came up with a potential approach for a dynamic configuration in the environment file.

{{ key }}: {{ value | to_nice_yaml(indent=2) | trim }}
{% endfor %}
{% endif %}

{% if is_multinode_install|bool == true and artemis_jhipster_registry_password is not none %}
Expand Down
9 changes: 7 additions & 2 deletions roles/artemis/templates/artemis.env.j2
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,13 @@ JHIPSTER_SECURITY_AUTHENTICATION_JWT_BASE64SECRET='{{ artemis_jhipster_jwt }}'
JHIPSTER_SECURITY_AUTHENTICATION_JWT_TOKENVALIDITYINSECONDS='259200'
JHIPSTER_SECURITY_AUTHENTICATION_JWT_TOKENVALIDITYINSECONDSFORREMEMBERME='2592000'
{% endif %}
{% if artemis_CORS_allowed_origins is defined and artemis_CORS_allowed_origins is not none %}
JHIPSTER_CORS_ALLOWEDORIGINS='{{ artemis_CORS_allowed_origins }}'
{% if artemis_cors is defined and artemis_cors is not none %}
JHIPSTER_CORS_ALLOWEDMETHODS='{{ artemis_cors.allowed_methods | join(',') }}'
JHIPSTER_CORS_ALLOWEDHEADERS='{{ artemis_cors.allowed_headers | join(',') }}'
JHIPSTER_CORS_EXPOSEDHEADERS='{{ artemis_cors.exposed_headers }}'
JHIPSTER_CORS_ALLOWCREDENTIALS='{{ artemis_cors.allow_credentials }}'
JHIPSTER_CORS_MAXAGE='{{ artemis_cors.max_age }}'
JHIPSTER_CORS_ALLOWEDORIGINS='{{ artemis_cors.allowed_origins | join(',') }}'
Comment on lines +252 to +257
Copy link
Member

@bensofficial bensofficial Oct 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
JHIPSTER_CORS_ALLOWEDMETHODS='{{ artemis_cors.allowed_methods | join(',') }}'
JHIPSTER_CORS_ALLOWEDHEADERS='{{ artemis_cors.allowed_headers | join(',') }}'
JHIPSTER_CORS_EXPOSEDHEADERS='{{ artemis_cors.exposed_headers }}'
JHIPSTER_CORS_ALLOWCREDENTIALS='{{ artemis_cors.allow_credentials }}'
JHIPSTER_CORS_MAXAGE='{{ artemis_cors.max_age }}'
JHIPSTER_CORS_ALLOWEDORIGINS='{{ artemis_cors.allowed_origins | join(',') }}'
{% for key, value in artemis_cors.items() %}
JHIPSTER_CORS_{{ key | upper | regex_replace ("[^A-Z0-9]","") }}='{{ value | join(',') }}'
{% endfor %}

{% endif %}
{% if is_multinode_install|bool == true and artemis_jhipster_registry_password is not none %}
JHIPSTER_REGISTRY_PASSWORD='{{ artemis_jhipster_registry_password }}'
Expand Down