{"action":"created","comment":{"url":"https://api.github.com/repos/SUNET/eduid-common/pulls/comments/215935223","pull_request_review_id":153311564,"id":215935223,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxNTkzNTIyMw==","diff_hunk":"@@ -0,0 +1,83 @@\n+# -*- coding: utf-8 -*-\n+\n+from __future__ import absolute_import\n+\n+import logging\n+from functools import wraps\n+from nacl import secret, encoding, exceptions\n+\n+from eduid_common.config.parsers.exceptions import SecretKeyException\n+\n+__author__ = 'lundberg'\n+\n+\n+def decrypt(f):\n+    @wraps(f)\n+    def decrypt_decorator(*args, **kwargs):\n+        config_dict = f(*args, **kwargs)\n+        decrypted_config_dict = decrypt_config(config_dict)\n+        return decrypted_config_dict\n+\n+    return decrypt_decorator\n+\n+\n+def read_secret_key(key_name):\n+    \"\"\"\n+    :param key_name: Key file name\n+    :type key_name: six.string_types\n+    :return: 32 bytes of secret data\n+    :rtype: bytes\n+    \"\"\"\n+    sanitized_key_name = \"\".join([c for c in key_name if c.isalpha() or c.isdigit() or c == '_'])\n+    fp = '/run/secrets/{}'.format(sanitized_key_name)\n+    with open(fp) as f:\n+        return encoding.URLSafeBase64Encoder.decode(f.readline())\n+\n+\n+def init_secret_box(key_name=None, secret_key=None):\n+    \"\"\"\n+    :param key_name: Key file name\n+    :type key_name: six.string_types\n+    :param secret_key: 32 bytes of secret data\n+    :type secret_key: bytes\n+    :return: SecretBox\n+    :rtype: SecretBox\n+    \"\"\"\n+    if not secret_key:\n+        try:\n+            secret_key = read_secret_key(key_name)\n+        except IOError as e:\n+            raise SecretKeyException(str(e))\n+    return secret.SecretBox(secret_key)\n+\n+\n+def decrypt_config(config_dict):\n+    \"\"\"\n+    :param config_dict: Configuration dictionary\n+    :type config_dict: dict\n+    :return: Configuration dictionary\n+    :rtype: dict\n+    \"\"\"\n+    boxes = {}\n+    for key, value in config_dict.items():\n+        if key.endswith('_ENCRYPTED'):\n+            for item in value:\n+                key_name = item['key_name']\n+                value = item['value']\n+\n+                if not boxes.get(key_name):\n+                    try:\n+                        boxes[key_name] = init_secret_box(key_name=key_name)\n+                    except SecretKeyException as e:\n+                        logging.error(e)","path":"src/eduid_common/config/parsers/decorators.py","position":72,"original_position":72,"commit_id":"7e101768594332ba9304ce63708cc2591aaad834","original_commit_id":"7e101768594332ba9304ce63708cc2591aaad834","user":{"login":"fredrikt","id":166095,"node_id":"MDQ6VXNlcjE2NjA5NQ==","avatar_url":"https://avatars0.githubusercontent.com/u/166095?v=4","gravatar_id":"","url":"https://api.github.com/users/fredrikt","html_url":"https://github.com/fredrikt","followers_url":"https://api.github.com/users/fredrikt/followers","following_url":"https://api.github.com/users/fredrikt/following{/other_user}","gists_url":"https://api.github.com/users/fredrikt/gists{/gist_id}","starred_url":"https://api.github.com/users/fredrikt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fredrikt/subscriptions","organizations_url":"https://api.github.com/users/fredrikt/orgs","repos_url":"https://api.github.com/users/fredrikt/repos","events_url":"https://api.github.com/users/fredrikt/events{/privacy}","received_events_url":"https://api.github.com/users/fredrikt/received_events","type":"User","site_admin":false},"body":"since this includes \"could not find the key x\" I don't think it should be logged with error priority -  it isn't an error until the `value' can't be decrypted at all","created_at":"2018-09-07T11:57:26Z","updated_at":"2018-09-07T11:57:27Z","html_url":"https://github.com/SUNET/eduid-common/pull/107#discussion_r215935223","pull_request_url":"https://api.github.com/repos/SUNET/eduid-common/pulls/107","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/SUNET/eduid-common/pulls/comments/215935223"},"html":{"href":"https://github.com/SUNET/eduid-common/pull/107#discussion_r215935223"},"pull_request":{"href":"https://api.github.com/repos/SUNET/eduid-common/pulls/107"}}},"pull_request":{"url":"https://api.github.com/repos/SUNET/eduid-common/pulls/107","id":213902365,"node_id":"MDExOlB1bGxSZXF1ZXN0MjEzOTAyMzY1","html_url":"https://github.com/SUNET/eduid-common/pull/107","diff_url":"https://github.com/SUNET/eduid-common/pull/107.diff","patch_url":"https://github.com/SUNET/eduid-common/pull/107.patch","issue_url":"https://api.github.com/repos/SUNET/eduid-common/issues/107","number":107,"state":"open","locked":false,"title":"Support for encrypted config values","user":{"login":"johanlundberg","id":105702,"node_id":"MDQ6VXNlcjEwNTcwMg==","avatar_url":"https://avatars3.githubusercontent.com/u/105702?v=4","gravatar_id":"","url":"https://api.github.com/users/johanlundberg","html_url":"https://github.com/johanlundberg","followers_url":"https://api.github.com/users/johanlundberg/followers","following_url":"https://api.github.com/users/johanlundberg/following{/other_user}","gists_url":"https://api.github.com/users/johanlundberg/gists{/gist_id}","starred_url":"https://api.github.com/users/johanlundberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johanlundberg/subscriptions","organizations_url":"https://api.github.com/users/johanlundberg/orgs","repos_url":"https://api.github.com/users/johanlundberg/repos","events_url":"https://api.github.com/users/johanlundberg/events{/privacy}","received_events_url":"https://api.github.com/users/johanlundberg/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-09-07T11:43:48Z","updated_at":"2018-09-07T11:57:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"15c568e63fe177b654667af3e0530028d9ac6903","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/SUNET/eduid-common/pulls/107/commits","review_comments_url":"https://api.github.com/repos/SUNET/eduid-common/pulls/107/comments","review_comment_url":"https://api.github.com/repos/SUNET/eduid-common/pulls/comments{/number}","comments_url":"https://api.github.com/repos/SUNET/eduid-common/issues/107/comments","statuses_url":"https://api.github.com/repos/SUNET/eduid-common/statuses/7e101768594332ba9304ce63708cc2591aaad834","head":{"label":"SUNET:config_decrypt","ref":"config_decrypt","sha":"7e101768594332ba9304ce63708cc2591aaad834","user":{"login":"SUNET","id":3405039,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM0MDUwMzk=","avatar_url":"https://avatars3.githubusercontent.com/u/3405039?v=4","gravatar_id":"","url":"https://api.github.com/users/SUNET","html_url":"https://github.com/SUNET","followers_url":"https://api.github.com/users/SUNET/followers","following_url":"https://api.github.com/users/SUNET/following{/other_user}","gists_url":"https://api.github.com/users/SUNET/gists{/gist_id}","starred_url":"https://api.github.com/users/SUNET/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SUNET/subscriptions","organizations_url":"https://api.github.com/users/SUNET/orgs","repos_url":"https://api.github.com/users/SUNET/repos","events_url":"https://api.github.com/users/SUNET/events{/privacy}","received_events_url":"https://api.github.com/users/SUNET/received_events","type":"Organization","site_admin":false},"repo":{"id":46415799,"node_id":"MDEwOlJlcG9zaXRvcnk0NjQxNTc5OQ==","name":"eduid-common","full_name":"SUNET/eduid-common","owner":{"login":"SUNET","id":3405039,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM0MDUwMzk=","avatar_url":"https://avatars3.githubusercontent.com/u/3405039?v=4","gravatar_id":"","url":"https://api.github.com/users/SUNET","html_url":"https://github.com/SUNET","followers_url":"https://api.github.com/users/SUNET/followers","following_url":"https://api.github.com/users/SUNET/following{/other_user}","gists_url":"https://api.github.com/users/SUNET/gists{/gist_id}","starred_url":"https://api.github.com/users/SUNET/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SUNET/subscriptions","organizations_url":"https://api.github.com/users/SUNET/orgs","repos_url":"https://api.github.com/users/SUNET/repos","events_url":"https://api.github.com/users/SUNET/events{/privacy}","received_events_url":"https://api.github.com/users/SUNET/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SUNET/eduid-common","description":"eduID common code","fork":false,"url":"https://api.github.com/repos/SUNET/eduid-common","forks_url":"https://api.github.com/repos/SUNET/eduid-common/forks","keys_url":"https://api.github.com/repos/SUNET/eduid-common/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SUNET/eduid-common/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SUNET/eduid-common/teams","hooks_url":"https://api.github.com/repos/SUNET/eduid-common/hooks","issue_events_url":"https://api.github.com/repos/SUNET/eduid-common/issues/events{/number}","events_url":"https://api.github.com/repos/SUNET/eduid-common/events","assignees_url":"https://api.github.com/repos/SUNET/eduid-common/assignees{/user}","branches_url":"https://api.github.com/repos/SUNET/eduid-common/branches{/branch}","tags_url":"https://api.github.com/repos/SUNET/eduid-common/tags","blobs_url":"https://api.github.com/repos/SUNET/eduid-common/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SUNET/eduid-common/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SUNET/eduid-common/git/refs{/sha}","trees_url":"https://api.github.com/repos/SUNET/eduid-common/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SUNET/eduid-common/statuses/{sha}","languages_url":"https://api.github.com/repos/SUNET/eduid-common/languages","stargazers_url":"https://api.github.com/repos/SUNET/eduid-common/stargazers","contributors_url":"https://api.github.com/repos/SUNET/eduid-common/contributors","subscribers_url":"https://api.github.com/repos/SUNET/eduid-common/subscribers","subscription_url":"https://api.github.com/repos/SUNET/eduid-common/subscription","commits_url":"https://api.github.com/repos/SUNET/eduid-common/commits{/sha}","git_commits_url":"https://api.github.com/repos/SUNET/eduid-common/git/commits{/sha}","comments_url":"https://api.github.com/repos/SUNET/eduid-common/comments{/number}","issue_comment_url":"https://api.github.com/repos/SUNET/eduid-common/issues/comments{/number}","contents_url":"https://api.github.com/repos/SUNET/eduid-common/contents/{+path}","compare_url":"https://api.github.com/repos/SUNET/eduid-common/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SUNET/eduid-common/merges","archive_url":"https://api.github.com/repos/SUNET/eduid-common/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SUNET/eduid-common/downloads","issues_url":"https://api.github.com/repos/SUNET/eduid-common/issues{/number}","pulls_url":"https://api.github.com/repos/SUNET/eduid-common/pulls{/number}","milestones_url":"https://api.github.com/repos/SUNET/eduid-common/milestones{/number}","notifications_url":"https://api.github.com/repos/SUNET/eduid-common/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SUNET/eduid-common/labels{/name}","releases_url":"https://api.github.com/repos/SUNET/eduid-common/releases{/id}","deployments_url":"https://api.github.com/repos/SUNET/eduid-common/deployments","created_at":"2015-11-18T11:56:53Z","updated_at":"2018-09-07T11:47:03Z","pushed_at":"2018-09-07T11:47:41Z","git_url":"git://github.com/SUNET/eduid-common.git","ssh_url":"git@github.com:SUNET/eduid-common.git","clone_url":"https://github.com/SUNET/eduid-common.git","svn_url":"https://github.com/SUNET/eduid-common","homepage":null,"size":642,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"archived":false,"open_issues_count":2,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause","node_id":"MDc6TGljZW5zZTU="},"forks":2,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"SUNET:master","ref":"master","sha":"f76f052e79abcfd18064564387a1fe820c96293b","user":{"login":"SUNET","id":3405039,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM0MDUwMzk=","avatar_url":"https://avatars3.githubusercontent.com/u/3405039?v=4","gravatar_id":"","url":"https://api.github.com/users/SUNET","html_url":"https://github.com/SUNET","followers_url":"https://api.github.com/users/SUNET/followers","following_url":"https://api.github.com/users/SUNET/following{/other_user}","gists_url":"https://api.github.com/users/SUNET/gists{/gist_id}","starred_url":"https://api.github.com/users/SUNET/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SUNET/subscriptions","organizations_url":"https://api.github.com/users/SUNET/orgs","repos_url":"https://api.github.com/users/SUNET/repos","events_url":"https://api.github.com/users/SUNET/events{/privacy}","received_events_url":"https://api.github.com/users/SUNET/received_events","type":"Organization","site_admin":false},"repo":{"id":46415799,"node_id":"MDEwOlJlcG9zaXRvcnk0NjQxNTc5OQ==","name":"eduid-common","full_name":"SUNET/eduid-common","owner":{"login":"SUNET","id":3405039,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM0MDUwMzk=","avatar_url":"https://avatars3.githubusercontent.com/u/3405039?v=4","gravatar_id":"","url":"https://api.github.com/users/SUNET","html_url":"https://github.com/SUNET","followers_url":"https://api.github.com/users/SUNET/followers","following_url":"https://api.github.com/users/SUNET/following{/other_user}","gists_url":"https://api.github.com/users/SUNET/gists{/gist_id}","starred_url":"https://api.github.com/users/SUNET/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SUNET/subscriptions","organizations_url":"https://api.github.com/users/SUNET/orgs","repos_url":"https://api.github.com/users/SUNET/repos","events_url":"https://api.github.com/users/SUNET/events{/privacy}","received_events_url":"https://api.github.com/users/SUNET/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/SUNET/eduid-common","description":"eduID common code","fork":false,"url":"https://api.github.com/repos/SUNET/eduid-common","forks_url":"https://api.github.com/repos/SUNET/eduid-common/forks","keys_url":"https://api.github.com/repos/SUNET/eduid-common/keys{/key_id}","collaborators_url":"https://api.github.com/repos/SUNET/eduid-common/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/SUNET/eduid-common/teams","hooks_url":"https://api.github.com/repos/SUNET/eduid-common/hooks","issue_events_url":"https://api.github.com/repos/SUNET/eduid-common/issues/events{/number}","events_url":"https://api.github.com/repos/SUNET/eduid-common/events","assignees_url":"https://api.github.com/repos/SUNET/eduid-common/assignees{/user}","branches_url":"https://api.github.com/repos/SUNET/eduid-common/branches{/branch}","tags_url":"https://api.github.com/repos/SUNET/eduid-common/tags","blobs_url":"https://api.github.com/repos/SUNET/eduid-common/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/SUNET/eduid-common/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/SUNET/eduid-common/git/refs{/sha}","trees_url":"https://api.github.com/repos/SUNET/eduid-common/git/trees{/sha}","statuses_url":"https://api.github.com/repos/SUNET/eduid-common/statuses/{sha}","languages_url":"https://api.github.com/repos/SUNET/eduid-common/languages","stargazers_url":"https://api.github.com/repos/SUNET/eduid-common/stargazers","contributors_url":"https://api.github.com/repos/SUNET/eduid-common/contributors","subscribers_url":"https://api.github.com/repos/SUNET/eduid-common/subscribers","subscription_url":"https://api.github.com/repos/SUNET/eduid-common/subscription","commits_url":"https://api.github.com/repos/SUNET/eduid-common/commits{/sha}","git_commits_url":"https://api.github.com/repos/SUNET/eduid-common/git/commits{/sha}","comments_url":"https://api.github.com/repos/SUNET/eduid-common/comments{/number}","issue_comment_url":"https://api.github.com/repos/SUNET/eduid-common/issues/comments{/number}","contents_url":"https://api.github.com/repos/SUNET/eduid-common/contents/{+path}","compare_url":"https://api.github.com/repos/SUNET/eduid-common/compare/{base}...{head}","merges_url":"https://api.github.com/repos/SUNET/eduid-common/merges","archive_url":"https://api.github.com/repos/SUNET/eduid-common/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/SUNET/eduid-common/downloads","issues_url":"https://api.github.com/repos/SUNET/eduid-common/issues{/number}","pulls_url":"https://api.github.com/repos/SUNET/eduid-common/pulls{/number}","milestones_url":"https://api.github.com/repos/SUNET/eduid-common/milestones{/number}","notifications_url":"https://api.github.com/repos/SUNET/eduid-common/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/SUNET/eduid-common/labels{/name}","releases_url":"https://api.github.com/repos/SUNET/eduid-common/releases{/id}","deployments_url":"https://api.github.com/repos/SUNET/eduid-common/deployments","created_at":"2015-11-18T11:56:53Z","updated_at":"2018-09-07T11:47:03Z","pushed_at":"2018-09-07T11:47:41Z","git_url":"git://github.com/SUNET/eduid-common.git","ssh_url":"git@github.com:SUNET/eduid-common.git","clone_url":"https://github.com/SUNET/eduid-common.git","svn_url":"https://github.com/SUNET/eduid-common","homepage":null,"size":642,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"archived":false,"open_issues_count":2,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause","node_id":"MDc6TGljZW5zZTU="},"forks":2,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/SUNET/eduid-common/pulls/107"},"html":{"href":"https://github.com/SUNET/eduid-common/pull/107"},"issue":{"href":"https://api.github.com/repos/SUNET/eduid-common/issues/107"},"comments":{"href":"https://api.github.com/repos/SUNET/eduid-common/issues/107/comments"},"review_comments":{"href":"https://api.github.com/repos/SUNET/eduid-common/pulls/107/comments"},"review_comment":{"href":"https://api.github.com/repos/SUNET/eduid-common/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/SUNET/eduid-common/pulls/107/commits"},"statuses":{"href":"https://api.github.com/repos/SUNET/eduid-common/statuses/7e101768594332ba9304ce63708cc2591aaad834"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"fredrikt"}}