Exemple #1
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 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 #3
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);
        }