Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions core/Azure.Mcp.Core/src/Services/Azure/BaseAzureService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,20 @@ protected static void ValidateRequiredParameters(params string?[] parameters)
ArgumentException.ThrowIfNullOrEmpty(param);
}
}

/// <summary>
/// Validates that the provided named parameters are not null or empty
/// </summary>
/// <param name="namedParameters">Array of tuples containing parameter names and values to validate</param>
/// <exception cref="ArgumentException">Thrown when any parameter is null or empty</exception>
protected static void ValidateRequiredParameters(params (string name, string? value)[] namedParameters)
{
foreach (var (name, value) in namedParameters)
{
if (string.IsNullOrEmpty(value))
{
throw new ArgumentException($"Parameter '{name}' is null or empty", name);
}
}
}
}
19 changes: 14 additions & 5 deletions tools/Azure.Mcp.Tools.Kusto/src/Services/KustoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public async Task<List<string>> ListClustersAsync(
string? tenant = null,
RetryPolicyOptions? retryPolicy = null)
{
ValidateRequiredParameters(subscriptionId);
ValidateRequiredParameters((nameof(subscriptionId), subscriptionId));

try
{
Expand All @@ -66,7 +66,7 @@ public async Task<KustoClusterModel> GetClusterAsync(
string? tenant = null,
RetryPolicyOptions? retryPolicy = null)
{
ValidateRequiredParameters(subscriptionId);
ValidateRequiredParameters((nameof(subscriptionId), subscriptionId));

try
{
Expand Down Expand Up @@ -101,7 +101,9 @@ public async Task<List<string>> ListDatabasesAsync(
AuthMethod.Credential,
RetryPolicyOptions? retryPolicy = null)
{
ValidateRequiredParameters(subscriptionId, clusterName);
ValidateRequiredParameters(
(nameof(subscriptionId), subscriptionId),
(nameof(clusterName), clusterName));

string clusterUri = await GetClusterUriAsync(subscriptionId, clusterName, tenant, retryPolicy);
return await ListDatabasesAsync(clusterUri, tenant, authMethod, retryPolicy);
Expand Down Expand Up @@ -131,7 +133,10 @@ public async Task<List<string>> ListTablesAsync(
AuthMethod? authMethod = AuthMethod.Credential,
RetryPolicyOptions? retryPolicy = null)
{
ValidateRequiredParameters(subscriptionId, clusterName, databaseName);
ValidateRequiredParameters(
(nameof(subscriptionId), subscriptionId),
(nameof(clusterName), clusterName),
(nameof(databaseName), databaseName));

string clusterUri = await GetClusterUriAsync(subscriptionId, clusterName, tenant, retryPolicy);
return await ListTablesAsync(clusterUri, databaseName, tenant, authMethod, retryPolicy);
Expand Down Expand Up @@ -199,7 +204,11 @@ public async Task<List<JsonElement>> QueryItemsAsync(
AuthMethod? authMethod = AuthMethod.Credential,
RetryPolicyOptions? retryPolicy = null)
{
ValidateRequiredParameters(subscriptionId, clusterName, databaseName, query);
ValidateRequiredParameters(
(nameof(subscriptionId), subscriptionId),
(nameof(clusterName), clusterName),
(nameof(databaseName), databaseName),
(nameof(query), query));

string clusterUri = await GetClusterUriAsync(subscriptionId, clusterName, tenant, retryPolicy);
return await QueryItemsAsync(clusterUri, databaseName, query, tenant, authMethod, retryPolicy);
Expand Down