Skip to content

Commit a92fdd2

Browse files
ahornaceVladimir Kotal
authored andcommitted
Webapp URI param should be more robust
1 parent 4d23fa1 commit a92fdd2

File tree

5 files changed

+37
-16
lines changed

5 files changed

+37
-16
lines changed

src/org/opensolaris/opengrok/configuration/RuntimeEnvironment.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,9 @@ public void writeConfiguration(File file) throws IOException {
13831383
*/
13841384
public void writeConfiguration(String host) throws IOException {
13851385
Response r = ClientBuilder.newClient()
1386-
.target(host + "/api/v1")
1386+
.target(host)
1387+
.path("api")
1388+
.path("v1")
13871389
.path("configuration")
13881390
.queryParam("reindex", true)
13891391
.request()
@@ -1407,7 +1409,10 @@ public void signalTorefreshSearcherManagers(List<String> subFiles, String host)
14071409

14081410
subFiles.stream().map(proj -> new File(proj).getName()).forEach(project -> {
14091411
Response r = ClientBuilder.newClient()
1410-
.target(host + "/api/v1/system")
1412+
.target(host)
1413+
.path("api")
1414+
.path("v1")
1415+
.path("system")
14111416
.path("refresh")
14121417
.request()
14131418
.put(Entity.text(project));

src/org/opensolaris/opengrok/index/IndexDatabase.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,10 @@ private void markProjectIndexed(Project project) {
371371
if (project != null) {
372372
if (env.getConfigHost() != null) {
373373
Response r = ClientBuilder.newClient()
374-
.target(env.getConfigHost() + "/api/v1/projects")
374+
.target(env.getConfigHost())
375+
.path("api")
376+
.path("v1")
377+
.path("projects")
375378
.path(Util.URIEncode(project.getName()))
376379
.path("indexed")
377380
.request()

src/org/opensolaris/opengrok/index/IndexerUtil.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ private IndexerUtil() {
3232

3333
static void enableProjects(final String host) {
3434
ClientBuilder.newClient()
35-
.target(host + "/api/v1/configuration")
35+
.target(host)
36+
.path("api")
37+
.path("v1")
38+
.path("configuration")
3639
.path("projectsEnabled")
3740
.request()
3841
.put(Entity.text(Boolean.TRUE.toString()));

tools/sync/opengrok.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ def get_repos(logger, project, uri):
6666
Return string with the result on success, None on failure.
6767
"""
6868

69-
r = get(logger, uri + '/api/v1/projects/' +
70-
urllib.parse.quote_plus(project) + '/repositories')
69+
r = get(logger, get_uri(uri, 'api', 'v1', 'projects',
70+
urllib.parse.quote_plus(project), 'repositories'))
7171

7272
if not r:
7373
logger.error('could not get repositories for ' + project)
@@ -86,8 +86,9 @@ def get_config_value(logger, name, uri):
8686
8787
Return string with the result on success, None on failure.
8888
"""
89-
r = get(logger, uri + '/api/v1/configuration/' +
90-
urllib.parse.quote_plus(name))
89+
r = get(logger, get_uri(uri, 'api', 'v1', 'configuration',
90+
urllib.parse.quote_plus(name)))
91+
9192
if not r:
9293
logger.error('could not get config value ' + name)
9394
return None
@@ -103,7 +104,8 @@ def get_repo_type(logger, repository, uri):
103104
"""
104105
payload = {'repository': repository}
105106

106-
r = get(logger, uri + '/api/v1/repositories/type', params=payload)
107+
r = get(logger, get_uri(uri, 'api', 'v1', 'repositories', 'type'),
108+
params=payload)
107109
if not r:
108110
logger.error('could not get repo type for ' + repository)
109111
return None
@@ -115,7 +117,7 @@ def get_repo_type(logger, repository, uri):
115117

116118

117119
def get_configuration(logger, uri):
118-
r = get(logger, uri + '/api/v1/configuration')
120+
r = get(logger, get_uri(uri, 'api', 'v1', 'configuration'))
119121
if not r:
120122
logger.error('could not get configuration')
121123
return None
@@ -124,7 +126,8 @@ def get_configuration(logger, uri):
124126

125127

126128
def set_configuration(logger, configuration, uri):
127-
r = put(logger, uri + '/api/v1/configuration', data=configuration)
129+
r = put(logger, get_uri(uri, 'api', 'v1', 'configuration'),
130+
data=configuration)
128131

129132
if not r:
130133
logger.error('could not set configuration')
@@ -134,7 +137,7 @@ def set_configuration(logger, configuration, uri):
134137

135138

136139
def list_indexed_projects(logger, uri):
137-
r = get(logger, uri + '/api/v1/projects/indexed')
140+
r = get(logger, get_uri(uri, 'api', 'v1', 'projects', 'indexed'))
138141
if not r:
139142
logger.error('could not list indexed projects')
140143
return None
@@ -143,7 +146,7 @@ def list_indexed_projects(logger, uri):
143146

144147

145148
def add_project(logger, project, uri):
146-
r = post(logger, uri + '/api/v1/projects', data=project)
149+
r = post(logger, get_uri(uri, 'api', 'v1', 'projects'), data=project)
147150

148151
if not r:
149152
logger.error('could not add project ' + project)
@@ -153,11 +156,15 @@ def add_project(logger, project, uri):
153156

154157

155158
def delete_project(logger, project, uri):
156-
r = delete(logger, uri + '/api/v1/projects/' +
157-
urllib.parse.quote_plus(project))
159+
r = delete(logger, get_uri(uri, 'api', 'v1', 'projects',
160+
urllib.parse.quote_plus(project)))
158161

159162
if not r:
160163
logger.error('could not delete project ' + project)
161164
return False
162165

163166
return True
167+
168+
169+
def get_uri(*uri_parts):
170+
return '/'.join(s.strip('/') for s in uri_parts)

tools/sync/reindex-project.ksh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ function reindex_one
6767
exit 1
6868
fi
6969

70-
curl "${OPENGROK_WEBAPP_CFGADDR}/${OPENGROK_WEBAPP_CONTEXT}/api/v1/configuration" > "$config_xml"
70+
CFG_URI_PATH="${OPENGROK_WEBAPP_CONTEXT}/api/v1/configuration"
71+
CFG_URI_PATH=$(echo ${CFG_URI_PATH} | sed 's://:/:g')
72+
73+
curl "${OPENGROK_WEBAPP_CFGADDR%/}/${CFG_URI_PATH#/}" > "$config_xml"
7174
if (( $? != 0 )); then
7275
print -u2 "failed to get configuration from webapp"
7376
rm -f "$config_xml"

0 commit comments

Comments
 (0)