Exemple #1
0
        public static async Task <IActionResult> Restore(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
            [Blob("sonarqube/plugins", FileAccess.Read, Connection = "StorageConnectionString")] Stream stream,
            ILogger log)
        {
            log.LogInformation("Sonarqube server - plugins restore");

            var url   = Environment.GetEnvironmentVariable("SonarqubeUrl");
            var token = req.Headers["sonarqube-token"].FirstOrDefault() ?? Environment.GetEnvironmentVariable("SonarqubeToken");

            var existingPlugins = await Sonarqube.PluginsInstalled(url, token);

            using (var reader = new StreamReader(stream))
            {
                var content = await reader.ReadToEndAsync();

                var requiredPlugins = JArray.Parse(content).Select(i => i.Value <string>());
                var missingPlugins  = requiredPlugins.Except(existingPlugins);
                if (missingPlugins.Any())
                {
                    log.LogInformation($"Restoring sonarqube plugins: {string.Join(",", missingPlugins)}");

                    await Sonarqube.InstallPlugins(url, token, missingPlugins);

                    await Sonarqube.Restart(url, token);
                }
            }

            return(new OkObjectResult(null));
        }
Exemple #2
0
        public static async Task <IActionResult> Restart(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("Sonarqube server - restarting");

            var url   = Environment.GetEnvironmentVariable("SonarqubeUrl");
            var token = req.Headers["sonarqube-token"].FirstOrDefault() ?? Environment.GetEnvironmentVariable("SonarqubeToken");

            await Sonarqube.Restart(url, token);

            return(new OkObjectResult(null));
        }
Exemple #3
0
        public static async Task <IActionResult> Update(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("Sonarqube server - plugins clean");

            var url   = Environment.GetEnvironmentVariable("SonarqubeUrl");
            var token = req.Headers["sonarqube-token"].FirstOrDefault() ?? Environment.GetEnvironmentVariable("SonarqubeToken");

            var plugins = await Sonarqube.PluginsUpdate(url, token);

            if (plugins.Any())
            {
                log.LogInformation($"Updating plugins: {string.Join(",", plugins)}");

                await Sonarqube.UpdatePlugins(url, token, plugins);

                await Sonarqube.Restart(url, token);
            }
            return(new OkObjectResult(null));
        }
Exemple #4
0
        public static async Task <IActionResult> Backup(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
            [Blob("sonarqube/plugins", FileAccess.Write, Connection = "StorageConnectionString")] TextWriter writer,
            [Blob("sonarqube/plugins-{DateTime}", FileAccess.Write, Connection = "StorageConnectionString")] TextWriter logWriter,

            ILogger log)
        {
            log.LogInformation("Sonarqube server - plugins backup");

            var url   = Environment.GetEnvironmentVariable("SonarqubeUrl");
            var token = req.Headers["sonarqube-token"].FirstOrDefault() ?? Environment.GetEnvironmentVariable("SonarqubeToken");

            var plugins = await Sonarqube.PluginsInstalled(url, token);

            var content = JsonConvert.SerializeObject(plugins);

            await writer.WriteAsync(content);

            await logWriter.WriteAsync(content);

            return(new OkObjectResult(content));
        }