예제 #1
0
 public void SetUp()
 {
     tempDirectory = fileSystem.CreateTemporaryDirectory();
     nginxServer   = Substitute.For <NginxServer>();
     nginxServer.GetConfigRootDirectory().Returns("/etc/nginx/conf.d");
     nginxServer.GetSslRootDirectory().Returns("/etc/ssl");
 }
예제 #2
0
파일: NginxParser.cs 프로젝트: diycp/Antd
        //(server[\s]+{[\s]+[\w\s\d;.\/:$#]+location[\s]+[\w\/][\s]+{[\s]+[\w\s\d:\/;$\-".]+[\s]+[}]*[\s]+[location]*[\/\s\w]*[\s]*[{]*[\s]*[\w\s\d:\/;$\-".]*)
        public static List <NginxServer> ParseServer(string text)
        {
            var list    = new List <NginxServer>();
            var regex   = new Regex("(server[\\s]+{[\\s]+[\\w\\s\\d;.\\/:$#]+location[\\s]+[\\w\\/][\\s]+{[\\s]+[\\w\\s\\d:\\/;$\\-\".]+[\\s]+[}]*[\\s]+[location]*[\\/\\s\\w]*[\\s]*[{]*[\\s]*[\\w\\s\\d:\\/;$\\-\".]*)");
            var matches = regex.Matches(text);

            foreach (var match in matches)
            {
                var listen                = CaptureGroup(match.ToString(), "listen[\\s]+([\\w\\d\\s]+);");
                var serverName            = CaptureGroup(match.ToString(), "server_name[\\s]+([\\w\\d.]+);");
                var serverTokens          = CaptureGroup(match.ToString(), "server_tokens[\\s]+([\\w\\d.]+);");
                var root                  = CaptureGroup(match.ToString(), "root[\\s]+([\\w\\d.\\/]+);");
                var clientMaxBodySize     = CaptureGroup(match.ToString(), "client_max_body_size[\\s]+([\\w\\d.\\/]+);");
                var sslCertificate        = CaptureGroup(match.ToString(), "ssl_certificate[\\s]+([\\w\\d.\\/]+);");
                var sslTrustedCertificate = CaptureGroup(match.ToString(), "ssl_trusted_certificate[\\s]+([\\w\\d.\\/]+);");
                var sslCertificateKey     = CaptureGroup(match.ToString(), "ssl_certificate_key[\\s]+([\\w\\d.\\/]+);");
                var returnRedirect        = CaptureGroup(match.ToString(), "");
                var server                = new NginxServer {
                    Listen                = listen,
                    ServerName            = serverName,
                    ServerTokens          = serverTokens,
                    Root                  = root,
                    ClientMaxBodySize     = clientMaxBodySize,
                    SslCertificate        = sslCertificate,
                    SslTrustedCertificate = sslTrustedCertificate,
                    SslCertificateKey     = sslCertificateKey,
                    ReturnRedirect        = returnRedirect,
                    Locations             = ParseLocation(match.ToString())
                };
                list.Add(server);
            }
            return(list);
        }
        public void Setup()
        {
            output      = new StringBuilder();
            testServers = new NginxServerList();
            var testServer = new NginxServer();

            testServer.Properties.Add(new PropertyEntry
            {
                Key   = "server_name",
                Value = "localhost"
            });
            testServer.Properties.Add(new PropertyEntry
            {
                Key   = "listen",
                Value = "443 ssl http2"
            });
            testServer.Locations.Add(new NginxLocation
            {
                Name       = "location /",
                Properties = new List <PropertyEntry>
                {
                    new PropertyEntry
                    {
                        Key   = "root",
                        Value = "/var/www/html"
                    }
                }
            });
            testServers.Add(testServer);
        }
예제 #4
0
        public static NginxServerList Parse(string config)
        {
            var serverEntries = new NginxServerList();
            var tokens        = NginxTokenizer.Tokenize(config);

            foreach (var entry in tokens)
            {
                if (!entry.Name.Contains("server"))
                {
                    continue;
                }
                var newServer = new NginxServer();
                newServer.ParseProperties(entry.Content);
                newServer.Locations = new List <NginxLocation>();
                foreach (var childToken in entry.Tokens)
                {
                    if (childToken.Name.Contains("location"))
                    {
                        newServer.Locations.Add(ParseLocationToken(childToken));
                    }
                    else if (childToken.Name.Contains("limit_except"))
                    {
                        newServer.LimitExcept = ParseLimitExceptToken(childToken);
                    }
                    else
                    {
                        newServer.UnsupportedTokens.Add(childToken);
                    }
                }
                serverEntries.Add(newServer);
            }

            return(serverEntries);
        }
예제 #5
0
        public override int Execute(string[] commandLineArguments)
        {
            Options.Parse(commandLineArguments);

            Guard.NotNullOrWhiteSpace(packageFile, "No package file was specified. Please pass --package YourPackage.nupkg");

            if (!File.Exists(packageFile))
            {
                throw new CommandException("Could not find package file: " + packageFile);
            }

            Log.Info("Deploying package:    " + packageFile);

            var fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem();

            var variables = new CalamariVariableDictionary(variablesFile, sensitiveVariableFiles, sensitiveVariablesPassword);

            fileSystem.FreeDiskSpaceOverrideInMegaBytes = variables.GetInt32(SpecialVariables.FreeDiskSpaceOverrideInMegaBytes);
            fileSystem.SkipFreeDiskSpaceCheck           = variables.GetFlag(SpecialVariables.SkipFreeDiskSpaceCheck);

            var featureClasses = new List <IFeature>();

            var replacer    = new ConfigurationVariablesReplacer(variables.GetFlag(SpecialVariables.Package.IgnoreVariableReplacementErrors));
            var generator   = new JsonConfigurationVariableReplacer();
            var substituter = new FileSubstituter(fileSystem);
            var configurationTransformer = ConfigurationTransformer.FromVariables(variables);
            var transformFileLocator     = new TransformFileLocator(fileSystem);
            var embeddedResources        = new AssemblyEmbeddedResources();

#if IIS_SUPPORT
            var iis = new InternetInformationServer();
            featureClasses.AddRange(new IFeature[] { new IisWebSiteBeforeDeployFeature(), new IisWebSiteAfterPostDeployFeature() });
#endif
            if (!CalamariEnvironment.IsRunningOnWindows)
            {
                featureClasses.Add(new NginxFeature(NginxServer.AutoDetect()));
            }

            var commandLineRunner = new CommandLineRunner(new SplitCommandOutput(new ConsoleCommandOutput(), new ServiceMessageCommandOutput(variables)));
            var semaphore         = SemaphoreFactory.Get();
            var journal           = new DeploymentJournal(fileSystem, semaphore, variables);

            var conventions = new List <IConvention>
            {
                new ContributeEnvironmentVariablesConvention(),
                new ContributePreviousInstallationConvention(journal),
                new ContributePreviousSuccessfulInstallationConvention(journal),
                new LogVariablesConvention(),
                new AlreadyInstalledConvention(journal),
                new ExtractPackageToApplicationDirectoryConvention(new GenericPackageExtractorFactory().createStandardGenericPackageExtractor(), fileSystem),
                new FeatureConvention(DeploymentStages.BeforePreDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new ConfiguredScriptConvention(DeploymentStages.PreDeploy, fileSystem, scriptEngine, commandLineRunner),
                new PackagedScriptConvention(DeploymentStages.PreDeploy, fileSystem, scriptEngine, commandLineRunner),
                new FeatureConvention(DeploymentStages.AfterPreDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new SubstituteInFilesConvention(fileSystem, substituter),
                new ConfigurationTransformsConvention(fileSystem, configurationTransformer, transformFileLocator),
                new ConfigurationVariablesConvention(fileSystem, replacer),
                new JsonConfigurationVariablesConvention(generator, fileSystem),
                new CopyPackageToCustomInstallationDirectoryConvention(fileSystem),
                new FeatureConvention(DeploymentStages.BeforeDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new PackagedScriptConvention(DeploymentStages.Deploy, fileSystem, scriptEngine, commandLineRunner),
                new ConfiguredScriptConvention(DeploymentStages.Deploy, fileSystem, scriptEngine, commandLineRunner),
                new FeatureConvention(DeploymentStages.AfterDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
#if IIS_SUPPORT
                new LegacyIisWebSiteConvention(fileSystem, iis),
#endif
                new FeatureConvention(DeploymentStages.BeforePostDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new PackagedScriptConvention(DeploymentStages.PostDeploy, fileSystem, scriptEngine, commandLineRunner),
                new ConfiguredScriptConvention(DeploymentStages.PostDeploy, fileSystem, scriptEngine, commandLineRunner),
                new FeatureConvention(DeploymentStages.AfterPostDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new RollbackScriptConvention(DeploymentStages.DeployFailed, fileSystem, scriptEngine, commandLineRunner),
                new FeatureRollbackConvention(DeploymentStages.DeployFailed, fileSystem, scriptEngine, commandLineRunner, embeddedResources)
            };

            var deployment       = new RunningDeployment(packageFile, variables);
            var conventionRunner = new ConventionProcessor(deployment, conventions);

            try
            {
                conventionRunner.RunConventions();
                if (!deployment.SkipJournal)
                {
                    journal.AddJournalEntry(new JournalEntry(deployment, true));
                }
            }
            catch (Exception)
            {
                if (!deployment.SkipJournal)
                {
                    journal.AddJournalEntry(new JournalEntry(deployment, false));
                }
                throw;
            }

            return(0);
        }
        public override int Execute(string[] commandLineArguments)
        {
            Options.Parse(commandLineArguments);

            Guard.NotNullOrWhiteSpace(pathToPackage, "No package file was specified. Please pass --package YourPackage.nupkg");

            if (!File.Exists(pathToPackage))
            {
                throw new CommandException("Could not find package file: " + pathToPackage);
            }

            Log.Info("Deploying package:    " + pathToPackage);

            var featureClasses = new List <IFeature>();

            var replacer = new ConfigurationVariablesReplacer(variables, log);
            var allFileFormatReplacers           = FileFormatVariableReplacers.BuildAllReplacers(fileSystem, log);
            var structuredConfigVariablesService = new StructuredConfigVariablesService(allFileFormatReplacers, fileSystem, log);
            var configurationTransformer         = ConfigurationTransformer.FromVariables(variables, log);
            var transformFileLocator             = new TransformFileLocator(fileSystem, log);
            var embeddedResources = new AssemblyEmbeddedResources();

#if IIS_SUPPORT
            var iis = new InternetInformationServer();
            featureClasses.AddRange(new IFeature[] { new IisWebSiteBeforeDeployFeature(), new IisWebSiteAfterPostDeployFeature() });
#endif
            if (!CalamariEnvironment.IsRunningOnWindows)
            {
                featureClasses.Add(new NginxFeature(NginxServer.AutoDetect(), fileSystem));
            }

            var semaphore = SemaphoreFactory.Get();
            var journal   = new DeploymentJournal(fileSystem, semaphore, variables);

            var conventions = new List <IConvention>
            {
                new AlreadyInstalledConvention(log, journal),
                new DelegateInstallConvention(d => extractPackage.ExtractToApplicationDirectory(pathToPackage)),
                new FeatureConvention(DeploymentStages.BeforePreDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new ConfiguredScriptConvention(new PreDeployConfiguredScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)),
                new PackagedScriptConvention(new PreDeployPackagedScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)),
                new FeatureConvention(DeploymentStages.AfterPreDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new SubstituteInFilesConvention(new SubstituteInFilesBehaviour(substituteInFiles)),
                new ConfigurationTransformsConvention(new ConfigurationTransformsBehaviour(fileSystem, configurationTransformer, transformFileLocator, log)),
                new ConfigurationVariablesConvention(new ConfigurationVariablesBehaviour(fileSystem, replacer, log)),
                new StructuredConfigurationVariablesConvention(new StructuredConfigurationVariablesBehaviour(structuredConfigVariablesService)),
                new CopyPackageToCustomInstallationDirectoryConvention(fileSystem),
                new FeatureConvention(DeploymentStages.BeforeDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new PackagedScriptConvention(new DeployPackagedScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)),
                new ConfiguredScriptConvention(new DeployConfiguredScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)),
                new FeatureConvention(DeploymentStages.AfterDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
#if IIS_SUPPORT
                new LegacyIisWebSiteConvention(fileSystem, iis),
#endif
                new FeatureConvention(DeploymentStages.BeforePostDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new PackagedScriptConvention(new PostDeployPackagedScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)),
                new ConfiguredScriptConvention(new PostDeployConfiguredScriptBehaviour(log, fileSystem, scriptEngine, commandLineRunner)),
                new FeatureConvention(DeploymentStages.AfterPostDeploy, featureClasses, fileSystem, scriptEngine, commandLineRunner, embeddedResources),
                new RollbackScriptConvention(log, DeploymentStages.DeployFailed, fileSystem, scriptEngine, commandLineRunner),
                new FeatureRollbackConvention(DeploymentStages.DeployFailed, fileSystem, scriptEngine, commandLineRunner, embeddedResources)
            };

            var deployment       = new RunningDeployment(pathToPackage, variables);
            var conventionRunner = new ConventionProcessor(deployment, conventions, log);

            try
            {
                conventionRunner.RunConventions();
                if (!deployment.SkipJournal)
                {
                    journal.AddJournalEntry(new JournalEntry(deployment, true));
                }
            }
            catch (Exception)
            {
                if (!deployment.SkipJournal)
                {
                    journal.AddJournalEntry(new JournalEntry(deployment, false));
                }
                throw;
            }

            return(0);
        }
예제 #7
0
 public NginxFeature(NginxServer nginxServer, ICalamariFileSystem fileSystem)
 {
     this.nginxServer = nginxServer;
     this.fileSystem  = fileSystem;
 }
예제 #8
0
 public NginxFeature(NginxServer nginxServer)
 {
     this.nginxServer = nginxServer;
 }