Skip to content

Commit 6726785

Browse files
authored
Automatically parse GUID from input string (#261)
1 parent b4e445e commit 6726785

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

extensions/content-health-monitor/content-health-monitor.qmd

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ connect_server = get_env_var("CONNECT_SERVER") # Automatically provided by Conne
3030
api_key = get_env_var("CONNECT_API_KEY") # Automatically provided by Connect, must be set when previewing locally
3131
monitored_content_guid = get_env_var("MONITORED_CONTENT_GUID")
3232
33+
# Extract GUID if it's a string or URL containing a GUID
34+
if monitored_content_guid:
35+
monitored_content_guid = extract_guid(monitored_content_guid)
36+
3337
# Only instantiate the client if we have the required environment variables
3438
client = None
3539
if not show_instructions:

extensions/content-health-monitor/content_health_utils.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import os
3+
import re
34
import requests
45
from posit import connect
56

@@ -94,6 +95,27 @@ def format_error_message(exception):
9495

9596
return error_message
9697

98+
# Function to extract GUID string or URL
99+
def extract_guid(input_string):
100+
"""
101+
Extract GUID from a string or URL.
102+
103+
Args:
104+
input_string: String that may contain a GUID
105+
106+
Returns:
107+
str: Extracted GUID or original string if no GUID found
108+
"""
109+
# Match UUIDs in various formats that might appear in URLs
110+
guid_pattern = re.compile(r'[0-9a-fA-F]{8}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{4}-?[0-9a-fA-F]{12}')
111+
112+
match = guid_pattern.search(input_string)
113+
if match:
114+
return match.group(0)
115+
116+
# Return original string if no GUID found
117+
return input_string
118+
97119
# Function to get content details from Connect API
98120
def get_content(client, guid):
99121
try:

0 commit comments

Comments
 (0)