Skip to content

Commit c120557

Browse files
jeremymanningclaude
andcommitted
Fix Lambda Cloud API key validation in widget test configuration
## Problems Fixed: - **Field Name Mismatch**: Fixed lookup from "api_key" to "lambda_api_key" - **No Real API Validation**: Added actual Lambda Cloud API connectivity testing - **Generic Error Messages**: Now provides specific feedback on API authentication ## Technical Changes: - Add `_test_lambda_connectivity()` method that calls Lambda Cloud API - Update `_test_cloud_connectivity()` to include Lambda Cloud - Fix test configuration to use correct field name (`lambda_api_key`) - Separate Lambda Cloud from generic provider handling for proper validation ## User Experience Improvements: - **With valid API key**: "✅ Lambda Cloud API connection successful" - **With invalid API key**: "❌ Lambda Cloud API connection failed (check API key)" - **With no API key**: "❌ Lambda Cloud API key is required" - **Connection issues**: Proper error handling and messaging Now widget "Test Configuration" actually validates API keys against Lambda Cloud servers. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent a507202 commit c120557

File tree

1 file changed

+51
-9
lines changed

1 file changed

+51
-9
lines changed

clustrix/notebook_magic.py

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1923,6 +1923,8 @@ def _test_cloud_connectivity(self, cluster_type, config):
19231923
return self._test_azure_connectivity(config)
19241924
elif cluster_type == "gcp":
19251925
return self._test_gcp_connectivity(config)
1926+
elif cluster_type == "lambda_cloud":
1927+
return self._test_lambda_connectivity(config)
19261928
else:
19271929
return False
19281930
except Exception:
@@ -1995,6 +1997,25 @@ def _test_gcp_connectivity(self, config):
19951997
except Exception:
19961998
return False
19971999

2000+
def _test_lambda_connectivity(self, config):
2001+
"""Test Lambda Cloud API connectivity."""
2002+
try:
2003+
from .cloud_providers.lambda_cloud import LambdaCloudProvider
2004+
2005+
api_key = config.get("lambda_api_key")
2006+
if not api_key:
2007+
return False
2008+
2009+
# Create provider instance and test authentication
2010+
provider = LambdaCloudProvider()
2011+
return provider.authenticate(api_key=api_key)
2012+
2013+
except ImportError:
2014+
print("ℹ️ Lambda Cloud provider not available for testing")
2015+
return False
2016+
except Exception:
2017+
return False
2018+
19982019
def _on_test_config(self, button):
19992020
"""Test the current configuration."""
20002021
with self.status_output:
@@ -2216,19 +2237,40 @@ def _on_test_config(self, button):
22162237

22172238
print("✅ GCP configuration appears valid")
22182239

2219-
elif cluster_type in ["lambda_cloud", "huggingface_spaces"]:
2220-
# Test other cloud providers
2221-
provider_name = cluster_type.replace("_", " ").title()
2222-
print(f"- Provider: {provider_name}")
2240+
elif cluster_type == "lambda_cloud":
2241+
# Test Lambda Cloud configuration
2242+
print("- Provider: Lambda Cloud")
22232243

2224-
# Basic validation for these providers
2225-
api_key = config.get("api_key", "")
2244+
# Check for Lambda Cloud API key
2245+
api_key = config.get("lambda_api_key", "")
22262246
if api_key:
2227-
print("✅ API key provided")
2247+
print("✅ Lambda Cloud API key provided")
2248+
2249+
# Test Lambda Cloud API connectivity
2250+
print("🔌 Testing Lambda Cloud API connectivity...")
2251+
if self._test_cloud_connectivity("lambda_cloud", config):
2252+
print("✅ Lambda Cloud API connection successful")
2253+
else:
2254+
print(
2255+
"❌ Lambda Cloud API connection failed (check API key)"
2256+
)
2257+
else:
2258+
print("❌ Lambda Cloud API key is required")
2259+
2260+
print("✅ Lambda Cloud configuration validation completed")
2261+
2262+
elif cluster_type == "huggingface_spaces":
2263+
# Test HuggingFace Spaces configuration
2264+
print("- Provider: HuggingFace Spaces")
2265+
2266+
# Basic validation for HuggingFace
2267+
hf_token = config.get("hf_token", "")
2268+
if hf_token:
2269+
print("✅ HuggingFace token provided")
22282270
else:
2229-
print("⚠️ API key may be required")
2271+
print("⚠️ HuggingFace token may be required")
22302272

2231-
print(f"✅ {provider_name} configuration appears valid")
2273+
print("✅ HuggingFace Spaces configuration appears valid")
22322274

22332275
else:
22342276
print(f"⚠️ Unknown cluster type: {cluster_type}")

0 commit comments

Comments
 (0)