{"action":"created","comment":{"url":"https://api.github.com/repos/jgi-kbase/IDMappingService/pulls/comments/208664926","pull_request_review_id":144521953,"id":208664926,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwODY2NDkyNg==","diff_hunk":"@@ -0,0 +1,140 @@\n+\"\"\"\n+Configuration handlers for the ID Mapping system.\n+\"\"\"\n+from typing import Dict, Optional\n+from pathlib import Path\n+import os\n+import configparser\n+# May want different configuration implementations based on the deployment environment.\n+# YAGNI for now.\n+\n+# TODO CFG support user handler custom configs\n+# TODO CFG support which user handlers are enabled\n+# TODO CFG support which user handlers are allowed to specify admins\n+\n+\n+class IDMappingConfigError(Exception):\n+    \"\"\" Thrown when there's an error in the ID Mapping system configuration. \"\"\"\n+    pass\n+\n+\n+class KBaseConfig:\n+    \"\"\"\n+    Loads a configuration from a standard KBase-style deploy.cfg file (an ini file with only\n+    one section.) The configuration is contained in the `idmapping` section of the config file.\n+\n+    The keys are:\n+    mongo-host\n+    mongo-db\n+    mongo-user\n+    mongo-pwd\n+    dont-trust-x-ip-headers\n+\n+    The last key is optional and instructs the server to ignore the X-Real-IP and X-Forwarded-For\n+    headers if set to the string 'true'.\n+\n+    :ivar mongo_host: the host of the MongoDB instance, including the port.\n+    :ivar mongo_db: the MongoDB database to use for the ID mapping service.\n+    :ivar mongo_user: the username to use with MongoDB, if any.\n+    :ivar mongo_pwd: the password to use with MongoDB, if any.\n+    :ivar ignore_ip_headers: True if the X-Real-IP and X-Forwarded-For headers should be ignored.\n+    \"\"\"\n+\n+    ENV_VAR_IDMAPPING = 'ID_MAPPING_CONFIG'\n+    \"\"\"\n+    The first environment variable where the system will look for the path to the config file.\n+    \"\"\"\n+\n+    ENV_VAR_KB_DEP = 'KB_DEPLOYMENT_CONFIG'\n+    \"\"\"\n+    The second environment variable where the system will look for the path to the config file.\n+    \"\"\"\n+\n+    CFG_SEC = 'idmapping'\n+    \"\"\" The section of the config file where the configuration is located. \"\"\"\n+\n+    _TEMP_KEY_CFG_FILE = 'temp-key-config-file'\n+\n+    KEY_MONGO_HOST = 'mongo-host'\n+    \"\"\" The key corresponding to the value containing the MongoDB host. \"\"\"\n+\n+    KEY_MONGO_DB = 'mongo-db'\n+    \"\"\" The key corresponding to the value containing the MongoDB database. \"\"\"\n+\n+    KEY_MONGO_USER = 'mongo-user'\n+    \"\"\" The key corresponding to the value containing the MongoDB username. \"\"\"\n+\n+    KEY_MONGO_PWD = 'mongo-pwd'\n+    \"\"\" The key corresponding to the value containing the MongoDB user password. \"\"\"\n+\n+    KEY_IGNORE_IP_HEADERS = 'dont-trust-x-ip-headers'\n+    \"\"\"\n+    The key corresponding to the value containing a boolean designating whether the X-Real_IP\n+    and X-Forwarded-For headers should be ignored. \"\"\"\n+\n+    _TRUE = 'true'\n+\n+    def __init__(self, cfgfile: Path=None) -> None:\n+        \"\"\"\n+        Load the configuration.\n+\n+        :param cfgfile: the path to the configuration file. If not provided, the path will be\n+            looked up in the environment variables, in order of precedence, ID_MAPPING_CONFIG and\n+            KB_DEPLOYMENT_CONFIG.\n+        \"\"\"\n+        if not cfgfile:\n+            cfgfile = self._get_cfg_from_env()\n+        cfg = self._get_cfg(cfgfile)\n+        self.ignore_ip_headers = self._TRUE == cfg.get(self.KEY_IGNORE_IP_HEADERS)\n+        self.mongo_host = self._get_string(self.KEY_MONGO_HOST, cfg)\n+        self.mongo_db = self._get_string(self.KEY_MONGO_DB, cfg)\n+        self.mongo_user = self._get_string(self.KEY_MONGO_USER, cfg, False)\n+        mongo_pwd = self._get_string(self.KEY_MONGO_PWD, cfg, False)\n+        if bool(self.mongo_user) ^ bool(mongo_pwd):  # xor","path":"src/jgikbase/idmapping/config.py","position":93,"original_position":93,"commit_id":"806849b31a312f2a1eddd7b3789fb71cb90722c5","original_commit_id":"806849b31a312f2a1eddd7b3789fb71cb90722c5","user":{"login":"jayrbolton","id":8740476,"node_id":"MDQ6VXNlcjg3NDA0NzY=","avatar_url":"https://avatars0.githubusercontent.com/u/8740476?v=4","gravatar_id":"","url":"https://api.github.com/users/jayrbolton","html_url":"https://github.com/jayrbolton","followers_url":"https://api.github.com/users/jayrbolton/followers","following_url":"https://api.github.com/users/jayrbolton/following{/other_user}","gists_url":"https://api.github.com/users/jayrbolton/gists{/gist_id}","starred_url":"https://api.github.com/users/jayrbolton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jayrbolton/subscriptions","organizations_url":"https://api.github.com/users/jayrbolton/orgs","repos_url":"https://api.github.com/users/jayrbolton/repos","events_url":"https://api.github.com/users/jayrbolton/events{/privacy}","received_events_url":"https://api.github.com/users/jayrbolton/received_events","type":"User","site_admin":false},"body":"If the server only actually supports mongo, and both of these are blank, will an error be raised down the line on server bootup?","created_at":"2018-08-08T17:19:15Z","updated_at":"2018-08-08T17:19:15Z","html_url":"https://github.com/jgi-kbase/IDMappingService/pull/67#discussion_r208664926","pull_request_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/pulls/67","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/jgi-kbase/IDMappingService/pulls/comments/208664926"},"html":{"href":"https://github.com/jgi-kbase/IDMappingService/pull/67#discussion_r208664926"},"pull_request":{"href":"https://api.github.com/repos/jgi-kbase/IDMappingService/pulls/67"}}},"pull_request":{"url":"https://api.github.com/repos/jgi-kbase/IDMappingService/pulls/67","id":206872800,"node_id":"MDExOlB1bGxSZXF1ZXN0MjA2ODcyODAw","html_url":"https://github.com/jgi-kbase/IDMappingService/pull/67","diff_url":"https://github.com/jgi-kbase/IDMappingService/pull/67.diff","patch_url":"https://github.com/jgi-kbase/IDMappingService/pull/67.patch","issue_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/issues/67","number":67,"state":"open","locked":false,"title":"SCT-1251 Add configuration class","user":{"login":"MrCreosote","id":1686141,"node_id":"MDQ6VXNlcjE2ODYxNDE=","avatar_url":"https://avatars1.githubusercontent.com/u/1686141?v=4","gravatar_id":"","url":"https://api.github.com/users/MrCreosote","html_url":"https://github.com/MrCreosote","followers_url":"https://api.github.com/users/MrCreosote/followers","following_url":"https://api.github.com/users/MrCreosote/following{/other_user}","gists_url":"https://api.github.com/users/MrCreosote/gists{/gist_id}","starred_url":"https://api.github.com/users/MrCreosote/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MrCreosote/subscriptions","organizations_url":"https://api.github.com/users/MrCreosote/orgs","repos_url":"https://api.github.com/users/MrCreosote/repos","events_url":"https://api.github.com/users/MrCreosote/events{/privacy}","received_events_url":"https://api.github.com/users/MrCreosote/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-08-08T02:01:21Z","updated_at":"2018-08-08T17:19:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9a3a1e23d3479b676ad7631e862a6ba3614bc055","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/pulls/67/commits","review_comments_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/pulls/67/comments","review_comment_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/pulls/comments{/number}","comments_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/issues/67/comments","statuses_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/statuses/806849b31a312f2a1eddd7b3789fb71cb90722c5","head":{"label":"MrCreosote:dev-prototype","ref":"dev-prototype","sha":"806849b31a312f2a1eddd7b3789fb71cb90722c5","user":{"login":"MrCreosote","id":1686141,"node_id":"MDQ6VXNlcjE2ODYxNDE=","avatar_url":"https://avatars1.githubusercontent.com/u/1686141?v=4","gravatar_id":"","url":"https://api.github.com/users/MrCreosote","html_url":"https://github.com/MrCreosote","followers_url":"https://api.github.com/users/MrCreosote/followers","following_url":"https://api.github.com/users/MrCreosote/following{/other_user}","gists_url":"https://api.github.com/users/MrCreosote/gists{/gist_id}","starred_url":"https://api.github.com/users/MrCreosote/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MrCreosote/subscriptions","organizations_url":"https://api.github.com/users/MrCreosote/orgs","repos_url":"https://api.github.com/users/MrCreosote/repos","events_url":"https://api.github.com/users/MrCreosote/events{/privacy}","received_events_url":"https://api.github.com/users/MrCreosote/received_events","type":"User","site_admin":false},"repo":{"id":139476819,"node_id":"MDEwOlJlcG9zaXRvcnkxMzk0NzY4MTk=","name":"IDMappingService","full_name":"MrCreosote/IDMappingService","owner":{"login":"MrCreosote","id":1686141,"node_id":"MDQ6VXNlcjE2ODYxNDE=","avatar_url":"https://avatars1.githubusercontent.com/u/1686141?v=4","gravatar_id":"","url":"https://api.github.com/users/MrCreosote","html_url":"https://github.com/MrCreosote","followers_url":"https://api.github.com/users/MrCreosote/followers","following_url":"https://api.github.com/users/MrCreosote/following{/other_user}","gists_url":"https://api.github.com/users/MrCreosote/gists{/gist_id}","starred_url":"https://api.github.com/users/MrCreosote/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MrCreosote/subscriptions","organizations_url":"https://api.github.com/users/MrCreosote/orgs","repos_url":"https://api.github.com/users/MrCreosote/repos","events_url":"https://api.github.com/users/MrCreosote/events{/privacy}","received_events_url":"https://api.github.com/users/MrCreosote/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/MrCreosote/IDMappingService","description":"Service for mapping data IDs between namespaces.","fork":true,"url":"https://api.github.com/repos/MrCreosote/IDMappingService","forks_url":"https://api.github.com/repos/MrCreosote/IDMappingService/forks","keys_url":"https://api.github.com/repos/MrCreosote/IDMappingService/keys{/key_id}","collaborators_url":"https://api.github.com/repos/MrCreosote/IDMappingService/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/MrCreosote/IDMappingService/teams","hooks_url":"https://api.github.com/repos/MrCreosote/IDMappingService/hooks","issue_events_url":"https://api.github.com/repos/MrCreosote/IDMappingService/issues/events{/number}","events_url":"https://api.github.com/repos/MrCreosote/IDMappingService/events","assignees_url":"https://api.github.com/repos/MrCreosote/IDMappingService/assignees{/user}","branches_url":"https://api.github.com/repos/MrCreosote/IDMappingService/branches{/branch}","tags_url":"https://api.github.com/repos/MrCreosote/IDMappingService/tags","blobs_url":"https://api.github.com/repos/MrCreosote/IDMappingService/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/MrCreosote/IDMappingService/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/MrCreosote/IDMappingService/git/refs{/sha}","trees_url":"https://api.github.com/repos/MrCreosote/IDMappingService/git/trees{/sha}","statuses_url":"https://api.github.com/repos/MrCreosote/IDMappingService/statuses/{sha}","languages_url":"https://api.github.com/repos/MrCreosote/IDMappingService/languages","stargazers_url":"https://api.github.com/repos/MrCreosote/IDMappingService/stargazers","contributors_url":"https://api.github.com/repos/MrCreosote/IDMappingService/contributors","subscribers_url":"https://api.github.com/repos/MrCreosote/IDMappingService/subscribers","subscription_url":"https://api.github.com/repos/MrCreosote/IDMappingService/subscription","commits_url":"https://api.github.com/repos/MrCreosote/IDMappingService/commits{/sha}","git_commits_url":"https://api.github.com/repos/MrCreosote/IDMappingService/git/commits{/sha}","comments_url":"https://api.github.com/repos/MrCreosote/IDMappingService/comments{/number}","issue_comment_url":"https://api.github.com/repos/MrCreosote/IDMappingService/issues/comments{/number}","contents_url":"https://api.github.com/repos/MrCreosote/IDMappingService/contents/{+path}","compare_url":"https://api.github.com/repos/MrCreosote/IDMappingService/compare/{base}...{head}","merges_url":"https://api.github.com/repos/MrCreosote/IDMappingService/merges","archive_url":"https://api.github.com/repos/MrCreosote/IDMappingService/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/MrCreosote/IDMappingService/downloads","issues_url":"https://api.github.com/repos/MrCreosote/IDMappingService/issues{/number}","pulls_url":"https://api.github.com/repos/MrCreosote/IDMappingService/pulls{/number}","milestones_url":"https://api.github.com/repos/MrCreosote/IDMappingService/milestones{/number}","notifications_url":"https://api.github.com/repos/MrCreosote/IDMappingService/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/MrCreosote/IDMappingService/labels{/name}","releases_url":"https://api.github.com/repos/MrCreosote/IDMappingService/releases{/id}","deployments_url":"https://api.github.com/repos/MrCreosote/IDMappingService/deployments","created_at":"2018-07-02T17:56:57Z","updated_at":"2018-07-02T17:56:59Z","pushed_at":"2018-08-08T01:57:00Z","git_url":"git://github.com/MrCreosote/IDMappingService.git","ssh_url":"git@github.com:MrCreosote/IDMappingService.git","clone_url":"https://github.com/MrCreosote/IDMappingService.git","svn_url":"https://github.com/MrCreosote/IDMappingService","homepage":null,"size":237,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"jgi-kbase:dev-prototype","ref":"dev-prototype","sha":"3b3902bb9420bd58d6c931b8d875057b31f26d17","user":{"login":"jgi-kbase","id":39579250,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM5NTc5MjUw","avatar_url":"https://avatars1.githubusercontent.com/u/39579250?v=4","gravatar_id":"","url":"https://api.github.com/users/jgi-kbase","html_url":"https://github.com/jgi-kbase","followers_url":"https://api.github.com/users/jgi-kbase/followers","following_url":"https://api.github.com/users/jgi-kbase/following{/other_user}","gists_url":"https://api.github.com/users/jgi-kbase/gists{/gist_id}","starred_url":"https://api.github.com/users/jgi-kbase/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jgi-kbase/subscriptions","organizations_url":"https://api.github.com/users/jgi-kbase/orgs","repos_url":"https://api.github.com/users/jgi-kbase/repos","events_url":"https://api.github.com/users/jgi-kbase/events{/privacy}","received_events_url":"https://api.github.com/users/jgi-kbase/received_events","type":"Organization","site_admin":false},"repo":{"id":139476171,"node_id":"MDEwOlJlcG9zaXRvcnkxMzk0NzYxNzE=","name":"IDMappingService","full_name":"jgi-kbase/IDMappingService","owner":{"login":"jgi-kbase","id":39579250,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM5NTc5MjUw","avatar_url":"https://avatars1.githubusercontent.com/u/39579250?v=4","gravatar_id":"","url":"https://api.github.com/users/jgi-kbase","html_url":"https://github.com/jgi-kbase","followers_url":"https://api.github.com/users/jgi-kbase/followers","following_url":"https://api.github.com/users/jgi-kbase/following{/other_user}","gists_url":"https://api.github.com/users/jgi-kbase/gists{/gist_id}","starred_url":"https://api.github.com/users/jgi-kbase/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jgi-kbase/subscriptions","organizations_url":"https://api.github.com/users/jgi-kbase/orgs","repos_url":"https://api.github.com/users/jgi-kbase/repos","events_url":"https://api.github.com/users/jgi-kbase/events{/privacy}","received_events_url":"https://api.github.com/users/jgi-kbase/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/jgi-kbase/IDMappingService","description":"Service for mapping data IDs between namespaces.","fork":false,"url":"https://api.github.com/repos/jgi-kbase/IDMappingService","forks_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/forks","keys_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/teams","hooks_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/hooks","issue_events_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/issues/events{/number}","events_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/events","assignees_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/assignees{/user}","branches_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/branches{/branch}","tags_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/tags","blobs_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/git/refs{/sha}","trees_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/statuses/{sha}","languages_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/languages","stargazers_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/stargazers","contributors_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/contributors","subscribers_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/subscribers","subscription_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/subscription","commits_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/commits{/sha}","git_commits_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/git/commits{/sha}","comments_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/comments{/number}","issue_comment_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/issues/comments{/number}","contents_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/contents/{+path}","compare_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/merges","archive_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/downloads","issues_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/issues{/number}","pulls_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/pulls{/number}","milestones_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/milestones{/number}","notifications_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/labels{/name}","releases_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/releases{/id}","deployments_url":"https://api.github.com/repos/jgi-kbase/IDMappingService/deployments","created_at":"2018-07-02T17:50:35Z","updated_at":"2018-07-02T17:56:40Z","pushed_at":"2018-08-08T02:01:21Z","git_url":"git://github.com/jgi-kbase/IDMappingService.git","ssh_url":"git@github.com:jgi-kbase/IDMappingService.git","clone_url":"https://github.com/jgi-kbase/IDMappingService.git","svn_url":"https://github.com/jgi-kbase/IDMappingService","homepage":null,"size":266,"stargazers_count":0,"watchers_count":0,"language":null,"has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":1,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/jgi-kbase/IDMappingService/pulls/67"},"html":{"href":"https://github.com/jgi-kbase/IDMappingService/pull/67"},"issue":{"href":"https://api.github.com/repos/jgi-kbase/IDMappingService/issues/67"},"comments":{"href":"https://api.github.com/repos/jgi-kbase/IDMappingService/issues/67/comments"},"review_comments":{"href":"https://api.github.com/repos/jgi-kbase/IDMappingService/pulls/67/comments"},"review_comment":{"href":"https://api.github.com/repos/jgi-kbase/IDMappingService/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/jgi-kbase/IDMappingService/pulls/67/commits"},"statuses":{"href":"https://api.github.com/repos/jgi-kbase/IDMappingService/statuses/806849b31a312f2a1eddd7b3789fb71cb90722c5"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"jayrbolton"}}