Skip to content

Commit 8dd82a9

Browse files
authored
Merge pull request #649 from OpenKnowledgeMaps/dev
Biweekly release (22-05-19)
2 parents 70dbee5 + c083c0f commit 8dd82a9

31 files changed

Lines changed: 299 additions & 202 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
## 2022-05-19
4+
5+
### New features
6+
7+
- The BASE content provider is now displayed in the context line & more info modal.
8+
9+
### Changes
10+
11+
- The new share buttons are now hidden in the embed mode.
12+
313
## 2022-05-05
414

515
### New features

docker-compose-dataworker.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ services:
1212
REDIS_PORT: "${REDIS_PORT}"
1313
REDIS_DB: "${REDIS_DB}"
1414
REDIS_PASSWORD: "${REDIS_PASSWORD}"
15-
REDIS_SSL: "${REDIS_SSL}"
1615
restart: always
1716
volumes:
1817
- /opt/local/renv/cache:/renv/cache

docker-compose.yml

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ services:
1111
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
1212
command: postgres -c config_file=/etc/postgresql.conf -c hba_file=/etc/pg_hba.conf
1313
volumes:
14-
# - ~/data/OKMaps/${COMPOSE_PROJECT_NAME}/postgresql/data:/var/lib/postgresql/data
1514
- db_data:/var/lib/postgresql/data
16-
- ./server/workers/pg_hba.conf:/etc/pg_hba.conf
17-
- ./server/workers/postgresql.conf:/etc/postgresql.conf
15+
- ./pg_hba.conf:/etc/pg_hba.conf
16+
- ./postgresql.conf:/etc/postgresql.conf
1817
networks:
1918
- headstart
2019

@@ -35,8 +34,7 @@ services:
3534
command: ["redis-server", "/etc/redis/redis.conf", "--bind", "${REDIS_HOST}", "--appendonly", "yes", "--port", "${REDIS_PORT}"]
3635
volumes:
3736
- 'redis:/var/lib/redis/data'
38-
- ./server/workers/redis.conf:/etc/redis/redis.conf
39-
- ./server/workers/certs:/etc/certs
37+
- ./redis.conf:/etc/redis/redis.conf
4038
ports:
4139
- "127.0.0.1:${REDIS_PORT}:6379"
4240
restart: always
@@ -52,12 +50,13 @@ services:
5250
REDIS_PORT: "${REDIS_PORT}"
5351
REDIS_PASSWORD: "${REDIS_PASSWORD}"
5452
REDIS_DB: "${REDIS_DB}"
55-
REDIS_SSL: "${REDIS_SSL}"
5653
BEHIND_PROXY: "${BEHIND_PROXY}"
5754
DEFAULT_DATABASE: "${DEFAULT_DATABASE}"
5855
DATABASES: "${DATABASES}"
5956
FLASK_ENV: "${FLASK_ENV}"
6057
command: ["gunicorn", "--workers", "10", "--threads", "2", "-b", "0.0.0.0:${API_PORT}", "app:app", "--timeout", "300"]
58+
volumes:
59+
- ./api_cache:/var/api_cache
6160
depends_on:
6261
- redis
6362
networks:
@@ -82,15 +81,12 @@ services:
8281

8382
triple:
8483
image: triple:${SERVICE_VERSION}
85-
env_file:
86-
- server/workers/triple/triple.env
8784
environment:
8885
SERVICE_VERSION: "${SERVICE_VERSION}"
8986
REDIS_HOST: "${REDIS_HOST}"
9087
REDIS_PORT: "${REDIS_PORT}"
9188
REDIS_DB: "${REDIS_DB}"
9289
REDIS_PASSWORD: "${REDIS_PASSWORD}"
93-
REDIS_SSL: "${REDIS_SSL}"
9490
LOGLEVEL: "${LOGLEVEL}"
9591
TRIPLE_USER: "${TRIPLE_USER}"
9692
TRIPLE_PASS: "${TRIPLE_PASS}"
@@ -107,15 +103,12 @@ services:
107103

108104
gsheets:
109105
image: gsheets:${SERVICE_VERSION}
110-
env_file:
111-
- server/workers/gsheets/gsheets.env
112106
environment:
113107
SERVICE_VERSION: "${SERVICE_VERSION}"
114108
REDIS_HOST: "${REDIS_HOST}"
115109
REDIS_PORT: "${REDIS_PORT}"
116110
REDIS_DB: "${REDIS_DB}"
117111
REDIS_PASSWORD: "${REDIS_PASSWORD}"
118-
REDIS_SSL: "${REDIS_SSL}"
119112
LOGLEVEL: "${LOGLEVEL}"
120113
restart: always
121114
depends_on:
@@ -125,16 +118,19 @@ services:
125118

126119
dataprocessing:
127120
image: dataprocessing:${SERVICE_VERSION}
128-
env_file:
129-
- server/workers/dataprocessing/dataprocessing.env
130121
environment:
131122
SERVICE_VERSION: "${SERVICE_VERSION}"
132123
REDIS_HOST: "${REDIS_HOST}"
133124
REDIS_PORT: "${REDIS_PORT}"
134125
REDIS_DB: "${REDIS_DB}"
135126
REDIS_PASSWORD: "${REDIS_PASSWORD}"
136-
REDIS_SSL: "${REDIS_SSL}"
137127
LOGLEVEL: "${LOGLEVEL}"
128+
LOGFILE: "${LOGFILE}"
129+
RENV_VERSION: 0.14.0-5
130+
CRAN_REPOS: https://cran.wu.ac.at
131+
LC_ALL: "en_US.UTF-8"
132+
LANG: "en_US.UTF-8"
133+
RENV_PATHS_CACHE: /renv/cache
138134
restart: always
139135
volumes:
140136
- /opt/local/renv/cache:/renv/cache
@@ -152,7 +148,6 @@ services:
152148
REDIS_PORT: "${REDIS_PORT}"
153149
REDIS_DB: "${REDIS_DB}"
154150
REDIS_PASSWORD: "${REDIS_PASSWORD}"
155-
REDIS_SSL: "${REDIS_SSL}"
156151
LOGLEVEL: "${LOGLEVEL}"
157152
LOGFILE: "/var/log/headstart/headstart.log"
158153
RENV_VERSION: 0.14.0-5
@@ -178,15 +173,13 @@ services:
178173
REDIS_PORT: "${REDIS_PORT}"
179174
REDIS_DB: "${REDIS_DB}"
180175
REDIS_PASSWORD: "${REDIS_PASSWORD}"
181-
REDIS_SSL: "${REDIS_SSL}"
182176
LOGLEVEL: "${LOGLEVEL}"
183-
LOGFILE: "/var/log/headstart/headstart.log"
177+
LOGFILE: "${LOGFILE}"
184178
RENV_VERSION: 0.14.0-5
185179
CRAN_REPOS: https://cran.wu.ac.at
186180
LC_ALL: "en_US.UTF-8"
187181
LANG: "en_US.UTF-8"
188182
RENV_PATHS_CACHE: /renv/cache
189-
PYTHONIOENCODING: "utf-8"
190183
restart: always
191184
volumes:
192185
- /opt/local/renv/cache:/renv/cache
@@ -204,15 +197,13 @@ services:
204197
REDIS_PORT: "${REDIS_PORT}"
205198
REDIS_DB: "${REDIS_DB}"
206199
REDIS_PASSWORD: "${REDIS_PASSWORD}"
207-
REDIS_SSL: "${REDIS_SSL}"
208200
LOGLEVEL: "${LOGLEVEL}"
209-
LOGFILE: "/var/log/headstart/headstart.log"
201+
LOGFILE: "${LOGFILE}"
210202
RENV_VERSION: 0.14.0-5
211203
CRAN_REPOS: https://cran.wu.ac.at
212204
LC_ALL: "en_US.UTF-8"
213205
LANG: "en_US.UTF-8"
214206
RENV_PATHS_CACHE: /renv/cache
215-
PYTHONIOENCODING: "utf-8"
216207
restart: always
217208
volumes:
218209
- /opt/local/renv/cache:/renv/cache
@@ -226,6 +217,8 @@ volumes:
226217
redis:
227218
db_data:
228219
driver: local
220+
api_cache:
221+
driver: local
229222

230223
networks:
231224
headstart:
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
rm(list = ls())
2+
3+
args <- commandArgs(TRUE)
4+
wd <- args[1]
5+
setwd(wd) #Don't forget to set your working directory
6+
7+
renv::activate()
8+
renv::restore(lockfile = '../renv.lock')
9+
Sys.setlocale(category="LC_ALL", locale = "en_US.UTF-8")
10+
11+
library(jsonlite)
12+
library(rbace)
13+
library(logging)
14+
15+
source('utils.R')
16+
if (Sys.getenv("LOGLEVEL") == "DEBUG") {
17+
DEBUG <- FALSE
18+
} else {
19+
DEBUG <- TRUE
20+
}
21+
22+
if (DEBUG==TRUE){
23+
setup_logging('DEBUG')
24+
} else {
25+
setup_logging('INFO')
26+
}
27+
28+
29+
log <- getLogger('base_repos')
30+
31+
tryCatch({
32+
contentproviders <- bs_repositories("")
33+
}, error=function(err){
34+
log$error(paste("Contentprovider failed", "base", "retrieve_contentproviders", "", err, sep="||"))
35+
failed <- list()
36+
failed$reason <- list(err)
37+
failed$status <- 'error'
38+
})
39+
40+
41+
if (exists('contentproviders')) {
42+
print(toJSON(contentproviders))
43+
} else {
44+
print(toJSON(failed))
45+
}

server/services/search.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@ function search($service_integration, $dirty_query
109109
}
110110
$unique_id = ($precomputed_id === null)?($unique_id):($precomputed_id);
111111
$post_params["vis_id"] = $unique_id;
112+
if (array_key_exists("repo", $post_params)) {
113+
$payload = json_encode(array("repo" => $post_params["repo"]));
114+
$res = $apiclient->call_api($endpoint . "/contentproviders", $payload);
115+
$res = $res["result"];
116+
$res = json_decode($res, true);
117+
$repo_name = $res["repo_name"];
118+
$post_params["repo_name"] = $repo_name;
119+
$param_types[] = "repo_name";
120+
}
112121
$params_json = packParamsJSON($param_types, $post_params);
113122

114123
if($retrieve_cached_map) {

server/workers/api/src/apis/base.py

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@
3939
description='raw results from ElasticSearch')})
4040

4141

42+
def get_or_create_contentprovider_lookup():
43+
try:
44+
k = str(uuid.uuid4())
45+
d = {"id": k, "params": {},"endpoint": "contentproviders"}
46+
base_ns.logger.debug(d)
47+
redis_store.rpush("base", json.dumps(d))
48+
result = get_key(redis_store, k)
49+
df = pd.DataFrame(json.loads(result["contentproviders"]))
50+
df.set_index("internal_name", inplace=True)
51+
cp_dict = df.name.to_dict()
52+
return cp_dict
53+
except Exception as e:
54+
base_ns.logger.error(e)
55+
56+
contentprovider_lookup = get_or_create_contentprovider_lookup()
57+
4258
@base_ns.route('/search')
4359
class Search(Resource):
4460
@base_ns.doc(responses={200: 'OK',
@@ -53,6 +69,9 @@ def post(self):
5369
if "optradio" in params:
5470
del params["optradio"]
5571
errors = search_param_schema.validate(params, partial=True)
72+
if "repo" in params:
73+
repo_name = contentprovider_lookup.get(params["repo"])
74+
params["repo_name"] = repo_name
5675
params["limit"] = 120
5776
params["list_size"] = 100
5877
base_ns.logger.debug(errors)
@@ -85,10 +104,40 @@ def post(self):
85104
base_ns.logger.error(e)
86105
abort(500, "Problem encountered, check logs.")
87106

107+
@base_ns.route('/contentproviders')
108+
class ContentProvider(Resource):
109+
@base_ns.doc(responses={200: 'OK',
110+
400: 'Invalid search parameters'})
111+
@base_ns.produces(["application/json"])
112+
def post(self):
113+
"""
114+
params: can be empty
115+
content_provider: BASE internal name, e.g. "ftunivlausanne"
116+
117+
returns: json
118+
{"contentprovider_short": "ftunivlausanne",
119+
"repo_name": "Université de Lausanne (UNIL): Serval - Serveur académique lausannois"}
120+
"""
121+
params = request.get_json()
122+
base_ns.logger.debug(params)
123+
if not params:
124+
result = contentprovider_lookup
125+
else:
126+
result = {"repo_name": contentprovider_lookup.get(params["repo"])}
127+
try:
128+
headers = {}
129+
headers["Content-Type"] = "application/json"
130+
return make_response(result,
131+
200,
132+
headers)
133+
except Exception as e:
134+
base_ns.logger.error(e)
135+
abort(500, "Problem encountered, check logs.")
136+
88137

89138

90139
@base_ns.route('/service_version')
91140
class ServiceVersion(Resource):
92141
def get(self):
93142
result = {"service_version": os.getenv("SERVICE_VERSION")}
94-
return make_response(result, 200, {"Content-Type": "application/json"})
143+
return make_response(result, 200, {"Content-Type": "application/json"})

server/workers/api/src/apis/request_validators.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class SearchParamSchema(Schema):
2121
unique_id = fields.Str()
2222
raw = fields.Boolean()
2323
sg_method = fields.Str()
24+
repo = fields.Str()
25+
repo_name = fields.Str()
26+
coll = fields.Str()
2427
vis_id = fields.Str(default=None)
2528
optradio = fields.Str()
2629
service = fields.Str()

server/workers/api/src/apis/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
"port": os.getenv("REDIS_PORT"),
1212
"db": os.getenv("REDIS_DB"),
1313
"password": os.getenv("REDIS_PASSWORD"),
14-
"client_name": "api",
15-
"ssl": True if os.getenv("REDIS_SSL") == "true" else False
14+
"client_name": "api"
1615
}
1716
redis_store = redis.StrictRedis(**redis_config)
1817

server/workers/api/src/app.py

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import os
22
import sys
3-
from flask import Flask, redirect, url_for
3+
from flask import Flask
44
from flask_restx import Api
55
from flask_cors import CORS
66
from werkzeug.middleware.proxy_fix import ProxyFix
7+
import logging
78

89
from apis.triple import triple_ns
910
from apis.gsheets import gsheets_ns
@@ -13,19 +14,45 @@
1314
from apis.create_vis import vis_ns
1415
from apis.export import export_ns
1516

16-
from utils.monkeypatches import ReverseProxied, __schema__, specs_url, _register_apidoc
17-
import logging
1817

18+
class ReverseProxied(object):
19+
'''Wrap the application in this middleware and configure the
20+
front-end server to add these headers, to let you quietly bind
21+
this to a URL other than / and to an HTTP scheme that is
22+
different than what is used locally.
23+
24+
location /myprefix {
25+
proxy_pass http://192.168.0.1:5001;
26+
proxy_set_header Host $host;
27+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
28+
proxy_set_header X-Scheme $scheme;
29+
proxy_set_header X-Script-Name /myprefix;
30+
}
31+
32+
:param app: the WSGI application
33+
'''
34+
def __init__(self, app):
35+
self.app = app
36+
37+
def __call__(self, environ, start_response):
38+
script_name = environ.get('HTTP_X_SCRIPT_NAME', '')
39+
if script_name:
40+
environ['SCRIPT_NAME'] = script_name
41+
path_info = environ['PATH_INFO']
42+
if path_info.startswith(script_name):
43+
environ['PATH_INFO'] = path_info[len(script_name):]
44+
45+
scheme = environ.get('HTTP_X_SCHEME', '')
46+
if scheme:
47+
environ['wsgi.url_scheme'] = scheme
48+
return self.app(environ, start_response)
1949

2050
def api_patches(app):
21-
Api._register_apidoc = _register_apidoc
22-
Api.__schema__ = __schema__
23-
Api.specs_url = specs_url
2451

2552
api_fixed = Api(
2653
app,
2754
title="Head Start API",
28-
description="Head Start API demo",
55+
description="Head Start API",
2956
version="0.1",
3057
prefix='/api',
3158
doc="/docs")

server/workers/api/src/utils/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)