Skip to content

Commit 7ec16c6

Browse files
add helper to get current content guid when running in connect
1 parent 274f1d6 commit 7ec16c6

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/posit/connect/content.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from __future__ import annotations
44

5+
import os
56
import posixpath
67
import time
78

@@ -1000,3 +1001,16 @@ def get(self, guid: str) -> ContentItem:
10001001

10011002
response = self._ctx.client.get(f"v1/content/{guid}", params=params)
10021003
return ContentItem(self._ctx, **response.json())
1004+
1005+
@property
1006+
def current(self) -> ContentItem:
1007+
"""Get the content item for the current context.
1008+
1009+
Returns
1010+
-------
1011+
ContentItem
1012+
"""
1013+
guid = os.getenv("CONNECT_CONTENT_GUID")
1014+
if not guid:
1015+
raise RuntimeError("CONNECT_CONTENT_GUID environment variable is not set.")
1016+
return self.get(guid)

0 commit comments

Comments
 (0)