public void Execute(string[] commandLineArguments)
        {
            var remainingArguments = optionGroups.Parse(commandLineArguments);

            if (remainingArguments.Count > 0)
            {
                throw new CommandException("Unrecognized command arguments: " + string.Join(", ", remainingArguments));
            }

            if (string.IsNullOrWhiteSpace(serverBaseUrl))
            {
                throw new CommandException("Please specify the Octopus Server URL using --server=http://your-server/");
            }

            if (string.IsNullOrWhiteSpace(apiKey) && (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password)))
            {
                throw new CommandException("Please specify either your API key using --apiKey=ABCDEF123456789, or your Octopus credentials using --user=MyName --pass=Secret.");
            }

            var credentials = ParseCredentials(username, password);

            var endpoint = new OctopusServerEndpoint(serverBaseUrl, apiKey, credentials);

            repository = repositoryFactory.CreateRepository(endpoint);

            repository.Client.SendingOctopusRequest += request => log.Debug("{Method} {Uri}", request.Method, request.Uri);

            ConfigureServerCertificateValidation();

            InitializeConnection();

            Execute();
        }
Example #2
0
        public void Execute(string[] commandLineArguments)
        {
            var remainingArguments = optionGroups.Parse(commandLineArguments);

            if (remainingArguments.Count > 0)
            {
                throw new CommandException("Unrecognized command arguments: " + string.Join(", ", remainingArguments));
            }

            if (string.IsNullOrWhiteSpace(serverBaseUrl))
            {
                throw new CommandException("Please specify the Octopus Server URL using --server=http://your-server/");
            }

            if (string.IsNullOrWhiteSpace(apiKey))
            {
                throw new CommandException("Please specify your API key using --apiKey=ABCDEF123456789. Learn more at: https://github.com/OctopusDeploy/Octopus-Tools");
            }

            var credentials = ParseCredentials(user, pass);

            var endpoint = new OctopusServerEndpoint(serverBaseUrl, apiKey, credentials);

            repository = repositoryFactory.CreateRepository(endpoint);

            if (enableDebugging)
            {
                repository.Client.SendingOctopusRequest += request => log.Debug(request.Method + " " + request.Uri);
            }

            ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) =>
            {
                if (errors == SslPolicyErrors.None)
                {
                    return(true);
                }

                var certificate2 = (X509Certificate2)certificate;
                var warning      = "The following certificate errors were encountered when establishing the HTTPS connection to the server: " + errors + Environment.NewLine +
                                   "Certificate subject name: " + certificate2.SubjectName.Name + Environment.NewLine +
                                   "Certificate thumbprint:   " + ((X509Certificate2)certificate).Thumbprint;

                if (ignoreSslErrors)
                {
                    log.Warn(warning);
                    log.Warn("Because --ignoreSslErrors was set, this will be ignored.");
                    return(true);
                }

                log.Error(warning);
                return(false);
            };

            log.Debug("Handshaking with Octopus server: " + serverBaseUrl);
            var root = repository.Client.RootDocument;

            log.Debug("Handshake successful. Octopus version: " + root.Version + "; API version: " + root.ApiVersion);

            Execute();
        }
        public void BaseSetup()
        {
            Log = Substitute.For<ILog>();

            RootResource rootDocument = Substitute.For<RootResource>();
            rootDocument.ApiVersion = "2.0";
            rootDocument.Version = "2.0";

            Repository = Substitute.For<IOctopusRepository>();
            Repository.Client.RootDocument.Returns(rootDocument);

            RepositoryFactory = Substitute.For<IOctopusRepositoryFactory>();
            RepositoryFactory.CreateRepository(null).ReturnsForAnyArgs(Repository);

            CommandLineArgs = new List<string>
            {
                "--server=http://the-server",
                "--apiKey=ABCDEF123456789"
            };
        }