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

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

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

            var variables = new VariableDictionary();
            variables.Set(SpecialVariables.Action.Azure.CloudServicePackagePath, packageFile);
            variables.Set(SpecialVariables.OriginalPackageDirectoryPath, !string.IsNullOrWhiteSpace(destinationDirectory) ? destinationDirectory : Path.GetDirectoryName(packageFile));

            var fileSystem = new WindowsPhysicalFileSystem();

            var conventions = new List<IConvention>
            {
                new EnsureCloudServicePackageIsCtpFormatConvention(fileSystem),
                new ExtractAzureCloudServicePackageConvention(fileSystem),
            };

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

            return 0;
        }
        public void ShouldKeepExistingValues()
        {
            var variables = new VariableDictionary();
            variables.Set("MyMessage", "Hello world!");
            variables.Set("EmailSettings:SmtpPort", "24");
            variables.Set("EmailSettings:DefaultRecipients:Cc", "*****@*****.**");

            var generated = Generate(variables, existingFile: "appsettings.existing-expected.json");
            AssertJsonEquivalent(generated, "appsettings.existing-expected.json");
        }
        public void DoesNotAddXmlHeader()
        {
            var variables = new VariableDictionary();
            variables.Set("WelcomeMessage", "Hello world");
            variables.Set("LogFile", "C:\\Log.txt");
            variables.Set("DatabaseConnection", null);

            var text = PerformTest(GetFixtureResouce("Samples", "NoHeader.config"), variables);
            Assert.That(text, Is.StringStarting("<configuration"));
        }
        public static void PopulateVariables(VariableDictionary variables)
        {
            var certificate = GetCertificate();

            variables.Set(SpecialVariables.Account.Name, "OctopusAzureTestAccount");
            variables.Set(SpecialVariables.Account.AccountType, "AzureSubscription");
            variables.Set(SpecialVariables.Action.Azure.CertificateBytes, Convert.ToBase64String(certificate.Export(X509ContentType.Pfx)));
            variables.Set(SpecialVariables.Action.Azure.CertificateThumbprint, CertificateThumbprint);
            variables.Set(SpecialVariables.Action.Azure.SubscriptionId, AzureSubscriptionId);
        }
 public void ShouldIgnoreOctopusPrefix()
 {
     var variables = new VariableDictionary();
     variables.Set("MyMessage", "Hello world");
     variables.Set("IThinkOctopusIsGreat", "Yes, I do");
     variables.Set("OctopusRocks", "This is ignored");
     variables.Set("Octopus.Rocks", "So is this");
     
     var generated = Generate(variables);
     AssertJsonEquivalent(generated, "appsettings.ignore-octopus.json");
 }
        public void ShouldWarnAndIgnoreAmbiguousSettings()
        {
            var variables = new VariableDictionary();
            variables.Set("EmailSettings:DefaultRecipients:To", "*****@*****.**");
            variables.Set("EmailSettings:DefaultRecipients", "*****@*****.**");

            var writer = new StringWriter();
            Log.StdOut = writer;
            var generated = Generate(variables);
            AssertJsonEquivalent(generated, "appsettings.ambiguous.json");
            Assert.That(writer.ToString(), Is.StringContaining("Unable to set value for EmailSettings:DefaultRecipients:To. The property at EmailSettings.DefaultRecipients is a String."));
        }
        public void ShouldGenerateSimpleFile()
        {
            var variables = new VariableDictionary();
            variables.Set("MyMessage", "Hello world");
            variables.Set("EmailSettings:SmtpHost", "localhost");
            variables.Set("EmailSettings:SmtpPort", "23");
            variables.Set("EmailSettings:DefaultRecipients:To", "*****@*****.**");
            variables.Set("EmailSettings:DefaultRecipients:Cc", "*****@*****.**");

            var generated = Generate(variables);
            AssertJsonEquivalent(generated, "appsettings.simple.json");
        }
        public void ReplacesStronglyTypedAppSettings()
        {
            var variables = new VariableDictionary();
            variables.Set("WelcomeMessage", "Hello world");
            variables.Set("LogFile", "C:\\Log.txt");
            variables.Set("DatabaseConnection", null);

            var text = PerformTest(GetFixtureResouce("Samples", "StrongTyped.config"), variables);

            var contents = XDocument.Parse(text);

            Assert.AreEqual("Hello world", contents.XPathSelectElement("//AppSettings.Properties.Settings/setting[@name='WelcomeMessage']/value").Value);
        }
        public void ReplacesConnectionStrings()
        {
            var variables = new VariableDictionary();
            variables.Set("MyDb1", "Server=foo");
            variables.Set("MyDb2", "Server=bar&bar=123");

            var text = PerformTest(GetFixtureResouce("Samples", "App.config"), variables);

            var contents = XDocument.Parse(text);

            Assert.AreEqual("Server=foo", contents.XPathSelectElement("//connectionStrings/add[@name='MyDb1']").Attribute("connectionString").Value);
            Assert.AreEqual("Server=bar&bar=123", contents.XPathSelectElement("//connectionStrings/add[@name='MyDb2']").Attribute("connectionString").Value);
        }
        public void Deploy()
        {
            OctopusTestAzureSubscription.IgnoreIfCertificateNotInstalled();

            var nugetPackageFile = PackageBuilder.BuildSamplePackage("Octopus.Sample.AzureCloudService", "1.0.0");

            var variablesFile = Path.GetTempFileName(); 
            var variables = new VariableDictionary();
            OctopusTestAzureSubscription.PopulateVariables(variables);
            OctopusTestCloudService.PopulateVariables(variables);
            variables.Set(SpecialVariables.Action.Azure.Slot, "Staging");
            variables.Set(SpecialVariables.Action.Azure.SwapIfPossible, false.ToString());
            variables.Set(SpecialVariables.Action.Azure.UseCurrentInstanceCount, true.ToString());

            variables.Set(SpecialVariables.Action.Name, "AzureCloudService");
            variables.Set(SpecialVariables.Release.Number, "1.0.0");

            // Enable variable-substitution
            variables.Set(SpecialVariables.Package.SubstituteInFilesEnabled, true.ToString());
            variables.Set(SpecialVariables.Package.SubstituteInFilesTargets, "ServiceDefinition\\ServiceDefinition.csdef");

            fileSystem = new WindowsPhysicalFileSystem();
            stagingDirectory = Path.GetTempPath(); 
            variables.Set(SpecialVariables.Action.Azure.PackageExtractionPath, stagingDirectory);

            variables.Save(variablesFile);

            result = Invoke(
                Calamari()
                    .Action("deploy-azure-cloud-service")
                    .Argument("package", nugetPackageFile)
                    .Argument("variables", variablesFile));       

        }
示例#11
0
        private string CreateAzureCertificate(string workingDirectory, VariableDictionary variables)
        {
            var certificateFilePath = Path.Combine(workingDirectory, CertificateFileName);
            var certificatePassword = GenerateCertificatePassword();
            var azureCertificate = certificateStore.GetOrAdd(
                variables.Get(SpecialVariables.Action.Azure.CertificateThumbprint),
                variables.Get(SpecialVariables.Action.Azure.CertificateBytes),
                StoreName.My);

            variables.Set("OctopusAzureCertificateFileName", certificateFilePath);
            variables.Set("OctopusAzureCertificatePassword", certificatePassword);

            fileSystem.WriteAllBytes(certificateFilePath, azureCertificate.Export(X509ContentType.Pfx, certificatePassword));
            return certificateFilePath;
        }
        public void SupportsNamespaces()
        {
            var variables = new VariableDictionary();
            variables.Set("WelcomeMessage", "Hello world");
            variables.Set("LogFile", "C:\\Log.txt");
            variables.Set("DatabaseConnection", null);

            var text = PerformTest(GetFixtureResouce("Samples","CrazyNamespace.config"), variables);

            var contents = XDocument.Parse(text);

            Assert.AreEqual("Hello world", contents.XPathSelectElement("//*[local-name()='appSettings']/*[local-name()='add'][@key='WelcomeMessage']").Attribute("value").Value);
            Assert.AreEqual("C:\\Log.txt", contents.XPathSelectElement("//*[local-name()='appSettings']/*[local-name()='add'][@key='LogFile']").Attribute("value").Value);
            Assert.AreEqual("", contents.XPathSelectElement("//*[local-name()='appSettings']/*[local-name()='add'][@key='DatabaseConnection']").Attribute("value").Value);
        }
 public void SetUp()
 {
     variables = new VariableDictionary();
     variables.Set(SpecialVariables.OriginalPackageDirectoryPath, stagingDirectory);
     fileSystem = Substitute.For<ICalamariFileSystem>();
     deployment = new RunningDeployment(packageFilePath, variables);
 }
示例#14
0
 static void AddVariables(VariableDictionary variableDictionary, IDictionary<string, string> items)
 {
     foreach (var variableName in items.Keys)
     {
        variableDictionary.Set(variableName, items[variableName]);
     }
 }
示例#15
0
        public void SetUp()
        {
            fileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem();

            // Ensure staging directory exists and is empty 
            stagingDirectory = Path.Combine(Path.GetTempPath(), "CalamariTestStaging");
            customDirectory = Path.Combine(Path.GetTempPath(), "CalamariTestCustom");
            fileSystem.EnsureDirectoryExists(stagingDirectory);
            fileSystem.PurgeDirectory(stagingDirectory, FailureOptions.ThrowOnFailure);

            Environment.SetEnvironmentVariable("TentacleJournal", Path.Combine(stagingDirectory, "DeploymentJournal.xml" ));

            variables = new VariableDictionary();
            variables.EnrichWithEnvironmentVariables();
            variables.Set(SpecialVariables.Tentacle.Agent.ApplicationDirectoryPath, stagingDirectory);
            variables.Set("PreDeployGreeting", "Bonjour");
        }
        public void SetUp()
        {
            fileSystem = Substitute.For<ICalamariFileSystem>();
            variables = new VariableDictionary();
            variables.Set(SpecialVariables.OriginalPackageDirectoryPath, StagingDirectory);
            deployment = new RunningDeployment(StagingDirectory, variables);

            convention = new ChooseCloudServiceConfigurationFileConvention(fileSystem);
        }
        public void SetUp()
        {
            fileSystem = Substitute.For<ICalamariFileSystem>();
            packageUploader = Substitute.For<IAzurePackageUploader>();
            credentialsFactory = Substitute.For<ISubscriptionCloudCredentialsFactory>();
            credentialsFactory.GetCredentials(azureSubscriptionId, certificateThumbprint, certificateBytes)
                .Returns(new FakeSubscriptionCloudCredentials(azureSubscriptionId));

            variables = new VariableDictionary();
            variables.Set(SpecialVariables.OriginalPackageDirectoryPath, stagingDirectory);
            variables.Set(SpecialVariables.Action.Azure.SubscriptionId, azureSubscriptionId);
            variables.Set(SpecialVariables.Action.Azure.CertificateThumbprint, certificateThumbprint);
            variables.Set(SpecialVariables.Action.Azure.CertificateBytes, certificateBytes);
            variables.Set(SpecialVariables.Action.Azure.StorageAccountName, storageAccountName);
            deployment = new RunningDeployment(stagingDirectory, variables);

            convention = new UploadAzureCloudServicePackageConvention(fileSystem, packageUploader, credentialsFactory);
        }
        public void ShouldSetAzureSubscription()
        {
            // If the Azure test certificate is not installed, we cannot run, so ignore
            OctopusTestAzureSubscription.IgnoreIfCertificateNotInstalled();

            var variablesFile = Path.GetTempFileName();
            var variables = new VariableDictionary();
            variables.Set(SpecialVariables.Account.AccountType, "AzureSubscription");
            variables.Set(SpecialVariables.Account.Name, "AzureTest");
            variables.Save(variablesFile);
            OctopusTestAzureSubscription.PopulateVariables(variables);

            var output = Invoke(Calamari()
                .Action("run-script")
                .Argument("script", GetFixtureResouce("AzureSubscription.ps1"))
                .Argument("variables", variablesFile));

            output.AssertZero();
            output.AssertOutput("Current subscription ID: " + OctopusTestAzureSubscription.AzureSubscriptionId);
        }
示例#19
0
        public void Deploy()
        {
            const string webAppName = "octodemo003-dev";

            OctopusTestAzureSubscription.IgnoreIfCertificateNotInstalled();

            variables = new VariableDictionary();
            OctopusTestAzureSubscription.PopulateVariables(variables);
            variables.Set(SpecialVariables.Action.Azure.WebAppName, webAppName);

            variables.Set("foo", "bar");
            // Enable file substitution and configure the target
            variables.Set(SpecialVariables.Package.SubstituteInFilesEnabled, true.ToString());
            variables.Set(SpecialVariables.Package.SubstituteInFilesTargets, "web.config");

            fileSystem = new WindowsPhysicalFileSystem();
            stagingDirectory = Path.GetTempPath(); 
            variables.Set(SpecialVariables.Action.Azure.PackageExtractionPath, stagingDirectory);

            result = DeployPackage("Acme.Web");
        }
示例#20
0
        public void ShouldSetActionIndexedOutputVariables()
        {
            var variables = new VariableDictionary();
            variables.Set(SpecialVariables.Action.Name, "run-script");

            var output = Invoke(Calamari() 
                .Action("run-script")
                .Argument("script", GetFixtureResouce("Scripts", "CanSetVariable.ps1")), 
                variables);

            Assert.AreEqual("World!", variables.Get("Octopus.Action[run-script].Output.TestA"));
        }
        public void SetUp()
        {
            fileSystem = Substitute.For<ICalamariFileSystem>();
            scriptEngine = Substitute.For<IScriptEngine>();
            commandLineRunner = Substitute.For<ICommandLineRunner>();

            scriptEngine.GetSupportedExtensions().Returns(new string[] { "ps1" });

            variables = new VariableDictionary();
            variables.Set(SpecialVariables.Package.EnabledFeatures, SpecialVariables.Features.CustomScripts);

            deployment = new RunningDeployment("C:\\packages", variables) { StagingDirectory = stagingDirectory };
        }
示例#22
0
        public void ShouldCallHello()
        {
            var variablesFile = Path.GetTempFileName();
            var variables = new VariableDictionary();
            variables.Set("Name", "Paul");
            variables.Set("Variable2", "DEF");
            variables.Set("Variable3", "GHI");
            variables.Set("Foo_bar", "Hello");
            variables.Set("Host", "Never");
            variables.Save(variablesFile);

            using (new TemporaryFile(variablesFile))
            {
                var output = Invoke(Calamari()
                    .Action("run-script")
                    .Argument("script", GetFixtureResouce("Scripts", "hello.sh"))
                    .Argument("variables", variablesFile));

                output.AssertZero();
                output.AssertOutput("Hello Paul");
            }
        }
        public string CreateAzureContextScript(string targetScriptFile, VariableDictionary variables)
        {
            var workingDirectory = Path.GetDirectoryName(targetScriptFile);
            EnsureVariablesSet(workingDirectory, variables);
            variables.Set("OctopusAzureTargetScript", targetScriptFile);

            var azureContextScriptFile = Path.Combine(workingDirectory, "Octopus.AzureContext.ps1");
            if (!fileSystem.FileExists(azureContextScriptFile))
            {
                fileSystem.OverwriteFile(azureContextScriptFile, embeddedResources.GetEmbeddedResourceText("Calamari.Scripts.AzureContext.ps1"));
            }

            return azureContextScriptFile;
        }
        public void ShouldIncludeSensitiveVariables()
        {
            const string encryptionPassword = "******";

            var insensitiveVariables = new VariableDictionary(insensitiveVariablesFileName);
            insensitiveVariables.Set("insensitiveVariableName", "insensitiveVariableValue");
            insensitiveVariables.Save();

            var sensitiveVariables = new Dictionary<string, string>
            {
                {"sensitiveVariableName", "sensitiveVariableValue"}
            };
            var salt = CreateEncryptedSensitiveVariablesFile(sensitiveVariablesFileName, encryptionPassword, sensitiveVariables);

            var result = subject.IncludeSensitiveVariables(insensitiveVariablesFileName, encryptionPassword, salt);

            Assert.AreEqual("sensitiveVariableValue", result.Get("sensitiveVariableName"));
            Assert.AreEqual("insensitiveVariableValue", result.Get("insensitiveVariableName"));
        }
示例#25
0
        public void ShouldFailIfAModuleHasASyntaxError()
        {
            var variablesFile = Path.GetTempFileName();

            var variables = new VariableDictionary();

            variables.Set("Octopus.Script.Module[Foo]", "function SayHello() { Write-Host \"Hello from module! }");
            variables.Save(variablesFile);

            using (new TemporaryFile(variablesFile))
            {
                var output = Invoke(Calamari()
                                    .Action("run-script")
                                    .Argument("script", GetFixtureResouce("Scripts", "UseModule.ps1"))
                                    .Argument("variables", variablesFile));

                output.AssertFailure();
                output.AssertErrorOutput("ParserError", true);
                output.AssertErrorOutput("is missing the terminator", true);
            }
        }
示例#26
0
        public void ShouldCallHelloWithVariableSubstitution()
        {
            var variablesFile = Path.GetTempFileName();

            var variables = new VariableDictionary();

            variables.Set("Name", "SubstitutedValue");
            variables.Save(variablesFile);

            using (new TemporaryFile(variablesFile))
            {
                var output = Invoke(Calamari()
                                    .Action("run-script")
                                    .Argument("script", GetFixtureResouce("Scripts", "HelloVariableSubstitution.fsx"))
                                    .Argument("variables", variablesFile)
                                    .Flag("substituteVariables"));

                output.AssertSuccess();
                output.AssertOutput("Hello SubstitutedValue");
            }
        }
示例#27
0
        public void ShouldCallHelloWithSensitiveVariable()
        {
            var variablesFile = Path.GetTempFileName();

            var variables = new VariableDictionary();

            variables.Set("Name", "NameToEncrypt");
            variables.SaveEncrypted("5XETGOgqYR2bRhlfhDruEg==", variablesFile);

            using (new TemporaryFile(variablesFile))
            {
                var output = Invoke(Calamari()
                                    .Action("run-script")
                                    .Argument("script", GetFixtureResouce("Scripts", "HelloWithVariable.ps1"))
                                    .Argument("sensitiveVariables", variablesFile)
                                    .Argument("sensitiveVariablesPassword", "5XETGOgqYR2bRhlfhDruEg=="));

                output.AssertSuccess();
                output.AssertOutput("Hello NameToEncrypt");
            }
        }
		public VariableDictionary Get(OctopusConfigurationProviderOptions options)
		{
			var variableDictionary = new VariableDictionary();

			var endpoint = new OctopusServerEndpoint(options.ServerAddress.ToString(), options.ApiKey);
			var repository = new OctopusRepository(endpoint);

			var project = repository.Projects.FindByName(options.ProjectName);
			if (project == null)
			{
				return variableDictionary;
			}

			var scopes = new Dictionary<ScopeField, string>();
			if (!string.IsNullOrEmpty(options.EnvironmentName))
			{
				scopes[ScopeField.Environment] = options.EnvironmentName;
			}
			if (!string.IsNullOrEmpty(options.MachineName))
			{
				scopes[ScopeField.Machine] = options.MachineName;
			}

			var variableSetIds = new List<string> { project.VariableSetId };
			variableSetIds.AddRange(project.IncludedLibraryVariableSetIds.Select(id => repository.LibraryVariableSets.Get(id).VariableSetId));

			var variables = new Dictionary<string, SortedSet<VariableResource>>();
			foreach (var variableSetId in variableSetIds)
			{
				var variableSet = repository.VariableSets.Get(variableSetId);
				AddVariableSet(variables, variableSet, scopes);
			}

			foreach (var variableName in variables.Keys)
			{
				variableDictionary.Set(variableName, variables[variableName].First().Value);
			}

			return variableDictionary;
		}
示例#29
0
        public void ShouldNotSubstituteVariablesInNonPackagedScript()
        {
            // Use a temp file for the script to avoid mutating the script file for other tests
            var scriptFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N") + ".ps1");

            File.WriteAllText(scriptFile, "Write-Host \"Hello #{Octopus.Environment.Name}!\"");

            var variables = new VariableDictionary();

            variables.Set("Octopus.Environment.Name", "Production");

            using (new TemporaryFile(scriptFile))
            {
                var output = InvokeCalamariForPowerShell(calamari => calamari
                                                         .Action("run-script")
                                                         .Argument("script", scriptFile), variables);

                output.AssertSuccess();
                output.AssertOutput("Hello #{Octopus.Environment.Name}!");
                AssertPowerShellEdition(output);
            }
        }
示例#30
0
        public void ShouldCustomizePowerShellVersionIfRequested(string customPowerShellVersion, string expectedLogMessage)
        {
            var variablesFile = Path.GetTempFileName();

            var variables = new VariableDictionary();

            variables.Set(SpecialVariables.Action.PowerShell.CustomPowerShellVersion, customPowerShellVersion);
            variables.Save(variablesFile);

            using (new TemporaryFile(variablesFile))
            {
                // Let's just use the Hello.ps1 script for something simples
                var output = Invoke(Calamari()
                                    .Action("run-script")
                                    .Argument("script", GetFixtureResouce("Scripts", "Hello.ps1"))
                                    .Argument("variables", variablesFile));

                output.AssertSuccess();
                output.AssertOutput(expectedLogMessage);
                output.AssertOutput("Hello!");
            }
        }
示例#31
0
        public void ShouldCustomizePowerShellVersionIfRequested(string customPowerShellVersion, string expectedLogMessage)
        {
            var variables = new VariableDictionary();

            variables.Set(SpecialVariables.Action.PowerShell.CustomPowerShellVersion, customPowerShellVersion);

            // Let's just use the Hello.ps1 script for something simples
            var output = InvokeCalamariForPowerShell(calamari => calamari
                                                     .Action("run-script")
                                                     .Argument("script", GetFixtureResouce("Scripts", "Hello.ps1")), variables);

            if (output.CapturedOutput.AllMessages
                .Select(line => new string(line.ToCharArray().Where(c => c != '\u0000').ToArray()))
                .Any(line => line.Contains(".NET Framework is not installed")))
            {
                Assert.Inconclusive("Version 2.0 of PowerShell is not supported on this machine");
            }

            output.AssertSuccess();
            output.AssertOutput(expectedLogMessage);
            output.AssertOutput("Hello!");
        }
        public void ShouldShowFriendlyErrorWithInvalidSyntaxInScriptModule()
        {
            var variablesFile = Path.GetTempFileName();

            var variables = new VariableDictionary();

            variables.Set("Octopus.Script.Module[Foo]", "function SayHello() { Write-Host \"Hello from module! }");
            variables.Save(variablesFile);

            using (new TemporaryFile(variablesFile))
            {
                var output = Invoke(Calamari()
                                    .Action("run-script")
                                    .Argument("script", GetFixtureResouce("Scripts", "UseModule.ps1"))
                                    .Argument("variables", variablesFile));

                output.AssertFailure();
                output.AssertOutput("Failed to import Script Module 'Foo'");
                output.AssertErrorOutput("Write-Host \"Hello from module!");
                output.AssertErrorOutput("The string is missing the terminator: \".");
            }
        }
示例#33
0
        public void ShouldCallWithNoProfileWhenVariableSet(string executeWithoutProfile, bool calledWithNoProfile)
        {
            var variables = new VariableDictionary();

            if (executeWithoutProfile != null)
            {
                variables.Set(SpecialVariables.Action.PowerShell.ExecuteWithoutProfile, executeWithoutProfile);
            }

            var output = InvokeCalamariForPowerShell(calamari => calamari
                                                     .Action("run-script")
                                                     .Argument("script", GetFixtureResouce("Scripts", ProfileScript)),
                                                     variables);

            output.AssertSuccess();
            // Need to check for "-NoProfile -NoLogo" not just "-NoProfile" because when
            // run via Cake we end up with the outer Powershell call included in the
            // output too, which has a -NoProfile flag.
            output.CapturedOutput.Infos
            .Any(line => line.Contains("-NoLo") && line.Contains("-NoProfile"))
            .Should().Be(calledWithNoProfile);
            AssertPowerShellEdition(output);
        }
示例#34
0
        public void ShouldReplaceWholeObject()
        {
            const string expected =
                @"{" +
                "  \"MyMessage\": \"Hello world\"," +
                "  \"EmailSettings\": {" +
                "    \"SmtpPort\": \"23\"," +
                "    \"SmtpHost\": \"localhost\"," +
                "    \"DefaultRecipients\": {" +
                "      \"To\": \"[email protected]\"," +
                "      \"Cc\": \"[email protected]\"" +
                "    }" +
                "  }" +
                "}";

            var variables = new VariableDictionary();

            variables.Set("EmailSettings:DefaultRecipients", @"{""To"": ""*****@*****.**"", ""Cc"": ""*****@*****.**""}");

            var replaced = Replace(variables, existingFile: "appsettings.simple.json");

            AssertJsonEquivalent(replaced, expected);
        }
示例#35
0
        public void ShouldCallWithNoProfileWhenVariableSet(string executeWithoutProfile, bool calledWithNoProfile)
        {
            var variablesFile = Path.GetTempFileName();

            var variables = new VariableDictionary();

            if (executeWithoutProfile != null)
            {
                variables.Set(SpecialVariables.Action.PowerShell.ExecuteWithoutProfile, executeWithoutProfile);
            }
            variables.Save(variablesFile);

            using (new TemporaryFile(variablesFile))
            {
                var output = Invoke(Calamari()
                                    .Action("run-script")
                                    .Argument("script", GetFixtureResouce("Scripts", "Profile.ps1"))
                                    .Argument("variables", variablesFile));

                output.AssertSuccess();
                var allOutput = string.Join(Environment.NewLine, output.CapturedOutput.Infos);
                Assert.That(allOutput.Contains("-NoProfile") == calledWithNoProfile);
            }
        }
示例#36
0
        public void ShouldReplaceBoolean()
        {
            const string expected =
                @"{" +
                "  \"MyMessage\": \"Hello world\"," +
                "  \"EmailSettings\": {" +
                "    \"SmtpPort\": 23," +
                "    \"UseProxy\": true," +
                "    \"SmtpHost\": \"localhost\"," +
                "    \"DefaultRecipients\": [" +
                "      \"[email protected]\"," +
                "      \"[email protected]\"" +
                "    ]" +
                "  }" +
                "}";

            var variables = new VariableDictionary();

            variables.Set("EmailSettings:UseProxy", "true");

            var replaced = Replace(variables, existingFile: "appsettings.array.json");

            AssertJsonEquivalent(replaced, expected);
        }
示例#37
0
        public void ShouldPrintVariables()
        {
            var variablesFile = Path.GetTempFileName();

            var variables = new VariableDictionary();
            variables.Set("Variable1", "ABC");
            variables.Set("Variable2", "DEF");
            variables.Set("Variable3", "GHI");
            variables.Set("Foo_bar", "Hello");
            variables.Set("Host", "Never");
            variables.Save(variablesFile);

            using (new TemporaryFile(variablesFile))
            {
                var output = Invoke(Calamari()
                   .Action("run-script")
                   .Argument("script", GetFixtureResouce("Scripts", "PrintVariables.ps1"))
                   .Argument("variables", variablesFile));

                output.AssertZero();
                output.AssertOutput("V1= ABC");
                output.AssertOutput("V2= DEF");
                output.AssertOutput("V3= GHI");
                output.AssertOutput("FooBar= Hello");     // Legacy - '_' used to be removed
                output.AssertOutput("Foo_Bar= Hello");    // Current - '_' is valid in PowerShell
            }
        }
示例#38
0
        public void SetUp()
        {
            FileSystem = CalamariPhysicalFileSystem.GetPhysicalFileSystem();

            // Ensure staging directory exists and is empty
            StagingDirectory = Path.Combine(Path.GetTempPath(), "CalamariTestStaging");
            FileSystem.EnsureDirectoryExists(StagingDirectory);
            FileSystem.PurgeDirectory(StagingDirectory, FailureOptions.ThrowOnFailure);

            Environment.SetEnvironmentVariable("TentacleJournal",
                                               Path.Combine(StagingDirectory, "DeploymentJournal.xml"));
            Variables = new VariableDictionary();
            Variables.EnrichWithEnvironmentVariables();
            Variables.Set(SpecialVariables.Tentacle.Agent.ApplicationDirectoryPath, StagingDirectory);

            //Chart Pckage
            Variables.Set(SpecialVariables.Package.NuGetPackageId, "mychart");
            Variables.Set(SpecialVariables.Package.NuGetPackageVersion, "0.3.7");
            Variables.Set(SpecialVariables.Packages.PackageId(""), $"#{{{SpecialVariables.Package.NuGetPackageId}}}");
            Variables.Set(SpecialVariables.Packages.PackageVersion(""), $"#{{{SpecialVariables.Package.NuGetPackageVersion}}}");

            //Helm Options
            Variables.Set(Kubernetes.SpecialVariables.Helm.ReleaseName, ReleaseName);

            //K8S Auth
            Variables.Set(Kubernetes.SpecialVariables.ClusterUrl, ServerUrl);
            Variables.Set(Kubernetes.SpecialVariables.SkipTlsVerification, "True");
            Variables.Set(Kubernetes.SpecialVariables.Namespace, Namespace);
            Variables.Set(SpecialVariables.Account.AccountType, "Token");
            Variables.Set(SpecialVariables.Account.Token, ClusterToken);

            AddPostDeployMessageCheckAndCleanup();
        }
示例#39
0
 public void Error(Exception ex)
 {
     ex = ex.GetBaseException();
     variables.Set(SpecialVariables.LastError, ex.ToString());
     variables.Set(SpecialVariables.LastErrorMessage, ex.Message);
 }
示例#40
0
文件: Model.cs 项目: ebekker/conjure
 void IOptionVariable.Set(VariableDictionary variableDictionary)
 {
     variableDictionary.Set(VariableConstants.ModelName, ModelClass);
 }
 private void CreateSensitiveVariableFile()
 {
     var insensitiveVariables = new VariableDictionary(insensitiveVariablesFileName);
     insensitiveVariables.Set("insensitiveVariableName", "insensitiveVariableValue");
     insensitiveVariables.Save();
 }
示例#42
0
        public void ShouldSubstituteVariablesInFiles()
        {
            variables.Set("foo", "bar");
            // Enable file substitution and configure the target
            variables.Set(SpecialVariables.Package.SubstituteInFilesEnabled, true.ToString());
            variables.Set(SpecialVariables.Package.SubstituteInFilesTargets, "web.config");

            DeployPackage("Acme.Web");

            // The #{foo} variable in web.config should have been replaced by 'bar'
            AssertXmlNodeValue(Path.Combine(stagingDirectory, "Acme.Web", "1.0.0", "web.config"), "configuration/appSettings/add[@key='foo']/@value", "bar");
        }
示例#43
0
 public static void PopulateVariables(VariableDictionary variables)
 {
     variables.Set(SpecialVariables.Action.Azure.CloudServiceName, ServiceName);
     variables.Set(SpecialVariables.Action.Azure.StorageAccountName, StorageAccountName);
 }
        public void SetUp()
        {
            result = null;

            fileSystem = Substitute.For<ICalamariFileSystem>();
            credentialsFactory = Substitute.For<ISubscriptionCloudCredentialsFactory>();
            configurationRetriever = Substitute.For<IAzureCloudServiceConfigurationRetriever>();
            variables = new VariableDictionary();
            variables.Set(SpecialVariables.OriginalPackageDirectoryPath, StagingDirectory);
            deployment = new RunningDeployment(StagingDirectory, variables);

            variables.Set(SpecialVariables.Action.Azure.SubscriptionId, AzureSubscriptionId);
            variables.Set(SpecialVariables.Action.Azure.CertificateThumbprint, CertificateThumbprint);
            variables.Set(SpecialVariables.Action.Azure.CertificateBytes, CertificateBytes);
            variables.Set(SpecialVariables.Action.Azure.CloudServiceName, CloudServiceName);
            variables.Set(SpecialVariables.Action.Azure.Slot, DeploymentSlot.ToString());

            credentialsFactory.GetCredentials(AzureSubscriptionId, CertificateThumbprint, CertificateBytes)
                .Returns(new FakeSubscriptionCloudCredentials(AzureSubscriptionId));

            convention = new ConfigureAzureCloudServiceConvention(fileSystem, credentialsFactory, configurationRetriever);
        }
示例#45
0
        public void ShouldSupportModulesInVariables()
        {
            var variablesFile = Path.GetTempFileName();

            var variables = new VariableDictionary();
            variables.Set("Octopus.Script.Module[Foo]", "function SayHello() { Write-Host \"Hello from module!\" }");
            variables.Save(variablesFile);

            using (new TemporaryFile(variablesFile))
            {
                var output = Invoke(Calamari()
                   .Action("run-script")
                   .Argument("script", GetFixtureResouce("Scripts", "UseModule.ps1"))
                   .Argument("variables", variablesFile));

                output.AssertZero();
                output.AssertOutput("Hello from module!");
            }
        }
示例#46
0
 public void ShouldCopyFilesWhenCustomInstallationDirectoryIsSupplied()
 {
     variables.Set(SpecialVariables.Package.CustomInstallationDirectory, customInstallationDirectory);
     CreateConvention().Install(deployment);
     fileSystem.Received().CopyDirectory(stagingDirectory, customInstallationDirectory);
 }
示例#47
0
 public static void PopulateVariables(VariableDictionary variables)
 {
     variables.Set(SpecialVariables.Action.Azure.CloudServiceName, ServiceName);
     variables.Set(SpecialVariables.Action.Azure.StorageAccountName, StorageAccountName);
 }
 void IOptionVariable.Set(VariableDictionary variableDictionary)
 {
     variableDictionary.Set(VariableConstants.TableSchema, TableSchema);
     variableDictionary.Set(VariableConstants.TableName, TableName);
     variableDictionary.Set(VariableConstants.EntityName, EntityClass);
 }