Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
ikethecoder committed May 25, 2024
2 parents cf8a1aa + b69acd1 commit 82eef97
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 5 deletions.
42 changes: 41 additions & 1 deletion microservices/gatewayApi/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
import pytest
import os
import sys
import json
from functools import wraps
import logging
log = logging.getLogger(__name__)
from logging.config import dictConfig

# sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

dictConfig({
'version': 1,
'formatters': {'default': {
'format': '%(asctime)s [%(process)3d] %(levelname)5s %(module)-15s: %(message)s',
}},
'handlers': {'app': {
'class': 'logging.StreamHandler',
'stream': 'ext://flask.logging.wsgi_errors_stream',
'formatter': 'default'
}},
'root': {
'level': 'DEBUG',
'handlers': ['app']
}
})


@pytest.fixture
Expand Down Expand Up @@ -71,7 +90,8 @@ def json():
"next": None
}
return Response
elif (path == 'http://kong/certificates?tags=gwa.ns.mytest'):
elif (path == 'http://kong/certificates?tags=gwa.ns.mytest' or
path == 'http://kong/certificates?tags=gwa.ns.sescookie'):
class Response:
def json():
return {
Expand Down Expand Up @@ -123,6 +143,20 @@ class Response:
# def json():
# return {}
return Response
elif (url == 'http://kube-api/namespaces/sescookie/routes'):
class Response:
status_code = 201
matched = {
'hosts': ['myapi.api.gov.bc.ca'],
'ns_attributes': {'perm-domains': ['.api.gov.bc.ca', '.cluster.local']},
'overrides': {
'aps.route.session.cookie.enabled': ['myapi.api.gov.bc.ca']
},
'select_tag': 'ns.sescookie.dev'
}

assert json.dumps(kwargs['json'], sort_keys=True) == json.dumps(matched, sort_keys=True)
return Response
elif (url == 'http://kube-api/namespaces/ns1/routes'):
class Response:
status_code = 201
Expand All @@ -139,6 +173,12 @@ class Response:
def json():
return {}
return Response
elif (url == 'http://kube-api/namespaces/sescookie/local_tls'):
class Response:
status_code = 200
def json():
return {}
return Response
else:
raise Exception(url)

Expand Down
23 changes: 23 additions & 0 deletions microservices/gatewayApi/tests/routes/v2/test_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,26 @@ def test_happy_sync_gateway_call(client):
response = client.put('/v2/namespaces/mytest/gateway', json=data)
assert response.status_code == 200
assert json.dumps(response.json) == '{"message": "Sync successful.", "results": "Deck reported no changes"}'

def test_happy_with_session_cookie_gateway_call(client):
configFile = '''
services:
- name: my-service
host: myupstream.local
tags: ["ns.sescookie.dev", "another"]
routes:
- name: route-1
hosts: [ myapi.api.gov.bc.ca ]
tags: ["ns.sescookie.dev", "aps.route.session.cookie.enabled"]
plugins:
- name: acl-auth
tags: ["ns.sescookie.dev"]
'''

data={
"configFile": configFile,
"dryRun": False
}
response = client.put('/v2/namespaces/sescookie/gateway', json=data)
assert response.status_code == 200
assert json.dumps(response.json) == '{"message": "Sync successful.", "results": "Deck reported no changes"}'
9 changes: 6 additions & 3 deletions microservices/gatewayApi/v1/routes/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from clients.portal import record_gateway_event
from clients.kong import get_routes
from clients.ocp_networksecuritypolicy import get_ocp_service_namespaces, check_nsp, apply_nsp, delete_nsp
from clients.ocp_routes import get_host_list, prepare_apply_routes, prepare_delete_routes, apply_routes, delete_routes
from clients.ocp_routes import get_host_list, get_route_overrides
from clients.ocp_gateway_secret import prep_submitted_config, prep_and_apply_secret, write_submitted_config

from utils.validators import host_valid
Expand Down Expand Up @@ -330,11 +330,14 @@ def write_config(namespace: str) -> object:
route_payload = {
"hosts": get_host_list(tempFolder),
"select_tag": selectTag,
"ns_attributes": ns_attributes.getAttrs()
"ns_attributes": ns_attributes.getAttrs(),
"overrides": {
"aps.route.session.cookie.enabled": get_route_overrides(tempFolder, "aps.route.session.cookie.enabled")
}
}
dp = get_data_plane(ns_attributes)
log.debug("[%s] - Initiating request to kube API %s" % (dp, route_payload))
rqst_url = app.config['data_planes'][dp]["kube-api"]
log.debug("[%s] - Initiating request to kube API" % (dp))
res = session.put(rqst_url + "/namespaces/%s/routes" % namespace, json=route_payload, auth=(
app.config['kubeApiCreds']['kubeApiUser'], app.config['kubeApiCreds']['kubeApiPass']))
log.debug("[%s] - The kube API responded with %s" % (dp, res.status_code))
Expand Down
2 changes: 1 addition & 1 deletion microservices/gatewayApi/v2/routes/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,8 @@ def write_config(namespace: str) -> object:
"aps.route.session.cookie.enabled": get_route_overrides(tempFolder, "aps.route.session.cookie.enabled")
}
}
log.debug("[%s] - Initiating request to kube API %s" % (dp, route_payload))
rqst_url = app.config['data_planes'][dp]["kube-api"]
log.debug("[%s] - Initiating request to kube API" % (dp))
res = session.put(rqst_url + "/namespaces/%s/routes" % namespace, json=route_payload, auth=(
app.config['kubeApiCreds']['kubeApiUser'], app.config['kubeApiCreds']['kubeApiPass']))
log.debug("[%s] - The kube API responded with %s" % (dp, res.status_code))
Expand Down
2 changes: 2 additions & 0 deletions microservices/kubeApi/clients/ocp_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ def prepare_apply_routes(ns, select_tag, hosts, root_path, data_plane, ns_templa
templ_version = ns_template_version
if overrides and 'aps.route.session.cookie.enabled' in overrides and host in overrides['aps.route.session.cookie.enabled']:
templ_version = 'v1'
else:
logger.debug("[%s] %s No override applied %s", select_tag, hosts, str(overrides))

route_template = ROUTES[templ_version]["ROUTE"]

Expand Down

0 comments on commit 82eef97

Please sign in to comment.