diff options
author | 2020-01-07 15:26:52 +0100 | |
---|---|---|
committer | 2020-01-07 15:26:52 +0100 | |
commit | 9ee12584b8ae4f6b7f0f3269d3afab9f80f1c0a8 (patch) | |
tree | 5568969d275b4cffbb4cde44b4132e7149549ba1 /bootstrap/codesearch/create_config.py | |
parent | 09a635790188dd59af2e3cc7612c76afac1bfd53 (diff) |
Add Hound code search configuration generator
Configuration is generated from Gerrit-supplied data.
Issue-ID: ONAPARC-540
Change-Id: I84d5b87580882926b916ed20dbcd2369be4c77f4
Signed-off-by: Pawel Wieczorek <p.wieczorek2@samsung.com>
Diffstat (limited to 'bootstrap/codesearch/create_config.py')
-rwxr-xr-x | bootstrap/codesearch/create_config.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/bootstrap/codesearch/create_config.py b/bootstrap/codesearch/create_config.py new file mode 100755 index 000000000..4009e51df --- /dev/null +++ b/bootstrap/codesearch/create_config.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +"""Create configuration for code search.""" + +import json +import urllib.request +import sys + +ONAP_GERRIT = "https://gerrit.onap.org/r" +API_PROJECTS = "/projects/" + +MAGIC_PREFIX = ")]}'" + + +def get_projects_list(): + """Request list of all available projects from ONAP Gerrit.""" + resp = urllib.request.urlopen(ONAP_GERRIT + API_PROJECTS) + resp_body = resp.read() + + no_magic = resp_body[len(MAGIC_PREFIX):] + decoded = no_magic.decode("utf-8") + projects = json.loads(decoded) + + return projects.keys() + + +def create_repos_list(projects): + """Create a map of all projects to their repositories' URLs.""" + return {p: {"url": "{}/{}.git".format(ONAP_GERRIT, p)} for p in projects} + + +def main(): + """Main entry point for the script.""" + repos = create_repos_list(get_projects_list()) + config = { + "max-concurrent-indexers": 2, + "dbpath": "data", + "health-check-uri": "/healthz", + "repos": repos + } + print(json.dumps(config, sort_keys=True, indent=4, separators=(',', ': '))) + + +if __name__ == '__main__': + sys.exit(main()) |