Parse() public method

public Parse ( IEnumerable arguments ) : List
arguments IEnumerable
return List
Exemplo n.º 1
0
        public async Task Execute(string[] commandLineArguments)
        {
            var remainingArguments = Options.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))
            {
                throw new CommandException("Please provide an API Key OR a username and password, not both");
            }

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

            var endpoint = string.IsNullOrWhiteSpace(apiKey)
                ? new OctopusServerEndpoint(ServerBaseUrl)
                : new OctopusServerEndpoint(ServerBaseUrl, apiKey);

#if HTTP_CLIENT_SUPPORTS_SSL_OPTIONS
            clientOptions.IgnoreSslErrors = ignoreSslErrors;
#else
            ServicePointManager.ServerCertificateValidationCallback = ServerCertificateValidationCallback;
#endif


            var client = await clientFactory.CreateAsyncClient(endpoint, clientOptions).ConfigureAwait(false);

            Repository = repositoryFactory.CreateRepository(client);
            RepositoryCommonQueries = new OctopusRepositoryCommonQueries(Repository, Log);

            if (enableDebugging)
            {
                Repository.Client.SendingOctopusRequest += request => Log.Debug("{Method:l} {Uri:l}", request.Method, request.Uri);
            }

            Log.Debug("Handshaking with Octopus server: {Url:l}", ServerBaseUrl);
            var root = Repository.Client.RootDocument;
            Log.Debug("Handshake successful. Octopus version: {Version:l}; API version: {ApiVersion:l}", root.Version, root.ApiVersion);

            if (!string.IsNullOrWhiteSpace(username))
            {
                await Repository.Users.SignIn(username, password);
            }

            var user = await Repository.Users.GetCurrent().ConfigureAwait(false);

            if (user != null)
            {
                Log.Debug("Authenticated as: {Name:l} <{EmailAddress:l}> {IsService:l}", user.DisplayName, user.EmailAddress, user.IsService ? "(a service account)" : "");
            }

            ValidateParameters();
            await Execute().ConfigureAwait(false);
        }
Exemplo n.º 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(username, password);

            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);

            var user = repository.Users.GetCurrent();

            if (user != null)
            {
                log.DebugFormat("Authenticated as: {0} <{1}> {2}", user.DisplayName, user.EmailAddress, user.IsService ? "(a service account)" : "");
            }

            Execute();
        }
Exemplo n.º 3
0
        public override async Task Execute(string[] commandLineArguments)
        {
            var remainingArguments = Options.Parse(commandLineArguments);

            if (printHelp)
            {
                GetHelp(Console.Out, commandLineArguments);

                return;
            }

            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/. " +
                                           $"The Octopus Server URL can also be set in the {ServerUrlEnvVar} environment variable.");
            }

            if (!string.IsNullOrWhiteSpace(ApiKey) && !string.IsNullOrWhiteSpace(Username))
            {
                throw new CommandException("Please provide an API Key OR a username and password, not both. " +
                                           "These values may have been passed in as command line arguments, or may have been set in the " +
                                           $"{ApiKeyEnvVar} and {UsernameEnvVar} environment variables.");
            }

            if (string.IsNullOrWhiteSpace(ApiKey) && string.IsNullOrWhiteSpace(Username))
            {
                throw new CommandException("Please specify your API key using --apiKey=ABCDEF123456789 OR a username and password. " +
                                           $"The API key can also be set in the {ApiKeyEnvVar} environment variable, " +
                                           $"while the username and password can be set in the {UsernameEnvVar} and {PasswordEnvVar} " +
                                           "environment variables respectively. Learn more at: https://github.com/OctopusDeploy/Octopus-Tools");
            }

            var endpoint = string.IsNullOrWhiteSpace(ApiKey)
                ? new OctopusServerEndpoint(ServerBaseUrl)
                : new OctopusServerEndpoint(ServerBaseUrl, ApiKey);

#if NETFRAMEWORK
            /*
             * There may be a delay between the completion of a large file upload and when Octopus responds
             * to finish the HTTP connection. This delay can be several minutes. During this time, no traffic is
             * sent, and some networking infrastructure will close the connection. For example, Azure VMs will
             * close idle connections after 4 minutes, and AWS VMs will close them after 350 seconds. The
             * TCP keepalive option will ensure that the connection is not idle at the end of the file upload.
             *
             * This is the bug that explains why this doesn't work with .NET Core:
             * https://github.com/dotnet/corefx/issues/26013
             */
            if (keepAlive > 0)
            {
                ServicePointManager.FindServicePoint(new Uri(ServerBaseUrl)).SetTcpKeepAlive(true, keepAlive, keepAlive);
            }
#endif

#if HTTP_CLIENT_SUPPORTS_SSL_OPTIONS
            clientOptions.IgnoreSslErrors = ignoreSslErrors;
#else
            ServicePointManager.ServerCertificateValidationCallback = ServerCertificateValidationCallback;
#endif

            commandOutputProvider.PrintMessages = OutputFormat == OutputFormat.Default || enableDebugging;
            CliSerilogLogProvider.PrintMessages = commandOutputProvider.PrintMessages;
            commandOutputProvider.PrintHeader();

            var client = await clientFactory.CreateAsyncClient(endpoint, clientOptions).ConfigureAwait(false);

            if (!string.IsNullOrWhiteSpace(Username))
            {
                await client.Repository.Users.SignIn(Username, Password).ConfigureAwait(false);
            }

            var serverHasSpaces = await client.ForSystem().HasLink("Spaces").ConfigureAwait(false);

            if (!string.IsNullOrEmpty(spaceNameOrId))
            {
                if (!serverHasSpaces)
                {
                    throw new CommandException($"The server {endpoint.OctopusServer} has no spaces. Try invoking {AssemblyExtensions.GetExecutableName()} without specifying the space name as an argument");
                }

                var space = await client.ForSystem().Spaces.FindByNameOrIdOrFail(spaceNameOrId).ConfigureAwait(false);

                Repository = repositoryFactory.CreateRepository(client, RepositoryScope.ForSpace(space));
                commandOutputProvider.Debug("Space name specified, process is now running in the context of space: {space:l}", space.Name);
            }
            else
            {
                Repository = repositoryFactory.CreateRepository(client);

                if (!serverHasSpaces)
                {
                    commandOutputProvider.Debug("Process will run in backwards compatible mode for older versions of Octopus Server");
                }
                else
                {
                    var defaultSpace = await client.ForSystem()
                                       .Spaces.FindOne(space => space.IsDefault)
                                       .ConfigureAwait(false);

                    if (defaultSpace == null)
                    {
                        throw new CommandException("Octopus Server does not have a default space enabled, hence you need to specify the space name as an argument");
                    }

                    commandOutputProvider.Debug("Space name unspecified, process will run in the default space context");
                }
            }

            RepositoryCommonQueries = new OctopusRepositoryCommonQueries(Repository, commandOutputProvider);

            if (enableDebugging)
            {
                Repository.Client.SendingOctopusRequest += request => commandOutputProvider.Debug("{Method:l} {Uri:l}", request.Method, request.Uri);
            }

            commandOutputProvider.Debug("Handshaking with Octopus Server: {Url:l}", ServerBaseUrl);

            var root = await Repository.LoadRootDocument().ConfigureAwait(false);

            commandOutputProvider.Debug("Handshake successful. Octopus version: {Version:l}; API version: {ApiVersion:l}", root.Version, root.ApiVersion);

            var user = await Repository.Users.GetCurrent().ConfigureAwait(false);

            if (user != null)
            {
                if (string.IsNullOrEmpty(user.EmailAddress))
                {
                    commandOutputProvider.Debug("Authenticated as: {Name:l} {IsService:l}", user.DisplayName, user.IsService ? "(a service account)" : "");
                }
                else
                {
                    commandOutputProvider.Debug("Authenticated as: {Name:l} <{EmailAddress:l}> {IsService:l}", user.DisplayName, user.EmailAddress, user.IsService ? "(a service account)" : "");
                }
            }

            await ValidateParameters().ConfigureAwait(false);
            await Execute().ConfigureAwait(false);
        }
Exemplo n.º 4
0
        public async Task Execute(string[] commandLineArguments)
        {
            var remainingArguments = Options.Parse(commandLineArguments);

            if (printHelp)
            {
                this.GetHelp(Console.Out, commandLineArguments);

                return;
            }

            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/. " +
                                           $"The Octopus Server URL can also be set in the {ServerUrlEnvVar} environment variable.");
            }

            if (!string.IsNullOrWhiteSpace(ApiKey) && !string.IsNullOrWhiteSpace(Username))
            {
                throw new CommandException("Please provide an API Key OR a username and password, not both. " +
                                           "These values may have been passed in as command line arguments, or may have been set in the " +
                                           $"{ApiKeyEnvVar} and {UsernameEnvVar} environment variables.");
            }

            if (string.IsNullOrWhiteSpace(ApiKey) && string.IsNullOrWhiteSpace(Username))
            {
                throw new CommandException("Please specify your API key using --apiKey=ABCDEF123456789 OR a username and password. " +
                                           $"The API key can also be set in the {ApiKeyEnvVar} environment variable, " +
                                           $"while the username and password can be set in the {UsernameEnvVar} and {PasswordEnvVar} " +
                                           "environment variables respectively. Learn more at: https://github.com/OctopusDeploy/Octopus-Tools");
            }

            var endpoint = string.IsNullOrWhiteSpace(ApiKey)
                ? new OctopusServerEndpoint(ServerBaseUrl)
                : new OctopusServerEndpoint(ServerBaseUrl, ApiKey);

#if HTTP_CLIENT_SUPPORTS_SSL_OPTIONS
            clientOptions.IgnoreSslErrors = ignoreSslErrors;
#else
            ServicePointManager.ServerCertificateValidationCallback = ServerCertificateValidationCallback;
#endif

            commandOutputProvider.PrintMessages = OutputFormat == OutputFormat.Default || enableDebugging;
            commandOutputProvider.PrintHeader();

            var client = await clientFactory.CreateAsyncClient(endpoint, clientOptions).ConfigureAwait(false);

            Repository = repositoryFactory.CreateRepository(client);
            RepositoryCommonQueries = new OctopusRepositoryCommonQueries(Repository, commandOutputProvider);

            if (enableDebugging)
            {
                Repository.Client.SendingOctopusRequest += request => commandOutputProvider.Debug("{Method:l} {Uri:l}", request.Method, request.Uri);
            }

            commandOutputProvider.Debug("Handshaking with Octopus server: {Url:l}", ServerBaseUrl);

            var root = Repository.Client.RootDocument;

            commandOutputProvider.Debug("Handshake successful. Octopus version: {Version:l}; API version: {ApiVersion:l}", root.Version, root.ApiVersion);

            if (!string.IsNullOrWhiteSpace(Username))
            {
                await Repository.Users.SignIn(Username, Password);
            }

            var user = await Repository.Users.GetCurrent().ConfigureAwait(false);

            if (user != null)
            {
                commandOutputProvider.Debug("Authenticated as: {Name:l} <{EmailAddress:l}> {IsService:l}", user.DisplayName, user.EmailAddress, user.IsService ? "(a service account)" : "");
            }

            ValidateParameters();
            await Execute().ConfigureAwait(false);
        }
Exemplo n.º 5
0
        public void Execute(string[] commandLineArguments)
        {
            optionGroups.Parse(commandLineArguments);

            if (string.IsNullOrWhiteSpace(id))
            {
                throw new CommandException("An ID is required");
            }

            if (includes.All(string.IsNullOrWhiteSpace))
            {
                includes.Add("**");
            }

            if (string.IsNullOrWhiteSpace(basePath))
            {
                basePath = Path.GetFullPath(Environment.CurrentDirectory);
            }

            if (string.IsNullOrWhiteSpace(outFolder))
            {
                outFolder = Path.GetFullPath(Environment.CurrentDirectory);
            }

            if (version == null)
            {
                var now = DateTime.Now;
                version = new SemanticVersion(now.Year, now.Month, now.Day, now.Hour * 10000 + now.Minute * 100 + now.Second);
            }

            if (authors.All(string.IsNullOrWhiteSpace))
            {
                authors.Add(Environment.UserName + "@" + Environment.UserDomainName);
            }

            if (string.IsNullOrWhiteSpace(description))
            {
                description = "A deployment package created from files on disk.";
            }

            string allReleaseNotes = null;

            if (!string.IsNullOrWhiteSpace(releaseNotesFile))
            {
                if (!File.Exists(releaseNotesFile))
                {
                    log.Warning("The release notes file '{0}' could not be found", releaseNotesFile);
                }
                else
                {
                    allReleaseNotes = fileSystem.ReadFile(releaseNotesFile);
                }
            }

            if (!string.IsNullOrWhiteSpace(releaseNotes))
            {
                if (allReleaseNotes != null)
                {
                    allReleaseNotes += Environment.NewLine + releaseNotes;
                }
                else
                {
                    allReleaseNotes = releaseNotes;
                }
            }

            var metadata = new ManifestMetadata
            {
                Id          = id,
                Authors     = authors,
                Description = description,
                Version     = version.ToNuGetVersion(),
            };

            if (!string.IsNullOrWhiteSpace(allReleaseNotes))
            {
                metadata.ReleaseNotes = allReleaseNotes;
            }

            if (!string.IsNullOrWhiteSpace(title))
            {
                metadata.Title = title;
            }

            log.Information("Packing {0} version {1}...", id, version);

            packageBuilder.BuildPackage(basePath, includes, metadata, outFolder, overwrite);

            log.Information("Done.");
        }