Skip to content

Commit 49d027d

Browse files
committed
Initial support for App Properties
1 parent c323c7c commit 49d027d

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
@@ -53,6 +53,8 @@
5353
from jira.resilientsession import PrepareRequestForRetry, ResilientSession
5454
from jira.resources import (
5555
AgileResource,
56+
AppProperty,
57+
AtlassianConnectResource,
5658
Attachment,
5759
Board,
5860
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,
@@ -424,6 +427,7 @@ def __init__(
424427
* rest_path -- the root REST path to use. Defaults to ``api``, where the Jira REST resources live.
425428
* rest_api_version -- the version of the REST resources under rest_path to use. Defaults to ``2``.
426429
* agile_rest_path - the REST path to use for Jira Agile requests. Defaults to ``agile``.
430+
* ace_rest_api_version -- the version of the REST resource to use for Jira Atlassian Connect. Defaults to ``1``.
427431
* verify (Union[bool, str]) -- Verify SSL certs. (Default: ``True``).
428432
Or path to a CA_BUNDLE file or directory with certificates of trusted CAs, for the `requests` library to use.
429433
* 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.
@@ -3662,6 +3666,62 @@ def kill_session(self) -> Response:
36623666
url = self.server_url + "/rest/auth/latest/session"
36633667
return self._session.delete(url)
36643668

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

jira/resources.py

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

14061406

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

14091440

0 commit comments

Comments
 (0)