Skip to content

Commit df0c492

Browse files
authored
Feature - Added Managed Identity authentication option to Enhanced Citations Storage Account Admin Setting (#412)
Bugfix 1 - Removed duplicate logo_version setting Bugfix 2 - Fixed Video Indexer settings in Admin Settings Setup Walkthrough so that API Key is optional since Video Indexer requires ARM authentication now instead of API Key auth
1 parent 1c93e7f commit df0c492

File tree

5 files changed

+78
-19
lines changed

5 files changed

+78
-19
lines changed

application/single_app/config.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -611,11 +611,14 @@ def initialize_clients(settings):
611611

612612
try:
613613
if enable_enhanced_citations:
614-
blob_service_client = BlobServiceClient.from_connection_string(settings.get("office_docs_storage_account_url"))
615-
CLIENTS["storage_account_office_docs_client"] = blob_service_client
616-
617-
# Create containers if they don't exist
618-
# This addresses the issue where the application assumes containers exist
614+
if settings.get("office_docs_authentication_type") == "key":
615+
blob_service_client = BlobServiceClient.from_connection_string(settings.get("office_docs_storage_account_url"))
616+
CLIENTS["storage_account_office_docs_client"] = blob_service_client
617+
if settings.get("office_docs_authentication_type") == "managed_identity":
618+
blob_service_client = BlobServiceClient(account_url=settings.get("office_docs_storage_account_blob_endpoint"), credential=DefaultAzureCredential())
619+
CLIENTS["storage_account_office_docs_client"] = blob_service_client
620+
# Create containers if they don't exist
621+
# This addresses the issue where the application assumes containers exist
619622
for container_name in [
620623
storage_account_user_documents_container_name,
621624
storage_account_group_documents_container_name,

application/single_app/functions_settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ def get_settings():
151151
'enable_enhanced_citations_mount': False,
152152
'enhanced_citations_mount': '/view_documents',
153153
'office_docs_storage_account_url': '',
154+
'office_docs_storage_account_blob_endpoint': '',
154155
'office_docs_authentication_type': 'key',
155156
'office_docs_key': '',
156157
'video_files_storage_account_url': '',

application/single_app/route_frontend_admin_settings.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,13 @@ def admin_settings():
309309

310310
# Enhanced Citations...
311311
enable_enhanced_citations = form_data.get('enable_enhanced_citations') == 'on'
312+
office_docs_storage_account_blob_endpoint = form_data.get('office_docs_storage_account_blob_endpoint', '').strip()
312313
office_docs_storage_account_url = form_data.get('office_docs_storage_account_url', '').strip()
314+
313315

314316
# Validate that if enhanced citations are enabled, a connection string is provided
315-
if enable_enhanced_citations and not office_docs_storage_account_url:
316-
flash("Enhanced Citations cannot be enabled without providing a connection string. Feature has been disabled.", "danger")
317+
if enable_enhanced_citations and not (office_docs_storage_account_blob_endpoint or office_docs_storage_account_url):
318+
flash("Enhanced Citations cannot be enabled without providing a connection string or blob service endpoint. Feature has been disabled.", "danger")
317319
enable_enhanced_citations = False
318320

319321
# Model JSON Parsing (Your existing logic is fine)
@@ -386,7 +388,6 @@ def is_valid_url(url):
386388
'logo_version': settings.get('logo_version', 1),
387389
'custom_logo_dark_base64': settings.get('custom_logo_dark_base64', ''),
388390
'logo_dark_version': settings.get('logo_dark_version', 1),
389-
'logo_version': settings.get('logo_version', 1),
390391
'custom_favicon_base64': settings.get('custom_favicon_base64', ''),
391392
'favicon_version': settings.get('favicon_version', 1),
392393
'landing_page_text': form_data.get('landing_page_text', ''),
@@ -477,6 +478,7 @@ def is_valid_url(url):
477478
'enable_enhanced_citations': enable_enhanced_citations,
478479
'enable_enhanced_citations_mount': form_data.get('enable_enhanced_citations_mount') == 'on' and enable_enhanced_citations,
479480
'enhanced_citations_mount': form_data.get('enhanced_citations_mount', '/view_documents').strip(),
481+
'office_docs_storage_account_blob_endpoint': office_docs_storage_account_blob_endpoint,
480482
'office_docs_storage_account_url': office_docs_storage_account_url,
481483
'office_docs_authentication_type': form_data.get('office_docs_authentication_type', 'key'),
482484
'office_docs_key': form_data.get('office_docs_key', '').strip(),
@@ -817,6 +819,7 @@ def is_valid_url(url):
817819
if updated_settings_for_file:
818820
ensure_custom_logo_file_exists(app, updated_settings_for_file)
819821
ensure_custom_favicon_file_exists(app, updated_settings_for_file)
822+
initialize_clients(updated_settings_for_file) # Important - reinitialize clients with new settings
820823
else:
821824
print("ERROR: Could not fetch settings after update to ensure logo/favicon files.")
822825

application/single_app/static/js/admin/admin_settings.js

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,14 +1471,42 @@ function setupToggles() {
14711471
}
14721472

14731473
const officeAuthType = document.getElementById('office_docs_authentication_type');
1474-
if (officeAuthType) {
1475-
officeAuthType.addEventListener('change', function(){
1476-
document.getElementById('office_docs_key_container').style.display =
1477-
(this.value === 'key') ? 'block' : 'none';
1474+
const connStrGroup = document.getElementById('office_docs_storage_conn_str_group');
1475+
const urlGroup = document.getElementById('office_docs_storage_url_group');
1476+
const connStrInput = document.getElementById('office_docs_storage_account_url');
1477+
const urlInput = document.getElementById('office_docs_storage_account_blob_endpoint');
1478+
1479+
if (officeAuthType && connStrGroup && urlGroup && connStrInput && urlInput) {
1480+
officeAuthType.addEventListener('change', function() {
1481+
if (this.value === 'managed_identity') {
1482+
connStrGroup.style.display = 'none';
1483+
urlGroup.style.display = '';
1484+
} else {
1485+
connStrGroup.style.display = '';
1486+
urlGroup.style.display = 'none';
1487+
}
14781488
markFormAsModified();
14791489
});
14801490
}
14811491

1492+
// Toggle visibility of connection string
1493+
const toggleConnStrBtn = document.getElementById('toggle_office_conn_str');
1494+
if (toggleConnStrBtn && connStrInput) {
1495+
toggleConnStrBtn.addEventListener('click', function() {
1496+
connStrInput.type = connStrInput.type === 'password' ? 'text' : 'password';
1497+
toggleConnStrBtn.textContent = connStrInput.type === 'password' ? 'Show' : 'Hide';
1498+
});
1499+
}
1500+
1501+
// Toggle visibility of blob service endpoint URL
1502+
const toggleUrlBtn = document.getElementById('toggle_office_url');
1503+
if (toggleUrlBtn && urlInput) {
1504+
toggleUrlBtn.addEventListener('click', function() {
1505+
urlInput.type = urlInput.type === 'password' ? 'text' : 'password';
1506+
toggleUrlBtn.textContent = urlInput.type === 'password' ? 'Show' : 'Hide';
1507+
});
1508+
}
1509+
14821510
const videoAuthType = document.getElementById('video_files_authentication_type');
14831511
if (videoAuthType) {
14841512
videoAuthType.addEventListener('change', function(){
@@ -2084,7 +2112,7 @@ togglePassword('toggle_azure_apim_document_intelligence_subscription_key', 'azur
20842112
togglePassword('toggle_office_docs_key', 'office_docs_key');
20852113
togglePassword('toggle_video_files_key', 'video_files_key');
20862114
togglePassword('toggle_audio_files_key', 'audio_files_key');
2087-
togglePassword('toggle_office_conn_str', 'office_docs_storage_account_url');
2115+
togglePassword('toggle_office_conn_str', 'office_docs_storage_account_blob_endpoint');
20882116
togglePassword('toggle_video_conn_str', 'video_files_storage_account_url');
20892117
togglePassword('toggle_audio_conn_str', 'audio_files_storage_account_url');
20902118
togglePassword('toggle_video_indexer_api_key', 'video_indexer_api_key');
@@ -2675,11 +2703,11 @@ function isStepComplete(stepNumber) {
26752703
if (!workspacesEnabled || !videoEnabled) return true;
26762704

26772705
// Otherwise check settings
2706+
const videoEndpoint = document.getElementById('video_indexer_endpoint')?.value;
26782707
const videoLocation = document.getElementById('video_indexer_location')?.value;
26792708
const videoAccountId = document.getElementById('video_indexer_account_id')?.value;
2680-
const videoApiKey = document.getElementById('video_indexer_api_key')?.value;
26812709

2682-
return videoLocation && videoAccountId && videoApiKey;
2710+
return videoLocation && videoAccountId && videoEndpoint;
26832711

26842712
case 9: // Audio support
26852713
const audioEnabled = document.getElementById('enable_audio_file_support').checked || false;

application/single_app/templates/admin_settings.html

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ <h4>8. Enable Video File Support</h4>
349349
</li>
350350
<li class="list-group-item d-flex justify-content-between align-items-center">
351351
<span>Video Indexer API Key</span>
352-
<span id="video-key-badge" class="badge bg-danger">Required</span>
352+
<span class="badge bg-secondary">Optional</span>
353353
</li>
354354
</ul>
355355
</div>
@@ -1863,21 +1863,45 @@ <h5>Enhanced Citations</h5>
18631863
<div class="card mb-3 p-3">
18641864
<h6><strong>All filetypes</strong></h6>
18651865
<div class="mb-3">
1866+
<label for="office_docs_authentication_type" class="form-label">
1867+
Storage Account Authentication Type
1868+
</label>
1869+
<select class="form-select" id="office_docs_authentication_type" name="office_docs_authentication_type">
1870+
<option value="key" {% if settings.office_docs_authentication_type == "key" or not settings.office_docs_authentication_type %}selected{% endif %}>Connection String</option>
1871+
<option value="managed_identity" {% if settings.office_docs_authentication_type == "managed_identity" %}selected{% endif %}>Managed Identity</option>
1872+
</select>
1873+
</div>
1874+
1875+
<div class="mb-3" id="office_docs_storage_conn_str_group" {% if settings.office_docs_authentication_type == "managed_identity" %}style="display:none;"{% endif %}>
18661876
<label for="office_docs_storage_account_url" class="form-label">
18671877
Storage Account Connection String
18681878
</label>
1869-
18701879
<div class="input-group">
18711880
<input
1872-
type="password"
1881+
type="password"
18731882
class="form-control"
18741883
id="office_docs_storage_account_url"
18751884
name="office_docs_storage_account_url"
18761885
value="{{ settings.office_docs_storage_account_url or '' }}"
18771886
>
18781887
<button type="button" class="btn btn-outline-secondary" id="toggle_office_conn_str">Show</button>
18791888
</div>
1880-
1889+
</div>
1890+
1891+
<div class="mb-3" id="office_docs_storage_url_group" {% if settings.office_docs_authentication_type != "managed_identity" %}style="display:none;"{% endif %}>
1892+
<label for="office_docs_storage_account_blob_endpoint" class="form-label">
1893+
Storage Account Blob Service Endpoint
1894+
</label>
1895+
<div class="input-group">
1896+
<input
1897+
type="password"
1898+
class="form-control"
1899+
id="office_docs_storage_account_blob_endpoint"
1900+
name="office_docs_storage_account_blob_endpoint"
1901+
value="{{ settings.office_docs_storage_account_blob_endpoint or '' }}"
1902+
>
1903+
<button type="button" class="btn btn-outline-secondary" id="toggle_office_url">Show</button>
1904+
</div>
18811905
</div>
18821906
</div>
18831907

0 commit comments

Comments
 (0)