Skip to content

Commit 3f0f8af

Browse files
committed
Initial support for App Properties
1 parent 3b5b7b4 commit 3f0f8af

File tree

2 files changed

+91
-0
lines changed

2 files changed

+91
-0
lines changed

jira/client.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
from jira.resilientsession import PrepareRequestForRetry, ResilientSession
5555
from jira.resources import (
5656
AgileResource,
57+
AppProperty,
58+
AtlassianConnectResource,
5759
Attachment,
5860
Board,
5961
Comment,
@@ -352,6 +354,7 @@ class JIRA:
352354
"rest_api_version": "2",
353355
"agile_rest_path": AgileResource.AGILE_BASE_REST_PATH,
354356
"agile_rest_api_version": "1.0",
357+
"ace_rest_api_version": "1",
355358
"verify": True,
356359
"resilient": True,
357360
"async": False,
@@ -426,6 +429,7 @@ def __init__(
426429
* rest_path -- the root REST path to use. Defaults to ``api``, where the Jira REST resources live.
427430
* rest_api_version -- the version of the REST resources under rest_path to use. Defaults to ``2``.
428431
* agile_rest_path - the REST path to use for Jira Agile requests. Defaults to ``agile``.
432+
* ace_rest_api_version -- the version of the REST resource to use for Jira Atlassian Connect. Defaults to ``1``.
429433
* verify (Union[bool, str]) -- Verify SSL certs. (Default: ``True``).
430434
Or path to a CA_BUNDLE file or directory with certificates of trusted CAs, for the `requests` library to use.
431435
* client_cert (Union[str, Tuple[str,str]]) -- Path to file with both cert and key or a tuple of (cert,key), for the `requests` library to use for client side SSL.
@@ -3668,6 +3672,62 @@ def kill_session(self) -> Response:
36683672
url = self.server_url + "/rest/auth/latest/session"
36693673
return self._session.delete(url)
36703674

3675+
# App properties
3676+
3677+
def app_properties(self, addon_key: str) -> List[AppProperty]:
3678+
"""Get a list of app properties.
3679+
3680+
Args:
3681+
addon_key (str): The key of the app, as defined in its descriptor
3682+
3683+
Returns:
3684+
List[AppProperty]
3685+
"""
3686+
r_json = self._get_json(
3687+
"addons/" + addon_key + "/properties",
3688+
base=AtlassianConnectResource.ACE_BASE_URL,
3689+
)
3690+
properties = [
3691+
AppProperty(
3692+
self._options,
3693+
self._session,
3694+
json_loads(self._session.get(raw_ap_json["self"])),
3695+
)
3696+
for raw_ap_json in r_json["keys"]
3697+
]
3698+
return properties
3699+
3700+
def app_property(self, addon_key: str, property_key: str) -> AppProperty:
3701+
"""Get an app property Resource from the server.
3702+
3703+
Args:
3704+
addon_key (str): The key of the app, as defined in its descriptor
3705+
property_key (str): The key of the property
3706+
3707+
Returns:
3708+
AppProperty
3709+
"""
3710+
return self._find_for_resource(AppProperty, (addon_key, property_key))
3711+
3712+
def create_app_property(
3713+
self, addon_key: str, property_key: str, data: Dict[str, Any]
3714+
) -> Response:
3715+
"""Create a new app property.
3716+
3717+
Args:
3718+
addon_key (str): The key of the app, as defined in its descriptor
3719+
property_key (str): The key of the property
3720+
data (Dict[str, Any]): The property value
3721+
3722+
Returns:
3723+
Response
3724+
"""
3725+
url = self._get_url(
3726+
"addons/" + addon_key + "/properties/" + property_key,
3727+
base=AtlassianConnectResource.ACE_BASE_URL,
3728+
)
3729+
return self._session.put(url, data=json.dumps(data))
3730+
36713731
# Websudo
36723732
def kill_websudo(self) -> Optional[Response]:
36733733
"""Destroy the user's current WebSudo session.

jira/resources.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,6 +1405,37 @@ def __init__(
14051405
self.raw: Dict[str, Any] = cast(Dict[str, Any], self.raw)
14061406

14071407

1408+
# AtlassianConnect
1409+
1410+
1411+
class AtlassianConnectResource(Resource):
1412+
"""A generic AtlassianConnect resource."""
1413+
1414+
ACE_BASE_URL = "{server}/rest/atlassian-connect/{ace_rest_api_version}/{path}"
1415+
1416+
def __init__(self, path, options, session, raw):
1417+
self.self = None
1418+
1419+
Resource.__init__(self, path, options, session, self.ACE_BASE_URL)
1420+
if raw:
1421+
self._parse_raw(raw)
1422+
1423+
1424+
class AppProperty(AtlassianConnectResource):
1425+
"""An AtlassianConnect app property."""
1426+
1427+
PATH = "addons/{0}/properties/{1}"
1428+
1429+
def __init__(self, options, session, raw=None):
1430+
AtlassianConnectResource.__init__(self, self.PATH, options, session, raw)
1431+
if raw:
1432+
self._parse_raw(raw)
1433+
1434+
def find(self, id, params=None):
1435+
Resource.find(self, id, params)
1436+
self.self = self._get_url(self.PATH.format(*id))
1437+
1438+
14081439
# Utilities
14091440

14101441

0 commit comments

Comments
 (0)