Skip to content

Commit

Permalink
Merge pull request #101 from bcgov/dev
Browse files Browse the repository at this point in the history
gwa cli v2 changes
  • Loading branch information
ikethecoder authored Sep 7, 2023
2 parents f155c27 + 7d26044 commit 56de3a8
Show file tree
Hide file tree
Showing 16 changed files with 597 additions and 652 deletions.
10 changes: 0 additions & 10 deletions microservices/gatewayApi/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@
import v1.v1 as v1
import v2.v2 as v2


def set_cors_headers_on_response(response):
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Headers'] = 'X-Requested-With'
response.headers['Access-Control-Allow-Methods'] = 'OPTIONS'
return response



def create_app(test_config=None):

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -65,7 +56,6 @@ def before_request():

@app.after_request
def after_request(response):
set_cors_headers_on_response(response)
log.debug('Rendered in %ss', g.request_time())
return response

Expand Down
4 changes: 4 additions & 0 deletions microservices/gatewayApi/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ cat > "${CONFIG_PATH:-./config/default.json}" <<EOF
"redis_port": 6379,
"redis_password": "${PLUGINS_RATELIMITING_REDIS_PASSWORD}",
"redis_timeout": 2000
},
"proxy_cache": {
"strategy": "memory",
"memory": { "dictionary_name": "${PLUGINS_PROXYCACHE_MEMORY_DICT:-"aps_proxy_cache"}" }
}
},
"defaultDataPlane": "${DEFAULT_DATA_PLANE:-"dp-silver-kong-proxy"}",
Expand Down
2 changes: 1 addition & 1 deletion microservices/gatewayApi/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cryptography==38.0.4
authlib==0.15.3
flask-swagger-ui==3.36.0
Jinja2==3.0.3
PyYAML==5.4
PyYAML==6.0.1
munch==2.5.0
boto3==1.9.12
flask==2.1.3
Expand Down
2 changes: 1 addition & 1 deletion microservices/gatewayApi/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def setup_swagger_docs (app, versions):
# app.view_functions['blah'] = blah
@app.route("/docs/<ver>/openapi.yaml")
def openapi_spec(ver:str):
return Response(open("%s/%s.yaml" % (conf.data['workingFolder'], ver)).read(), mimetype='application/yaml')
return Response(open("%s/%s.yaml" % (conf.data['workingFolder'], ver)).read(), mimetype='application/x-yaml')

#app.add_url_rule("/%s/docs/openapi.yaml" % version, openapi_spec)
app.register_blueprint(swaggerui_blueprint)
Expand Down
14 changes: 14 additions & 0 deletions microservices/gatewayApi/utils/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@
def plugins_transformations (namespace, yaml):
traverse_plugins (yaml)

def proxy_cache (plugin, plugin_configs=None):
override_config = conf['plugins']['proxy_cache']

if 'config' in plugin:
plugin_config = plugin['config']
else:
plugin['config'] = {}
plugin_config = plugin['config']

for k, v in override_config.items():
plugin_config[k] = v

def rate_limiting (plugin, plugin_configs=None):
override_config = conf['plugins']['rate_limiting']

Expand Down Expand Up @@ -63,6 +75,8 @@ def traverse_plugins (yaml, plugin_configs = None):
if k == 'plugins':
if item['name'] == 'rate-limiting':
rate_limiting(item, plugin_configs)
elif item['name'] == 'proxy-cache':
proxy_cache(item, plugin_configs)
traverse_plugins (item, plugin_configs)


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 @@ -173,7 +173,7 @@ def write_config(namespace: str) -> object:
for route in all_routes:
if tag_match not in route['tags'] and 'hosts' in route:
for host in route['hosts']:
reserved_hosts.append(transform_host(host))
reserved_hosts.append(host)
reserved_hosts = list(set(reserved_hosts))


Expand Down
9 changes: 7 additions & 2 deletions microservices/gatewayApi/v2/routes/gw_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def get_statuses(namespace: str) -> object:
for route in routes:
if route['service']['id'] == service['id'] and 'hosts' in route:
actual_host = route['hosts'][0]
host = clean_host(actual_host)
if route['preserve_host']:
host = clean_host(actual_host)

try:
addr = socket.gethostbyname(service['host'])
Expand All @@ -56,7 +57,11 @@ def get_statuses(namespace: str) -> object:
else:
u = urlparse(url)

headers['Host'] = host
if host is None:
headers['Host'] = u.hostname
else:
headers['Host'] = host

log.info("GET %-30s %s" % ("%s://%s" % (u.scheme, u.netloc), headers))

urllib3.disable_warnings()
Expand Down
Loading

0 comments on commit 56de3a8

Please sign in to comment.