Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
19 changes: 14 additions & 5 deletions src/DevOpsMetrics.Service/Controllers/DORASummaryController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ public async Task<ProcessingResult> UpdateDORASummaryItem(
clientSecret = Configuration[clientSecretName];
if (string.IsNullOrEmpty(clientId) || string.IsNullOrEmpty(clientSecret))
{
errorMessage = $"clientId '{clientId}' or clientSecret '{clientSecret}' not found in key vault";
throw new Exception(errorMessage);
errorMessage = $"clientId '{clientIdName}' or clientSecret '{clientSecretName}' not found in key vault";
}
}
else
Expand All @@ -85,11 +84,23 @@ public async Task<ProcessingResult> UpdateDORASummaryItem(
if (string.IsNullOrEmpty(patToken))
{
errorMessage = $"patToken '{patTokenName}' not found in key vault";
throw new Exception(errorMessage);
}
}

ProcessingResult result = new();
//If the settings are missing, skip the processing and return an empty result
if (string.IsNullOrEmpty(errorMessage) == false)
{
if (log == null)
{
Console.WriteLine(errorMessage);
}
else
{
log.LogInformation(errorMessage);
}
return result;
}
DeploymentFrequencyModel deploymentFrequencyModel = new();
LeadTimeForChangesModel leadTimeForChangesModel = new();
MeanTimeToRestoreModel meanTimeToRestoreModel = new();
Expand All @@ -108,12 +119,10 @@ public async Task<ProcessingResult> UpdateDORASummaryItem(
//TODO: fix this - should be using a common interface, not this null hack
if (log == null)
{
Console.WriteLine(errorMessage);
Console.WriteLine(message);
}
else
{
log.LogInformation(errorMessage);
log.LogInformation(message);
}
if (useParallelProcessing)
Expand Down
51 changes: 51 additions & 0 deletions src/DevOpsMetrics.Service/Controllers/SettingsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public SettingsController(IConfiguration configuration, IAzureTableStorageDA azu
public async Task<List<AzureDevOpsSettings>> GetAzureDevOpsSettings(string rowKey = null)
{
TableStorageConfiguration tableStorageConfig = Common.GenerateTableStorageConfiguration(Configuration);
//If the storage settings are missing, return an empty list instead of throwing an error
if (IsTableStorageConfigured(tableStorageConfig, tableStorageConfig.TableAzureDevOpsSettings) == false)
{
return new List<AzureDevOpsSettings>();
}
List<AzureDevOpsSettings> settings = await AzureTableStorageDA.GetAzureDevOpsSettingsFromStorage(tableStorageConfig, tableStorageConfig.TableAzureDevOpsSettings, rowKey);
return settings;
}
Expand All @@ -39,6 +44,11 @@ public async Task<List<AzureDevOpsSettings>> GetAzureDevOpsSettings(string rowKe
public async Task<List<GitHubSettings>> GetGitHubSettings(string rowKey = null)
{
TableStorageConfiguration tableStorageConfig = Common.GenerateTableStorageConfiguration(Configuration);
//If the storage settings are missing, return an empty list instead of throwing an error
if (IsTableStorageConfigured(tableStorageConfig, tableStorageConfig.TableGitHubSettings) == false)
{
return new List<GitHubSettings>();
}
List<GitHubSettings> settings = await AzureTableStorageDA.GetGitHubSettingsFromStorage(tableStorageConfig, tableStorageConfig.TableGitHubSettings, rowKey);
return settings;
}
Expand All @@ -59,6 +69,10 @@ public async Task<bool> UpdateAzureDevOpsSetting(string patToken,

//Save everything else to table storage
TableStorageConfiguration tableStorageConfig = Common.GenerateTableStorageConfiguration(Configuration);
if (IsTableStorageConfigured(tableStorageConfig, tableStorageConfig.TableAzureDevOpsSettings) == false)
{
return false;
}
return await AzureTableStorageDA.UpdateAzureDevOpsSettingInStorage(tableStorageConfig, tableStorageConfig.TableAzureDevOpsSettings,
organization, project, repository, branch, buildName, buildId, resourceGroup, itemOrder, showSetting);
}
Expand All @@ -85,6 +99,10 @@ public async Task<bool> UpdateGitHubSetting(string clientId, string clientSecret

//Save everything else to table storage
TableStorageConfiguration tableStorageConfig = Common.GenerateTableStorageConfiguration(Configuration);
if (IsTableStorageConfigured(tableStorageConfig, tableStorageConfig.TableGitHubSettings) == false)
{
return false;
}
return await AzureTableStorageDA.UpdateGitHubSettingInStorage(tableStorageConfig, tableStorageConfig.TableGitHubSettings,
owner, repo, branch, workflowName, workflowId, resourceGroup, itemOrder, showSetting);
}
Expand All @@ -93,6 +111,10 @@ public async Task<bool> UpdateGitHubSetting(string clientId, string clientSecret
public async Task<bool> UpdateDevOpsMonitoringEvent([FromBody] MonitoringEvent monitoringEvent)
{
TableStorageConfiguration tableStorageConfig = Common.GenerateTableStorageConfiguration(Configuration);
if (IsTableStorageConfigured(tableStorageConfig, tableStorageConfig.TableLog) == false)
{
return false;
}
return await AzureTableStorageDA.UpdateDevOpsMonitoringEventInStorage(tableStorageConfig, monitoringEvent);
}

Expand All @@ -102,6 +124,10 @@ public async Task<List<ProjectLog>> GetAzureDevOpsProjectLog(string organization
string partitionKey = PartitionKeys.CreateAzureDevOpsSettingsPartitionKey(organization, project, repository);

TableStorageConfiguration tableStorageConfig = Common.GenerateTableStorageConfiguration(Configuration);
if (IsTableStorageConfigured(tableStorageConfig, tableStorageConfig.TableLog) == false)
{
return new List<ProjectLog>();
}
return await AzureTableStorageDA.GetProjectLogsFromStorage(tableStorageConfig, partitionKey);
}

Expand All @@ -115,6 +141,10 @@ public async Task<bool> UpdateAzureDevOpsProjectLog(string organization, string
buildsUpdated, prsUpdated, HttpUtility.UrlDecode(buildUrl), HttpUtility.UrlDecode(prUrl), exceptionMessage, exceptionStackTrace);

TableStorageConfiguration tableStorageConfig = Common.GenerateTableStorageConfiguration(Configuration);
if (IsTableStorageConfigured(tableStorageConfig, tableStorageConfig.TableLog) == false)
{
return false;
}
return await AzureTableStorageDA.UpdateProjectLogInStorage(tableStorageConfig, log);
}

Expand All @@ -124,6 +154,10 @@ public async Task<List<ProjectLog>> GetGitHubProjectLog(string owner, string rep
string partitionKey = PartitionKeys.CreateGitHubSettingsPartitionKey(owner, repo);

TableStorageConfiguration tableStorageConfig = Common.GenerateTableStorageConfiguration(Configuration);
if (IsTableStorageConfigured(tableStorageConfig, tableStorageConfig.TableLog) == false)
{
return new List<ProjectLog>();
}
return await AzureTableStorageDA.GetProjectLogsFromStorage(tableStorageConfig, partitionKey);
}

Expand All @@ -137,12 +171,29 @@ public async Task<bool> UpdateGitHubProjectLog(string owner, string repo,
buildsUpdated, prsUpdated, HttpUtility.UrlDecode(buildUrl), HttpUtility.UrlDecode(prUrl), exceptionMessage, exceptionStackTrace);

TableStorageConfiguration tableStorageConfig = Common.GenerateTableStorageConfiguration(Configuration);
if (IsTableStorageConfigured(tableStorageConfig, tableStorageConfig.TableLog) == false)
{
return false;
}
return await AzureTableStorageDA.UpdateProjectLogInStorage(tableStorageConfig, log);
}

//If the table storage settings aren't available, we skip the call rather than throwing an error
private static bool IsTableStorageConfigured(TableStorageConfiguration tableStorageConfig, string tableName)
{
return tableStorageConfig != null &&
string.IsNullOrEmpty(tableStorageConfig.StorageAccountConnectionString) == false &&
string.IsNullOrEmpty(tableName) == false;
}

private async Task<KeyVaultSecret> CreateKeyVaultSecret(string secretName, string secretValue)
{
string keyVaultURI = Configuration["AppSettings:KeyVaultURL"];
//If the key vault isn't setup, or the secret is empty, skip saving the secret rather than throwing an error
if (string.IsNullOrEmpty(keyVaultURI) || string.IsNullOrEmpty(secretValue))
{
return null;
}
SecretClient secretClient = new(new Uri(keyVaultURI), new DefaultAzureCredential());
return await secretClient.SetSecretAsync(secretName, secretValue);
}
Expand Down
10 changes: 5 additions & 5 deletions src/DevOpsMetrics.Tests/Service/TableStorageControllerDATests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public async Task UpdateAzureDevOpsSettingTest()
bool result = await controller.UpdateAzureDevOpsSetting(patToken, organization, project, repository, branch, buildName, buildId, resourceGroup, itemOrder, showSetting);

//Assert
Assert.AreEqual(true, result);
Assert.AreEqual(false, result);
}

[TestMethod]
Expand All @@ -256,7 +256,7 @@ public async Task UpdateGitHubSettingTest()
bool result = await controller.UpdateGitHubSetting(clientId, clientSecret, owner, repo, branch, workflowName, workflowId, resourceGroup, itemOrder, showSetting);

//Assert
Assert.AreEqual(true, result);
Assert.AreEqual(false, result);
}

[TestMethod]
Expand All @@ -272,7 +272,7 @@ public async Task UpdateDevOpsMonitoringEventTest()
bool result = await controller.UpdateDevOpsMonitoringEvent(newEvent);

//Assert
Assert.AreEqual(true, result);
Assert.AreEqual(false, result);
}

[TestMethod]
Expand Down Expand Up @@ -317,7 +317,7 @@ public async Task UpdateAzureDevOpsLogTest()
buildsUpdated, prsUpdated, buildUrl, prUrl, exceptionMessage, exceptionStackTrace);

//Assert
Assert.AreEqual(true, result);
Assert.AreEqual(false, result);
}

[TestMethod]
Expand Down Expand Up @@ -361,7 +361,7 @@ public async Task UpdateGitHubLogTest()
buildsUpdated, prsUpdated, buildUrl, prUrl, exceptionMessage, exceptionStackTrace);

//Assert
Assert.AreEqual(true, result);
Assert.AreEqual(false, result);
}

private static int GetSampleUpdateData()
Expand Down
Loading