Exemple #1
0
        public async Task <int> UpdateAzureDevOpsBuilds(
            string organization, string project, string repository, string branch,
            string buildName, string buildId,
            int numberOfDays, int maxNumberOfItems)
        {
            int numberOfRecordsSaved;

            try
            {
                TableStorageConfiguration tableStorageConfig = Common.GenerateTableStorageConfiguration(Configuration);

                //Get the PAT token from the key vault
                string patTokenName = PartitionKeys.CreateAzureDevOpsSettingsPartitionKeyPatToken(organization, project, repository);
                patTokenName = SecretsProcessing.CleanKey(patTokenName);
                string patToken = Configuration[patTokenName];
                if (string.IsNullOrEmpty(patToken) == true)
                {
                    throw new Exception($"patToken '{patTokenName}' not found in key vault");
                }

                numberOfRecordsSaved = await AzureTableStorageDA.UpdateAzureDevOpsBuildsInStorage(patToken, tableStorageConfig, organization, project, branch, buildName, buildId, numberOfDays, maxNumberOfItems);
            }
            catch (Exception ex)
            {
                if (ex.Message == "Response status code does not indicate success: 403 (rate limit exceeded).")
                {
                    numberOfRecordsSaved = -1;
                }
                else
                {
                    throw;
                }
            }
            return(numberOfRecordsSaved);
        }
Exemple #2
0
        public async Task <bool> UpdateGitHubSetting(string clientId, string clientSecret,
                                                     string owner, string repo,
                                                     string branch, string workflowName, string workflowId, string resourceGroup,
                                                     int itemOrder, bool showSetting)
        {
            //Save the Client Id and Client Secret to the key vault
            string clientIdName = PartitionKeys.CreateGitHubSettingsPartitionKeyClientId(owner, repo);

            clientIdName = SecretsProcessing.CleanKey(clientIdName);
            if (clientIdName.Length > 10)
            {
                await CreateKeyVaultSecret(clientIdName, clientId);
            }
            string clientSecretName = PartitionKeys.CreateGitHubSettingsPartitionKeyClientSecret(owner, repo);

            clientSecretName = SecretsProcessing.CleanKey(clientSecretName);
            if (clientSecretName.Length > 14)
            {
                await CreateKeyVaultSecret(clientSecretName, clientSecret);
            }

            //Save everything else to table storage
            TableStorageConfiguration tableStorageConfig = Common.GenerateTableStorageConfiguration(Configuration);

            return(await AzureTableStorageDA.UpdateGitHubSettingInStorage(tableStorageConfig, tableStorageConfig.TableGitHubSettings,
                                                                          owner, repo, branch, workflowName, workflowId, resourceGroup, itemOrder, showSetting));
        }
        public void SecretThatIsValidTest()
        {
            //Arrange
            string name = "SamLearnsAzure123abcCI";

            //Act
            string result = SecretsProcessing.CleanKey(name);

            //Assert
            Assert.AreEqual("SamLearnsAzure123abcCI", result);
        }
        public void SecretWithQuestionTest()
        {
            //Arrange
            string name = "SamLearnsAzure?CI";

            //Act
            string result = SecretsProcessing.CleanKey(name);

            //Assert
            Assert.AreEqual("SamLearnsAzure-CI", result);
        }
Exemple #5
0
        public async Task <bool> UpdateAzureDevOpsSetting(string patToken,
                                                          string organization, string project, string repository,
                                                          string branch, string buildName, string buildId, string resourceGroup,
                                                          int itemOrder, bool showSetting)
        {
            //Save the PAT token to the key vault
            string patTokenName = PartitionKeys.CreateAzureDevOpsSettingsPartitionKeyPatToken(organization, project, repository);

            patTokenName = SecretsProcessing.CleanKey(patTokenName);
            if (patTokenName.Length > 12)
            {
                await CreateKeyVaultSecret(patTokenName, patToken);
            }

            //Save everything else to table storage
            TableStorageConfiguration tableStorageConfig = Common.GenerateTableStorageConfiguration(Configuration);

            return(await AzureTableStorageDA.UpdateAzureDevOpsSettingInStorage(tableStorageConfig, tableStorageConfig.TableAzureDevOpsSettings,
                                                                               organization, project, repository, branch, buildName, buildId, resourceGroup, itemOrder, showSetting));
        }
        public async Task<LeadTimeForChangesModel> GetGitHubLeadTimeForChanges(bool getSampleData, 
            string owner, string repo, string branch, string workflowName, string workflowId,
            int numberOfDays, int maxNumberOfItems, bool useCache)
        {
            LeadTimeForChangesModel model = new();
            try
            {
                TableStorageConfiguration tableStorageConfig = Common.GenerateTableStorageConfiguration(Configuration);

                //Get the client id and secret from the settings
                string clientIdName = PartitionKeys.CreateGitHubSettingsPartitionKeyClientId(owner, repo);
                clientIdName = SecretsProcessing.CleanKey(clientIdName);
                string clientSecretName = PartitionKeys.CreateGitHubSettingsPartitionKeyClientSecret(owner, repo);
                clientSecretName = SecretsProcessing.CleanKey(clientSecretName);
                string clientId = Configuration[clientIdName];
                string clientSecret = Configuration[clientSecretName];
                if (string.IsNullOrEmpty(clientId) == true | string.IsNullOrEmpty(clientSecret) == true)
                {
                    throw new Exception($"clientId '{clientId}' or clientSecret '{clientSecret}' not found in key vault");
                }

                LeadTimeForChangesDA da = new();
                model = await da.GetGitHubLeadTimesForChanges(getSampleData, clientId, clientSecret, tableStorageConfig,
                        owner, repo, branch, workflowName, workflowId, numberOfDays, maxNumberOfItems, useCache);
            }
            catch (Exception ex)
            {
                if (ex.Message == "Response status code does not indicate success: 403 (rate limit exceeded).")
                {
                    model.ProjectName = repo;
                    model.RateLimitHit = true;
                }
                else
                {
                    throw;
                }
            }
            return model;

        }
Exemple #7
0
        public async Task <int> UpdateGitHubActionRuns(
            string owner, string repo, string branch, string workflowName, string workflowId,
            int numberOfDays, int maxNumberOfItems)
        {
            int numberOfRecordsSaved;

            try
            {
                TableStorageConfiguration tableStorageConfig = Common.GenerateTableStorageConfiguration(Configuration);

                //Get the client id and secret from the settings
                string clientIdName = PartitionKeys.CreateGitHubSettingsPartitionKeyClientId(owner, repo);
                clientIdName = SecretsProcessing.CleanKey(clientIdName);
                string clientSecretName = PartitionKeys.CreateGitHubSettingsPartitionKeyClientSecret(owner, repo);
                clientSecretName = SecretsProcessing.CleanKey(clientSecretName);
                string clientId     = Configuration[clientIdName];
                string clientSecret = Configuration[clientSecretName];
                if (string.IsNullOrEmpty(clientId) == true | string.IsNullOrEmpty(clientSecret) == true)
                {
                    throw new Exception($"clientId '{clientId}' or clientSecret '{clientSecret}' not found in key vault");
                }

                numberOfRecordsSaved = await AzureTableStorageDA.UpdateGitHubActionRunsInStorage(clientId, clientSecret, tableStorageConfig,
                                                                                                 owner, repo, branch, workflowName, workflowId, numberOfDays, maxNumberOfItems);
            }
            catch (Exception ex)
            {
                if (ex.Message == "Response status code does not indicate success: 403 (rate limit exceeded).")
                {
                    numberOfRecordsSaved = -1;
                }
                else
                {
                    throw;
                }
            }
            return(numberOfRecordsSaved);
        }
        public async Task<LeadTimeForChangesModel> GetAzureDevOpsLeadTimeForChanges(bool getSampleData, 
            string organization, string project, string repository, string branch, string buildName, 
            int numberOfDays, int maxNumberOfItems, bool useCache)
        {
            LeadTimeForChangesModel model = new();
            try
            {
                TableStorageConfiguration tableStorageConfig = Common.GenerateTableStorageConfiguration(Configuration);

                //Get the PAT token from the key vault
                string patTokenName = PartitionKeys.CreateAzureDevOpsSettingsPartitionKeyPatToken(organization, project, repository);
                patTokenName = SecretsProcessing.CleanKey(patTokenName);
                string patToken = Configuration[patTokenName];
                if (string.IsNullOrEmpty(patToken) == true)
                {
                    throw new Exception($"patToken '{patTokenName}' not found in key vault");
                }

                LeadTimeForChangesDA da = new();
                model = await da.GetAzureDevOpsLeadTimesForChanges(getSampleData,  patToken, tableStorageConfig,
                        organization, project, repository, branch, buildName, numberOfDays, maxNumberOfItems, useCache);
            }
            catch (Exception ex)
            {
                if (ex.Message == "Response status code does not indicate success: 403 (rate limit exceeded).")
                {
                    model.ProjectName = project;
                    model.RateLimitHit = true;
                }
                else
                {
                    throw;
                }
            }
            return model;
        }