Skip to content

Commit e1ab209

Browse files
authored
Merge pull request #840 from MetaCell/feature/gateway-updates
Feature/gateway updates
2 parents e27c636 + ad45cb2 commit e1ab209

99 files changed

Lines changed: 3213 additions & 458 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/instructions/copilot-instructions.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,10 @@ Verify which application/components is in scope and read specific prompt instruc
2020

2121
Check best practices in every instruction file in scope and docs and apply them when writing code or performing code reviews.
2222
Use reference for any questions regarding project structure, development workflow, and best practices.
23-
If you have any doubts about where to find information, ask for clarification before proceeding.
23+
If you have any doubts about where to find information, ask for clarification before proceeding.
24+
25+
### Development principles
26+
- Follow the best practices and coding style guidelines outlined in the documentation and instruction files.
27+
- Configuration is set on values.yaml files and injected into the application via Helm templates and Kubernetes manifests. Do not hardcode configuration values directly into the application code or templates.
28+
- Structured configuration can be injected via resources, that are process by helm templates and loaded as ConfigMaps automatically. See for instance `applications/accounts/deploy/resources/realm.json`
29+
- The cloud harness configuration API is handled by the models library and defined as [openapi spec](../../libraries/models/api/openapi.yaml). Use `harness-generate models` to generate the models library after making changes to the spec.

.github/instructions/tools.instructions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ Take the following best practices into account when writing code for the project
4949
- Handle exceptions only at the higher level; let lower layers raise. NEVER catch exceptions in helpers or services unless you are adding context and re-raising.
5050
- Cover critical logic with unit tests, especially in helpers and services. Use mocks to isolate units under test.
5151
- Prefer models classes for helpers and services to ensure data validation and clear interfaces. Use typed dicts for structured data that isn't covered by Schema classes. Use plain dicts only to represent real unstructured data. Avoid returning tuples.
52+
- Bubble up exceptions to the highest level possible, where they can be handled. Avoid return values to reflect success or failure. Embed library exceptions and untyped exceptions in custom exceptions with clear meaning and context. This allows for better error handling and debugging.
5253
5354
5455
## Important Constraints

applications/accounts/deploy/resources/realm.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"rememberMe": true,
1313
"verifyEmail": false,
1414
"loginWithEmailAllowed": true,
15+
"organizationsEnabled": {{ .Values.apps.accounts.realm.organizationsEnabled | default false }},
1516
"duplicateEmailsAllowed": false,
1617
"resetPasswordAllowed": true,
1718
"editUsernameAllowed": {{ .Values.apps.accounts.editUsernameAllowed }},

applications/accounts/deploy/values.yaml

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,44 +7,29 @@ harness:
77
port: 8080
88
resources:
99
requests:
10-
memory: "512Mi"
10+
memory: "800Mi"
1111
cpu: "10m"
1212
limits:
13-
memory: "1024Mi"
13+
memory: "1Gi"
1414
service:
1515
auto: true
1616
port: 8080
17-
env:
18-
- name: KC_BOOTSTRAP_ADMIN_USERNAME
19-
value: "admin"
20-
- name: KC_BOOTSTRAP_ADMIN_PASSWORD
21-
value: "metacell"
22-
- name: KC_PROXY_HEADERS
23-
value: xforwarded
24-
- name: KC_DB
25-
value: "postgres"
26-
- name: KC_DB_URL_HOST
27-
value: "keycloak-postgres"
28-
- name: KC_DB_URL_DATABASE
29-
value: "auth_db"
30-
- name: KC_DB_USERNAME
31-
value: "user"
32-
- name: KC_DB_PASSWORD
33-
value: "password"
34-
- name: KC_HTTP_ENABLED
35-
value: "true"
36-
- name: KC_PROXY
37-
value: "edge"
38-
- name: KC_HOSTNAME_STRICT
39-
value: "false"
40-
- name: KC_HOSTNAME_STRICT_HTTPS
41-
value: "false"
42-
- name: KC_HEALTH_ENABLED
43-
value: "true"
44-
- name: KC_METRICS_ENABLED
45-
value: "true"
46-
- name: JAVA_OPTS
47-
value: -server -Xms64m -Xmx896m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED --add-exports=jdk.unsupported/sun.reflect=ALL-UNNAMED
17+
envmap:
18+
KC_BOOTSTRAP_ADMIN_USERNAME: "admin"
19+
KC_BOOTSTRAP_ADMIN_PASSWORD: "metacell"
20+
KC_PROXY_HEADERS: xforwarded
21+
KC_DB: "postgres"
22+
KC_DB_URL_HOST: "keycloak-postgres"
23+
KC_DB_URL_DATABASE: "auth_db"
24+
KC_DB_USERNAME: "user"
25+
KC_DB_PASSWORD: "password"
26+
KC_HTTP_ENABLED: "true"
27+
KC_PROXY: "edge"
28+
KC_HOSTNAME_STRICT: "false"
29+
KC_HOSTNAME_STRICT_HTTPS: "false"
30+
KC_HEALTH_ENABLED: "true"
31+
KC_METRICS_ENABLED: "true"
32+
JAVA_OPTS: "-server -Xms64m -Xmx896m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED --add-exports=jdk.unsupported/sun.reflect=ALL-UNNAMED"
4833
database:
4934
auto: true
5035
name: keycloak-postgres
@@ -87,10 +72,12 @@ admin:
8772
editUsernameAllowed: true
8873
useEvents: true
8974
identityProviders:
90-
- github
91-
- google
75+
- github
76+
- google
9277
theme:
9378
login: "keycloak"
9479
account: "keycloak"
9580
admin: "keycloak"
9681
email: "keycloak"
82+
realm:
83+
organizationsEnabled: false

applications/samples/api/openapi.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,22 @@ paths:
8383
description: |
8484
Check if the token is valid
8585
x-openapi-router-controller: samples.controllers.auth_controller
86+
/db-connect-string:
87+
get:
88+
tags:
89+
- database
90+
summary: Get database connection string
91+
operationId: get_db_connect_string
92+
description: Returns the database connection string for the current application.
93+
responses:
94+
"200":
95+
description: Database connection string returned successfully
96+
content:
97+
application/json:
98+
schema:
99+
type: string
100+
"500":
101+
description: Error retrieving database connection string
86102
/sampleresources:
87103
summary: Path used to manage the list of sampleresources.
88104
description: >-
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
connexion[swagger-ui,flask,uvicorn]>=3.0.0,<4.0.0
2-
swagger-ui-bundle>=1.1.0
3-
python_dateutil>=2.9.0
4-
setuptools>=21.0.0
5-
uvicorn
6-
# Following some unnecessary requirements to make sure they can be installed
7-
psycopg2-binary
8-
sqlalchemy<2.0.0
9-
scipy
1+
connexion[swagger-ui] >= 2.6.0; python_version>="3.6"
2+
# 2.3 is the last version that supports python 3.4-3.5
3+
connexion[swagger-ui] <= 2.3.0; python_version=="3.5" or python_version=="3.4"
4+
# prevent breaking dependencies from advent of connexion>=3.0
5+
connexion[swagger-ui] <= 2.14.2; python_version>"3.4"
6+
# connexion requires werkzeug but connexion < 2.4.0 does not install werkzeug
7+
# we must peg werkzeug versions below to fix connexion
8+
# https://github.com/zalando/connexion/pull/1044
9+
werkzeug == 0.16.1; python_version=="3.5" or python_version=="3.4"
10+
swagger-ui-bundle >= 0.0.2
11+
python_dateutil >= 2.6.0
12+
setuptools >= 21.0.0
13+
Flask == 2.1.1
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import connexion
2+
from typing import Dict
3+
from typing import Tuple
4+
from typing import Union
5+
6+
from samples.models.get_db_connect_string200_response import GetDbConnectString200Response # noqa: E501
7+
from samples import util
8+
9+
10+
def get_db_connect_string(): # noqa: E501
11+
"""Get database connection string
12+
13+
Returns the database connection string for the current application. # noqa: E501
14+
15+
16+
:rtype: Union[GetDbConnectString200Response, Tuple[GetDbConnectString200Response, int], Tuple[GetDbConnectString200Response, int, Dict[str, str]]
17+
"""
18+
from cloudharness.applications import get_current_configuration
19+
config = get_current_configuration()
20+
return config.get_db_connection_string()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from typing import List
2+
3+
4+
def info_from_bearerAuth(token):
5+
"""
6+
Check and retrieve authentication information from custom bearer token.
7+
Returned value will be passed in 'token_info' parameter of your operation function, if there is one.
8+
'sub' or 'uid' will be set in 'user' parameter of your operation function, if there is one.
9+
10+
:param token Token provided by Authorization header
11+
:type token: str
12+
:return: Decoded token information or None if token is invalid
13+
:rtype: dict | None
14+
"""
15+
return {'uid': 'user_id'}
16+
17+
18+
def info_from_cookieAuth(api_key, required_scopes):
19+
"""
20+
Check and retrieve authentication information from api_key.
21+
Returned value will be passed in 'token_info' parameter of your operation function, if there is one.
22+
'sub' or 'uid' will be set in 'user' parameter of your operation function, if there is one.
23+
24+
:param api_key API key provided by Authorization header
25+
:type api_key: str
26+
:param required_scopes Always None. Used for other authentication method
27+
:type required_scopes: None
28+
:return: Information attached to provided api_key or None if api_key is invalid or does not allow access to called API
29+
:rtype: dict | None
30+
"""
31+
return {'uid': 'user_id'}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from datetime import date, datetime # noqa: F401
2+
3+
from typing import List, Dict # noqa: F401
4+
5+
from samples.models.base_model import Model
6+
from samples import util
7+
8+
9+
class GetDbConnectString200Response(Model):
10+
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
11+
12+
Do not edit the class manually.
13+
"""
14+
15+
def __init__(self, connect_string=None): # noqa: E501
16+
"""GetDbConnectString200Response - a model defined in OpenAPI
17+
18+
:param connect_string: The connect_string of this GetDbConnectString200Response. # noqa: E501
19+
:type connect_string: str
20+
"""
21+
self.openapi_types = {
22+
'connect_string': str
23+
}
24+
25+
self.attribute_map = {
26+
'connect_string': 'connect_string'
27+
}
28+
29+
self._connect_string = connect_string
30+
31+
@classmethod
32+
def from_dict(cls, dikt) -> 'GetDbConnectString200Response':
33+
"""Returns the dict as a model
34+
35+
:param dikt: A dict.
36+
:type: dict
37+
:return: The get_db_connect_string_200_response of this GetDbConnectString200Response. # noqa: E501
38+
:rtype: GetDbConnectString200Response
39+
"""
40+
return util.deserialize_model(dikt, cls)
41+
42+
@property
43+
def connect_string(self) -> str:
44+
"""Gets the connect_string of this GetDbConnectString200Response.
45+
46+
47+
:return: The connect_string of this GetDbConnectString200Response.
48+
:rtype: str
49+
"""
50+
return self._connect_string
51+
52+
@connect_string.setter
53+
def connect_string(self, connect_string: str):
54+
"""Sets the connect_string of this GetDbConnectString200Response.
55+
56+
57+
:param connect_string: The connect_string of this GetDbConnectString200Response.
58+
:type connect_string: str
59+
"""
60+
61+
self._connect_string = connect_string

applications/samples/backend/samples/openapi/openapi.yaml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@ tags:
1515
- description: ""
1616
name: resource
1717
paths:
18+
/db-connect-string:
19+
get:
20+
description: Returns the database connection string for the current application.
21+
operationId: get_db_connect_string
22+
responses:
23+
"200":
24+
content:
25+
application/json:
26+
schema:
27+
type: string
28+
description: Database connection string returned successfully
29+
"500":
30+
description: Error retrieving database connection string
31+
summary: Get database connection string
32+
tags:
33+
- database
34+
x-openapi-router-controller: samples.controllers.database_controller
1835
/error:
1936
get:
2037
operationId: error
@@ -336,4 +353,4 @@ components:
336353
in: cookie
337354
name: kc-access
338355
type: apiKey
339-
x-apikeyInfoFunc: samples.controllers.security_controller_.info_from_cookieAuth
356+
x-apikeyInfoFunc: cloudharness.auth.decode_token

0 commit comments

Comments
 (0)