Skip to content

Commit f0e73eb

Browse files
add helper to get current content guid when running in connect
1 parent 7f3bf8c commit f0e73eb

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

@@ -996,3 +997,16 @@ def get(self, guid: str) -> ContentItem:
996997
"""
997998
response = self._ctx.client.get(f"v1/content/{guid}")
998999
return ContentItem(self._ctx, **response.json())
1000+
1001+
@property
1002+
def current(self) -> ContentItem:
1003+
"""Get the content item for the current context.
1004+
1005+
Returns
1006+
-------
1007+
ContentItem
1008+
"""
1009+
guid = os.getenv("CONNECT_CONTENT_GUID")
1010+
if not guid:
1011+
raise RuntimeError("CONNECT_CONTENT_GUID environment variable is not set.")
1012+
return self.get(guid)

0 commit comments

Comments
 (0)