Skip to content
Snippets Groups Projects
Verified Commit 07aa4054 authored by David Hoese's avatar David Hoese
Browse files

Remove legacy wms_times API

parent 2f0e4e81
No related branches found
No related tags found
1 merge request!5Add initial attempt at S3 geotiff reading
Pipeline #39947 failed with stages
in 18 minutes and 24 seconds
......@@ -17,9 +17,6 @@ ingress:
paths:
- path: "/wms"
pathType: ImplementationSpecific
# the test site uses the production WMS server
# - host: geosphere-test.ssec.wisc.edu
# paths: ["/wms", "/wms_times"]
tls:
- hosts:
- "test"
......
......@@ -19,11 +19,6 @@ ingress:
paths:
- path: "/wms"
pathType: ImplementationSpecific
- path: "/wms_times"
pathType: ImplementationSpecific
# the test site uses the production WMS server
# - host: geosphere-test.ssec.wisc.edu
# paths: ["/wms", "/wms_times"]
tls:
- hosts:
- "test"
......
......@@ -13,11 +13,6 @@ ingress:
paths:
- path: "/wms"
pathType: ImplementationSpecific
- path: "/wms_times"
pathType: ImplementationSpecific
# the test site uses the production WMS server
# - host: geosphere-test.ssec.wisc.edu
# paths: ["/wms", "/wms_times"]
tls:
- hosts:
- "test"
......
......@@ -157,7 +157,7 @@ RUN echo ttf-mscorefonts-installer msttcorefonts/accepted-mscorefonts-eula selec
COPY site-conf /etc/apache2/sites-available/cspp_geo.conf
# disable the default which would conflict with our custom
RUN a2ensite cspp_geo && a2dissite 000-default
COPY cgi-bin/* /usr/lib/cgi-bin/
# Trick apache log to stdout/stderr
RUN ln -sf /dev/stdout /var/log/apache2/access.log && \
ln -sf /dev/stderr /var/log/apache2/error.log
......
#!/usr/bin/env python3
"""CGI script to read on-disk shapefiles for available times for one layer."""
import os
import cgi
import json
import fiona
form = cgi.FieldStorage()
layer = form['layer'].value
if not os.path.isfile(layer):
times = []
else:
with fiona.open(layer, 'r') as shp_file:
times = [x['properties']['time'] for x in shp_file]
print("Content-Type: application/json")
print("Access-Control-Allow-Origin: *")
print() # blank line, end of headers
print(json.dumps(times))
#!/usr/bin/env python3
"""CGI script to read PostGIS for available times for one layer."""
import os
import sys
import cgi
import json
from datetime import datetime
import psycopg2
from psycopg2 import sql
def bad_request(msg):
print("""Status: 400 Bad Request
Content-type: text/plain
Access-Control-Allow-Origin: *
{}""".format(msg))
sys.exit(1)
def get_connect_str():
pw_filename = "__POSTGRES_PASSWORD_FILE__"
connect_str = "host=__POSTGRES_HOST__ " \
"port=__POSTGRES_PORT__ " \
"dbname=__POSTGRES_DBNAME__ " \
"user=__POSTGRES_USER__"
if not os.path.isfile(pw_filename) or '__' in connect_str:
print("""Status: 500 Backend Misconfigured\n
Content-type: text/plain
Access-Control-Allow-Origin: *
Backend has not been configured properly and doesn't know how to communicate with the database.
Please contact site administrator.
""")
sys.exit(1)
with open(pw_filename, 'r') as pw_file:
password = pw_file.read().strip()
connect_str += " password={}".format(password)
return connect_str
connect_str = get_connect_str()
form = cgi.FieldStorage()
table_name = form.getvalue('layer')
start_time = form.getvalue('start_time')
end_time = form.getvalue('end_time')
num_times = form.getvalue('num_times', 0)
order = form.getvalue('order', 'ASC')
if table_name is None:
bad_request("Missing required parameter 'layer'.")
if start_time is not None:
try:
start_time = datetime.strptime(start_time, "%Y-%m-%dT%H:%M:%S")
except ValueError:
bad_request("""Bad 'start_time' format. Expected: 'YYYY-MM-DDTHH:MM:SS'""")
if end_time is not None:
try:
end_time = datetime.strptime(end_time, "%Y-%m-%dT%H:%M:%S")
except ValueError:
bad_request("""Bad 'end_time' format. Expected: 'YYYY-MM-DDTHH:MM:SS'""")
try:
num_times = int(num_times)
if num_times < 0:
raise ValueError("'num_times' must greater or equal to 0.")
except ValueError:
bad_request("""Invalid integer for 'num_times'.""")
order = order.upper()
if order not in ('ASC', 'DESC'):
bad_request("""'order' must be either 'ASC' or 'DESC'.""")
query_str = """SELECT to_char(start_time, 'YYYY-MM-DD"T"HH24:MI:SS') FROM {}"""
if start_time is not None or end_time is not None:
query_str += " WHERE "
if start_time is not None:
query_str += "start_time >= timestamp '{}'".format(start_time.strftime('%Y-%m-%dT%H:%M:%S'))
if start_time is not None and end_time is not None:
query_str += " AND "
if end_time is not None:
query_str += "start_time <= timestamp '{}'".format(end_time.strftime('%Y-%m-%dT%H:%M:%S'))
query_str += " ORDER BY start_time {}".format(order)
if num_times != 0:
query_str += " LIMIT {}".format(num_times)
try:
conn = psycopg2.connect(connect_str)
with conn:
with conn.cursor() as cur:
cur.execute(sql.SQL(query_str).format(sql.Identifier(table_name)))
times = cur.fetchall()
except psycopg2.errors.DatabaseError:
print("""Status: 500 Database Error
Content-type: text/plain
Access-Control-Allow-Origin: *
Error requesting time information from database.
""")
sys.exit(1)
# postgres returned a list of tuples
times = [time_tuple[0] for time_tuple in times]
print("Content-Type: application/json")
print("Access-Control-Allow-Origin: *")
print() # blank line, end of headers
print(json.dumps(times))
......@@ -15,14 +15,9 @@ export LAYER_BASE_DIR=${LAYER_BASE_DIR:-"/data/tiles"}
# Update the mapcache.xml file with the real host and port name
mf_tmpl="/work/abi_l1b_template.map"
sed -i "s:__LAYER_BASE_DIR__:$LAYER_BASE_DIR:g" /etc/apache2/sites-available/cspp_geo.conf
if [[ ${POSTGRES_HOST} != "" ]]; then
sed -i "s:wms_times_postgres:wms_times:g" /etc/apache2/sites-available/cspp_geo.conf
replace_pg_params /usr/lib/cgi-bin/layer_times_postgres.py
replace_pg_params /work/render.py
else
sed -i "s:wms_times_shapes:wms_times:g" /etc/apache2/sites-available/cspp_geo.conf
fi
export GEOSPHERE_CONFIG=${GEOSPHERE_CONFIG:-"/work/geosphere_settings.yaml"}
......
......@@ -37,10 +37,6 @@
# FCGI version of the URL
RewriteRule "^/wms/([^/]+)/([^/]+)/([^/]+)/([^/]+)?(.*)" "/cgi-bin/mapserv.fcgi?map=/work/mapfiles/$1_$2_$3_$4.map&$5" [PT,QSA]
RewriteRule "^/wms/([^/]+)?(.*)" "/cgi-bin/mapserv.fcgi?map=/work/mapfiles/$1.map&$2" [PT,QSA]
# /wms_times/g16/abi/radf/true_color
# LAYER_BASE_DIR defaults to /data/tiles
RewriteRule "^/wms_times_postgres/([^/]+)/([^/]+)/([^/]+)/([^/]+)" "/cgi-bin/layer_times_postgres.py?layer=$1_$2_$3_l1b_${lc:$4}" [PT,QSA]
RewriteRule "^/wms_times_shapes/([^/]+)/([^/]+)/([^/]+)/([^/]+)" "/cgi-bin/layer_times.py?layer=__LAYER_BASE_DIR__/$1/$2/$3/$4/$4.shp" [PT,QSA]
# Regular CGI version of the URL (put last since it should be used less often)
RewriteRule "^/wms_cgi/([^/]+)/([^/]+)/([^/]+)/([^/]+)?(.*)" "/cgi-bin/mapserv?map=/work/mapfiles/$1_$2_$3_$4.map&$5" [PT,QSA]
RewriteRule "^/wms_cgi/([^/]+)?(.*)" "/cgi-bin/mapserv?map=/work/mapfiles/$1.map&$2" [PT,QSA]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment