We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
SubCA autogenerated descriptions for their certs are incorrect
If you create a root CA, and look up the certificate for that CA its description is: 
This is the ROOT certificate for the $CN certificate authority.
If you create a subCA off of that rootCA, and look up the certificate for that SubCA its description is: 
This is the ROOT certificate for the $CN certificate authority


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `lemur/authorities/service.py`
Content:
```
1 """
2 .. module: lemur.authorities.service
3     :platform: Unix
4     :synopsis: This module contains all of the services level functions used to
5     administer authorities in Lemur
6     :copyright: (c) 2015 by Netflix Inc., see AUTHORS for more
7     :license: Apache, see LICENSE for more details.
8 .. moduleauthor:: Kevin Glisson <kglisson@netflix.com>
9 
10 """
11 from flask import g
12 from flask import current_app
13 
14 from lemur import database
15 from lemur.authorities.models import Authority
16 from lemur.roles import service as role_service
17 from lemur.notifications import service as notification_service
18 
19 from lemur.roles.models import Role
20 from lemur.certificates.models import Certificate
21 
22 from lemur.plugins.base import plugins
23 
24 
25 def update(authority_id, description=None, owner=None, active=None, roles=None):
26     """
27     Update a an authority with new values.
28 
29     :param authority_id:
30     :param roles: roles that are allowed to use this authority
31     :rtype : Authority
32     :return:
33     """
34     authority = get(authority_id)
35     if roles:
36         authority = database.update_list(authority, 'roles', Role, roles)
37 
38     if active:
39         authority.active = active
40 
41     authority.description = description
42     authority.owner = owner
43     return database.update(authority)
44 
45 
46 def create(kwargs):
47     """
48     Create a new authority.
49 
50     :rtype : Authority
51     :return:
52     """
53 
54     issuer = plugins.get(kwargs.get('pluginName'))
55 
56     kwargs['creator'] = g.current_user.email
57     cert_body, intermediate, issuer_roles = issuer.create_authority(kwargs)
58 
59     cert = Certificate(cert_body, chain=intermediate)
60     cert.owner = kwargs['ownerEmail']
61     cert.description = "This is the ROOT certificate for the {0} certificate authority".format(kwargs.get('caName'))
62     cert.user = g.current_user
63 
64     cert.notifications = notification_service.create_default_expiration_notifications(
65         'DEFAULT_SECURITY',
66         current_app.config.get('LEMUR_SECURITY_TEAM_EMAIL')
67     )
68 
69     # we create and attach any roles that the issuer gives us
70     role_objs = []
71     for r in issuer_roles:
72 
73         role = role_service.create(
74             r['name'],
75             password=r['password'],
76             description="{0} auto generated role".format(kwargs.get('pluginName')),
77             username=r['username'])
78 
79         # the user creating the authority should be able to administer it
80         if role.username == 'admin':
81             g.current_user.roles.append(role)
82 
83         role_objs.append(role)
84 
85     authority = Authority(
86         kwargs.get('caName'),
87         kwargs['ownerEmail'],
88         kwargs['pluginName'],
89         cert_body,
90         description=kwargs['caDescription'],
91         chain=intermediate,
92         roles=role_objs
93     )
94 
95     database.update(cert)
96     authority = database.create(authority)
97 
98     g.current_user.authorities.append(authority)
99 
100     return authority
101 
102 
103 def get_all():
104     """
105     Get all authorities that are currently in Lemur.
106 
107     :rtype : List
108     :return:
109     """
110     query = database.session_query(Authority)
111     return database.find_all(query, Authority, {}).all()
112 
113 
114 def get(authority_id):
115     """
116     Retrieves an authority given it's ID
117 
118     :rtype : Authority
119     :param authority_id:
120     :return:
121     """
122     return database.get(Authority, authority_id)
123 
124 
125 def get_by_name(authority_name):
126     """
127     Retrieves an authority given it's name.
128 
129     :param authority_name:
130     :rtype : Authority
131     :return:
132     """
133     return database.get(Authority, authority_name, field='name')
134 
135 
136 def get_authority_role(ca_name):
137     """
138     Attempts to get the authority role for a given ca uses current_user
139     as a basis for accomplishing that.
140 
141     :param ca_name:
142     """
143     if g.current_user.is_admin:
144         authority = get_by_name(ca_name)
145         # TODO we should pick admin ca roles for admin
146         return authority.roles[0]
147     else:
148         for role in g.current_user.roles:
149             if role.authority:
150                 if role.authority.name == ca_name:
151                     return role
152 
153 
154 def render(args):
155     """
156     Helper that helps us render the REST Api responses.
157     :param args:
158     :return:
159     """
160     query = database.session_query(Authority)
161     sort_by = args.pop('sort_by')
162     sort_dir = args.pop('sort_dir')
163     page = args.pop('page')
164     count = args.pop('count')
165     filt = args.pop('filter')
166 
167     if filt:
168         terms = filt.split(';')
169         if 'active' in filt:  # this is really weird but strcmp seems to not work here??
170             query = query.filter(Authority.active == terms[1])
171         else:
172             query = database.filter(query, Authority, terms)
173 
174     # we make sure that a user can only use an authority they either own are are a member of - admins can see all
175     if not g.current_user.is_admin:
176         authority_ids = []
177         for role in g.current_user.roles:
178             if role.authority:
179                 authority_ids.append(role.authority.id)
180         query = query.filter(Authority.id.in_(authority_ids))
181 
182     query = database.find_all(query, Authority, args)
183 
184     if sort_by and sort_dir:
185         query = database.sort(query, Authority, sort_by, sort_dir)
186 
187     return database.paginate(query, page, count)
188
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/lemur/authorities/service.py b/lemur/authorities/service.py
--- a/lemur/authorities/service.py
+++ b/lemur/authorities/service.py
@@ -58,7 +58,15 @@
 
     cert = Certificate(cert_body, chain=intermediate)
     cert.owner = kwargs['ownerEmail']
-    cert.description = "This is the ROOT certificate for the {0} certificate authority".format(kwargs.get('caName'))
+
+    if kwargs['caType'] == 'subca':
+        cert.description = "This is the ROOT certificate for the {0} sub certificate authority the parent \
+                                authority is {1}.".format(kwargs.get('caName'), kwargs.get('caParent'))
+    else:
+        cert.description = "This is the ROOT certificate for the {0} certificate authority.".format(
+            kwargs.get('caName')
+        )
+
     cert.user = g.current_user
 
     cert.notifications = notification_service.create_default_expiration_notifications(

{"golden_diff": "diff --git a/lemur/authorities/service.py b/lemur/authorities/service.py\n--- a/lemur/authorities/service.py\n+++ b/lemur/authorities/service.py\n@@ -58,7 +58,15 @@\n \n     cert = Certificate(cert_body, chain=intermediate)\n     cert.owner = kwargs['ownerEmail']\n-    cert.description = \"This is the ROOT certificate for the {0} certificate authority\".format(kwargs.get('caName'))\n+\n+    if kwargs['caType'] == 'subca':\n+        cert.description = \"This is the ROOT certificate for the {0} sub certificate authority the parent \\\n+                                authority is {1}.\".format(kwargs.get('caName'), kwargs.get('caParent'))\n+    else:\n+        cert.description = \"This is the ROOT certificate for the {0} certificate authority.\".format(\n+            kwargs.get('caName')\n+        )\n+\n     cert.user = g.current_user\n \n     cert.notifications = notification_service.create_default_expiration_notifications(\n", "issue": "SubCA autogenerated descriptions for their certs are incorrect\nIf you create a root CA, and look up the certificate for that CA its description is: \nThis is the ROOT certificate for the $CN certificate authority.\nIf you create a subCA off of that rootCA, and look up the certificate for that SubCA its description is: \nThis is the ROOT certificate for the $CN certificate authority\n\n", "before_files": [{"content": "\"\"\"\n.. module: lemur.authorities.service\n    :platform: Unix\n    :synopsis: This module contains all of the services level functions used to\n    administer authorities in Lemur\n    :copyright: (c) 2015 by Netflix Inc., see AUTHORS for more\n    :license: Apache, see LICENSE for more details.\n.. moduleauthor:: Kevin Glisson <kglisson@netflix.com>\n\n\"\"\"\nfrom flask import g\nfrom flask import current_app\n\nfrom lemur import database\nfrom lemur.authorities.models import Authority\nfrom lemur.roles import service as role_service\nfrom lemur.notifications import service as notification_service\n\nfrom lemur.roles.models import Role\nfrom lemur.certificates.models import Certificate\n\nfrom lemur.plugins.base import plugins\n\n\ndef update(authority_id, description=None, owner=None, active=None, roles=None):\n    \"\"\"\n    Update a an authority with new values.\n\n    :param authority_id:\n    :param roles: roles that are allowed to use this authority\n    :rtype : Authority\n    :return:\n    \"\"\"\n    authority = get(authority_id)\n    if roles:\n        authority = database.update_list(authority, 'roles', Role, roles)\n\n    if active:\n        authority.active = active\n\n    authority.description = description\n    authority.owner = owner\n    return database.update(authority)\n\n\ndef create(kwargs):\n    \"\"\"\n    Create a new authority.\n\n    :rtype : Authority\n    :return:\n    \"\"\"\n\n    issuer = plugins.get(kwargs.get('pluginName'))\n\n    kwargs['creator'] = g.current_user.email\n    cert_body, intermediate, issuer_roles = issuer.create_authority(kwargs)\n\n    cert = Certificate(cert_body, chain=intermediate)\n    cert.owner = kwargs['ownerEmail']\n    cert.description = \"This is the ROOT certificate for the {0} certificate authority\".format(kwargs.get('caName'))\n    cert.user = g.current_user\n\n    cert.notifications = notification_service.create_default_expiration_notifications(\n        'DEFAULT_SECURITY',\n        current_app.config.get('LEMUR_SECURITY_TEAM_EMAIL')\n    )\n\n    # we create and attach any roles that the issuer gives us\n    role_objs = []\n    for r in issuer_roles:\n\n        role = role_service.create(\n            r['name'],\n            password=r['password'],\n            description=\"{0} auto generated role\".format(kwargs.get('pluginName')),\n            username=r['username'])\n\n        # the user creating the authority should be able to administer it\n        if role.username == 'admin':\n            g.current_user.roles.append(role)\n\n        role_objs.append(role)\n\n    authority = Authority(\n        kwargs.get('caName'),\n        kwargs['ownerEmail'],\n        kwargs['pluginName'],\n        cert_body,\n        description=kwargs['caDescription'],\n        chain=intermediate,\n        roles=role_objs\n    )\n\n    database.update(cert)\n    authority = database.create(authority)\n\n    g.current_user.authorities.append(authority)\n\n    return authority\n\n\ndef get_all():\n    \"\"\"\n    Get all authorities that are currently in Lemur.\n\n    :rtype : List\n    :return:\n    \"\"\"\n    query = database.session_query(Authority)\n    return database.find_all(query, Authority, {}).all()\n\n\ndef get(authority_id):\n    \"\"\"\n    Retrieves an authority given it's ID\n\n    :rtype : Authority\n    :param authority_id:\n    :return:\n    \"\"\"\n    return database.get(Authority, authority_id)\n\n\ndef get_by_name(authority_name):\n    \"\"\"\n    Retrieves an authority given it's name.\n\n    :param authority_name:\n    :rtype : Authority\n    :return:\n    \"\"\"\n    return database.get(Authority, authority_name, field='name')\n\n\ndef get_authority_role(ca_name):\n    \"\"\"\n    Attempts to get the authority role for a given ca uses current_user\n    as a basis for accomplishing that.\n\n    :param ca_name:\n    \"\"\"\n    if g.current_user.is_admin:\n        authority = get_by_name(ca_name)\n        # TODO we should pick admin ca roles for admin\n        return authority.roles[0]\n    else:\n        for role in g.current_user.roles:\n            if role.authority:\n                if role.authority.name == ca_name:\n                    return role\n\n\ndef render(args):\n    \"\"\"\n    Helper that helps us render the REST Api responses.\n    :param args:\n    :return:\n    \"\"\"\n    query = database.session_query(Authority)\n    sort_by = args.pop('sort_by')\n    sort_dir = args.pop('sort_dir')\n    page = args.pop('page')\n    count = args.pop('count')\n    filt = args.pop('filter')\n\n    if filt:\n        terms = filt.split(';')\n        if 'active' in filt:  # this is really weird but strcmp seems to not work here??\n            query = query.filter(Authority.active == terms[1])\n        else:\n            query = database.filter(query, Authority, terms)\n\n    # we make sure that a user can only use an authority they either own are are a member of - admins can see all\n    if not g.current_user.is_admin:\n        authority_ids = []\n        for role in g.current_user.roles:\n            if role.authority:\n                authority_ids.append(role.authority.id)\n        query = query.filter(Authority.id.in_(authority_ids))\n\n    query = database.find_all(query, Authority, args)\n\n    if sort_by and sort_dir:\n        query = database.sort(query, Authority, sort_by, sort_dir)\n\n    return database.paginate(query, page, count)\n", "path": "lemur/authorities/service.py"}], "after_files": [{"content": "\"\"\"\n.. module: lemur.authorities.service\n    :platform: Unix\n    :synopsis: This module contains all of the services level functions used to\n    administer authorities in Lemur\n    :copyright: (c) 2015 by Netflix Inc., see AUTHORS for more\n    :license: Apache, see LICENSE for more details.\n.. moduleauthor:: Kevin Glisson <kglisson@netflix.com>\n\n\"\"\"\nfrom flask import g\nfrom flask import current_app\n\nfrom lemur import database\nfrom lemur.authorities.models import Authority\nfrom lemur.roles import service as role_service\nfrom lemur.notifications import service as notification_service\n\nfrom lemur.roles.models import Role\nfrom lemur.certificates.models import Certificate\n\nfrom lemur.plugins.base import plugins\n\n\ndef update(authority_id, description=None, owner=None, active=None, roles=None):\n    \"\"\"\n    Update a an authority with new values.\n\n    :param authority_id:\n    :param roles: roles that are allowed to use this authority\n    :rtype : Authority\n    :return:\n    \"\"\"\n    authority = get(authority_id)\n    if roles:\n        authority = database.update_list(authority, 'roles', Role, roles)\n\n    if active:\n        authority.active = active\n\n    authority.description = description\n    authority.owner = owner\n    return database.update(authority)\n\n\ndef create(kwargs):\n    \"\"\"\n    Create a new authority.\n\n    :rtype : Authority\n    :return:\n    \"\"\"\n\n    issuer = plugins.get(kwargs.get('pluginName'))\n\n    kwargs['creator'] = g.current_user.email\n    cert_body, intermediate, issuer_roles = issuer.create_authority(kwargs)\n\n    cert = Certificate(cert_body, chain=intermediate)\n    cert.owner = kwargs['ownerEmail']\n\n    if kwargs['caType'] == 'subca':\n        cert.description = \"This is the ROOT certificate for the {0} sub certificate authority the parent \\\n                                authority is {1}.\".format(kwargs.get('caName'), kwargs.get('caParent'))\n    else:\n        cert.description = \"This is the ROOT certificate for the {0} certificate authority.\".format(\n            kwargs.get('caName')\n        )\n\n    cert.user = g.current_user\n\n    cert.notifications = notification_service.create_default_expiration_notifications(\n        'DEFAULT_SECURITY',\n        current_app.config.get('LEMUR_SECURITY_TEAM_EMAIL')\n    )\n\n    # we create and attach any roles that the issuer gives us\n    role_objs = []\n    for r in issuer_roles:\n\n        role = role_service.create(\n            r['name'],\n            password=r['password'],\n            description=\"{0} auto generated role\".format(kwargs.get('pluginName')),\n            username=r['username'])\n\n        # the user creating the authority should be able to administer it\n        if role.username == 'admin':\n            g.current_user.roles.append(role)\n\n        role_objs.append(role)\n\n    authority = Authority(\n        kwargs.get('caName'),\n        kwargs['ownerEmail'],\n        kwargs['pluginName'],\n        cert_body,\n        description=kwargs['caDescription'],\n        chain=intermediate,\n        roles=role_objs\n    )\n\n    database.update(cert)\n    authority = database.create(authority)\n\n    g.current_user.authorities.append(authority)\n\n    return authority\n\n\ndef get_all():\n    \"\"\"\n    Get all authorities that are currently in Lemur.\n\n    :rtype : List\n    :return:\n    \"\"\"\n    query = database.session_query(Authority)\n    return database.find_all(query, Authority, {}).all()\n\n\ndef get(authority_id):\n    \"\"\"\n    Retrieves an authority given it's ID\n\n    :rtype : Authority\n    :param authority_id:\n    :return:\n    \"\"\"\n    return database.get(Authority, authority_id)\n\n\ndef get_by_name(authority_name):\n    \"\"\"\n    Retrieves an authority given it's name.\n\n    :param authority_name:\n    :rtype : Authority\n    :return:\n    \"\"\"\n    return database.get(Authority, authority_name, field='name')\n\n\ndef get_authority_role(ca_name):\n    \"\"\"\n    Attempts to get the authority role for a given ca uses current_user\n    as a basis for accomplishing that.\n\n    :param ca_name:\n    \"\"\"\n    if g.current_user.is_admin:\n        authority = get_by_name(ca_name)\n        # TODO we should pick admin ca roles for admin\n        return authority.roles[0]\n    else:\n        for role in g.current_user.roles:\n            if role.authority:\n                if role.authority.name == ca_name:\n                    return role\n\n\ndef render(args):\n    \"\"\"\n    Helper that helps us render the REST Api responses.\n    :param args:\n    :return:\n    \"\"\"\n    query = database.session_query(Authority)\n    sort_by = args.pop('sort_by')\n    sort_dir = args.pop('sort_dir')\n    page = args.pop('page')\n    count = args.pop('count')\n    filt = args.pop('filter')\n\n    if filt:\n        terms = filt.split(';')\n        if 'active' in filt:  # this is really weird but strcmp seems to not work here??\n            query = query.filter(Authority.active == terms[1])\n        else:\n            query = database.filter(query, Authority, terms)\n\n    # we make sure that a user can only use an authority they either own are are a member of - admins can see all\n    if not g.current_user.is_admin:\n        authority_ids = []\n        for role in g.current_user.roles:\n            if role.authority:\n                authority_ids.append(role.authority.id)\n        query = query.filter(Authority.id.in_(authority_ids))\n\n    query = database.find_all(query, Authority, args)\n\n    if sort_by and sort_dir:\n        query = database.sort(query, Authority, sort_by, sort_dir)\n\n    return database.paginate(query, page, count)\n", "path": "lemur/authorities/service.py"}]}