public void DiscoverKubernetesClusterWithNoValidCredentials()
        {
            const string accessKeyEnvVar   = "AWS_ACCESS_KEY_ID";
            const string secretKeyEnvVar   = "AWS_SECRET_ACCESS_KEY";
            var          originalAccessKey = Environment.GetEnvironmentVariable(accessKeyEnvVar);
            var          originalSecretKey = Environment.GetEnvironmentVariable(secretKeyEnvVar);

            try
            {
                Environment.SetEnvironmentVariable(accessKeyEnvVar, null);
                Environment.SetEnvironmentVariable(secretKeyEnvVar, null);

                var authenticationDetails = new AwsAuthenticationDetails
                {
                    Type        = "Aws",
                    Credentials = new AwsCredentials {
                        Type = "worker"
                    },
                    Role = new AwsAssumedRole {
                        Type = "noAssumedRole"
                    },
                    Regions = new [] { region }
                };

                var serviceMessageCollectorLog = new ServiceMessageCollectorLog();
                Log = serviceMessageCollectorLog;

                DoDiscovery(authenticationDetails);

                serviceMessageCollectorLog.ServiceMessages.Should().BeEmpty();

                serviceMessageCollectorLog.Messages.Should().NotContain(m => m.Level == InMemoryLog.Level.Error);

                serviceMessageCollectorLog.StandardError.Should().BeEmpty();

                serviceMessageCollectorLog.Messages.Should()
                .ContainSingle(m =>
                               m.Level == InMemoryLog.Level.Warn &&
                               m.FormattedMessage ==
                               "Unable to authorise credentials, see verbose log for details.");
            }
            finally
            {
                Environment.SetEnvironmentVariable(accessKeyEnvVar, originalAccessKey);
                Environment.SetEnvironmentVariable(secretKeyEnvVar, originalSecretKey);
            }
        }
        protected void DoDiscoveryAndAssertReceivedServiceMessageWithMatchingProperties(
            AwsAuthenticationDetails authenticationDetails,
            Dictionary <string, string> properties)
        {
            var serviceMessageCollectorLog = new ServiceMessageCollectorLog();

            Log = serviceMessageCollectorLog;

            DoDiscovery(authenticationDetails);

            var expectedServiceMessage = new ServiceMessage(
                KubernetesDiscoveryCommand.CreateKubernetesTargetServiceMessageName,
                properties);

            serviceMessageCollectorLog.ServiceMessages.Should()
            .ContainSingle(s => s.Properties["name"] == properties["name"])
            .Which.Should()
            .BeEquivalentTo(expectedServiceMessage);
        }
        public void DiscoverKubernetesClusterWithInvalidAccountCredentials()
        {
            var authenticationDetails = new AwsAuthenticationDetails
            {
                Type        = "Aws",
                Credentials = new AwsCredentials
                {
                    Account = new AwsAccount
                    {
                        AccessKey = "abcdefg",
                        SecretKey = null
                    },
                    AccountId = "Accounts-1",
                    Type      = "account"
                },
                Role = new AwsAssumedRole {
                    Type = "noAssumedRole"
                },
                Regions = new [] { region }
            };

            var serviceMessageCollectorLog = new ServiceMessageCollectorLog();

            Log = serviceMessageCollectorLog;

            DoDiscovery(authenticationDetails);

            serviceMessageCollectorLog.ServiceMessages.Should().BeEmpty();

            serviceMessageCollectorLog.Messages.Should().NotContain(m => m.Level == InMemoryLog.Level.Error);

            serviceMessageCollectorLog.StandardError.Should().BeEmpty();

            serviceMessageCollectorLog.Messages.Should()
            .ContainSingle(m =>
                           m.Level == InMemoryLog.Level.Warn &&
                           m.FormattedMessage ==
                           "Unable to authorise credentials, see verbose log for details.");
        }
Ejemplo n.º 4
0
        public void DiscoverKubernetesClusterWithAzureServicePrincipalAccount()
        {
            var serviceMessageCollectorLog = new ServiceMessageCollectorLog();

            Log = serviceMessageCollectorLog;

            var scope = new TargetDiscoveryScope("TestSpace",
                                                 "Staging",
                                                 "testProject",
                                                 null,
                                                 new[] { "discovery-role" },
                                                 "WorkerPool-1");

            var account = new ServicePrincipalAccount(
                ExternalVariables.Get(ExternalVariable.AzureSubscriptionId),
                ExternalVariables.Get(ExternalVariable.AzureSubscriptionClientId),
                ExternalVariables.Get(ExternalVariable.AzureSubscriptionTenantId),
                ExternalVariables.Get(ExternalVariable.AzureSubscriptionPassword),
                null,
                null,
                null);

            var authenticationDetails =
                new AccountAuthenticationDetails <ServicePrincipalAccount>(
                    "Azure",
                    "Accounts-1",
                    account);

            var targetDiscoveryContext =
                new TargetDiscoveryContext <AccountAuthenticationDetails <ServicePrincipalAccount> >(scope,
                                                                                                     authenticationDetails);

            var result =
                ExecuteDiscoveryCommand(targetDiscoveryContext,
                                        new[] { "Calamari.Azure" }
                                        );

            result.AssertSuccess();

            var targetName             = $"aks/{azureSubscriptionId}/{azurermResourceGroup}/{aksClusterName}";
            var expectedServiceMessage = new ServiceMessage(
                KubernetesDiscoveryCommand.CreateKubernetesTargetServiceMessageName,
                new Dictionary <string, string>
            {
                { "name", targetName },
                { "clusterName", aksClusterName },
                { "clusterResourceGroup", azurermResourceGroup },
                { "skipTlsVerification", bool.TrueString },
                { "octopusDefaultWorkerPoolIdOrName", scope.WorkerPoolId },
                { "octopusAccountIdOrName", "Accounts-1" },
                { "octopusRoles", "discovery-role" },
                { "updateIfExisting", bool.TrueString },
                { "isDynamic", bool.TrueString },
                { "awsUseWorkerCredentials", bool.FalseString },
                { "awsAssumeRole", bool.FalseString },
            });

            serviceMessageCollectorLog.ServiceMessages.Should()
            .ContainSingle(s => s.Properties["name"] == targetName)
            .Which.Should()
            .BeEquivalentTo(expectedServiceMessage);
        }