blob: 4009e51df04f14ac07b6e6b22906644f3e224cb8 [file] [log] [blame]
Pawel Wieczorek9ee12582020-01-07 15:26:52 +01001#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3
4"""Create configuration for code search."""
5
6import json
7import urllib.request
8import sys
9
10ONAP_GERRIT = "https://gerrit.onap.org/r"
11API_PROJECTS = "/projects/"
12
13MAGIC_PREFIX = ")]}'"
14
15
16def get_projects_list():
17 """Request list of all available projects from ONAP Gerrit."""
18 resp = urllib.request.urlopen(ONAP_GERRIT + API_PROJECTS)
19 resp_body = resp.read()
20
21 no_magic = resp_body[len(MAGIC_PREFIX):]
22 decoded = no_magic.decode("utf-8")
23 projects = json.loads(decoded)
24
25 return projects.keys()
26
27
28def create_repos_list(projects):
29 """Create a map of all projects to their repositories' URLs."""
30 return {p: {"url": "{}/{}.git".format(ONAP_GERRIT, p)} for p in projects}
31
32
33def main():
34 """Main entry point for the script."""
35 repos = create_repos_list(get_projects_list())
36 config = {
37 "max-concurrent-indexers": 2,
38 "dbpath": "data",
39 "health-check-uri": "/healthz",
40 "repos": repos
41 }
42 print(json.dumps(config, sort_keys=True, indent=4, separators=(',', ': ')))
43
44
45if __name__ == '__main__':
46 sys.exit(main())