public ExitCode Run(IFilesystem filesystem, IInternalPluginRepository repository, AddUserOptions options) { try { var accessToken = repository.AddUser(options.Username, options.Email, options.AccessToken); Log.InfoFormat("Added user {0}, {1}", options.Username, options.Email); Log.InfoFormat("The following access token has been generated for this user"); Log.InfoFormat("DO NOT SHARE THIS TOKEN WITH ANYONE AS IT CAN BE USED TO PUSH PLUGINS TO THIS REPOSITORY"); Log.InfoFormat("\t{0}", accessToken); return(ExitCode.Success); } catch (CannotAddUserException e) { if (!e.IsError) { Log.WarnFormat(e.Message); return(ExitCode.Success); } Log.ErrorFormat(e.Message); return(ExitCode.GenericFailure); } }
public ExitCode Run(IFilesystem filesystem, IInternalPluginRepository repository, ListPluginsOptions options) { foreach (var plugin in repository.FindAllPlugins()) { Console.WriteLine("\t{0}", plugin); } return(ExitCode.Success); }
public ExitCode Run(IFilesystem filesystem, IInternalPluginRepository repository, WriteConfigurationOptions options) { var filePath = MakeAbsolute(options.Filename); Log.DebugFormat("Writing configuration to '{0}'...", filePath); new ServerConfiguration().WriteTo(filePath); Log.InfoFormat("Configuration file written to '{0}'", filePath); return(ExitCode.Success); }
public ExitCode Run(IFilesystem filesystem, IInternalPluginRepository repository, RemovePluginOptions options) { try { repository.RemovePlugin(options.Id, options.Version); } catch (CannotRemovePluginException e) { Log.ErrorFormat(e.Message); return(ExitCode.GenericFailure); } return(ExitCode.Success); }
public ExitCode Run(IFilesystem filesystem, IInternalPluginRepository repository, RemoveUserOptions options) { try { repository.RemoveUser(options.Username); Log.InfoFormat("Removed user '{0}'", options.Username); return(ExitCode.Success); } catch (CannotRemoveUserException e) { Log.ErrorFormat(e.Message); return(ExitCode.GenericFailure); } }
public ExitCode Run(IFilesystem filesystem, IInternalPluginRepository repository, RunServerOptions options) { try { var fileName = Constants.ApplicationConfigurationFile; Log.InfoFormat("Using configuration file '{0}'", fileName); var configuration = ServerConfiguration.ReadOrCreate(fileName); if (options.AllowRemotePublish != null) { configuration.Publishing.AllowRemotePublish = options.AllowRemotePublish.Value; } Log.InfoFormat("Remote publishing is {0}", configuration.Publishing.AllowRemotePublish ? "allowed" : "not allowed"); if (!SetConsoleCtrlHandler(ConsoleCtrlCheck, add: true)) { var error = Marshal.GetLastWin32Error(); Log.WarnFormat("Could not add console ctrl handler, GetLastError()={0}", error); } Log.InfoFormat("The repository contains {0} plugin(s)", repository.CountPlugins()); Log.InfoFormat("Starting server..."); var repositoryProxy = new PluginRepositoryProxy(repository, configuration); if (!TryParseEndPoint(configuration.Address, out var ep)) { return(ExitCode.InvalidAddress); } using (new Server(ep, repositoryProxy)) { Console.WriteLine("Press ctrl+c to exit the application..."); BeginShutdownEvent.WaitOne(); return(ExitCode.Success); } } finally { FinishedShutdownEvent.Set(); } }
public ExitCode Run(IFilesystem filesystem, IInternalPluginRepository repository, ListUsersOptions options) { var users = repository.GetAllUsers().ToList(); if (users.Any()) { Console.WriteLine("There are {0} user(s):", users.Count); foreach (var user in users) { Console.WriteLine("\t{0}, {1}, access token: {2}", user.Username, user.Email, user.AccessToken); } } else { Console.WriteLine("No users have been added"); } return(ExitCode.GenericFailure); }
public ExitCode Run(IFilesystem filesystem, IInternalPluginRepository repository, AddPluginOptions options) { try { if (!TryLoadPlugin(filesystem, options.PluginFileName, out var plugin, out var exitCode)) { return(exitCode); } if (!string.IsNullOrEmpty(options.Username)) { if (!repository.TryGetAccessToken(options.Username, out var token)) { Log.InfoFormat("'{0}' is not a valid username.", options.Username); return(ExitCode.InvalidUserName); } repository.PublishPlugin(plugin, token.ToString(), options.PublishTimestamp); } else if (!string.IsNullOrEmpty(options.AccessToken)) { repository.PublishPlugin(plugin, options.AccessToken, options.PublishTimestamp); } else { Log.ErrorFormat("Either a username or an access-token must be specified"); return(ExitCode.GenericFailure); } } catch (InvalidUserTokenException e) { Log.ErrorFormat(e.Message); return(ExitCode.InvalidUserToken); } return(ExitCode.Success); }
public ExitCode Run(IFilesystem filesystem, IInternalPluginRepository repository, ExportOptions options) { var folder = options.ExportFolder; Directory.CreateDirectory(folder); using (var file = filesystem.CreateFile(Path.Combine(folder, "import.cmd"))) using (var writer = new StreamWriter(file)) { writer.WriteLine("@echo off"); writer.WriteLine("setlocal"); writer.WriteLine(); writer.WriteLine("set SCRIPT_PATH=%~dp0"); writer.WriteLine(); writer.WriteLine("rem Add users"); foreach (var user in repository.GetAllUsers()) { writer.WriteLine("repository.exe add-user \"{0}\" \"{1}\" --access-token \"{2}\"", user.Username, user.Email, user.AccessToken); } writer.WriteLine(); writer.WriteLine("rem Add plugins"); foreach (var plugin in repository.GetAllPlugins()) { var content = repository.DownloadPlugin(plugin.Identifier); var pluginFileName = $"{plugin.Identifier.Id}.{plugin.Identifier.Version}.tvp"; var pluginFilePath = Path.Combine(folder, pluginFileName); File.WriteAllBytes(pluginFilePath, content); writer.WriteLine("repository.exe add-plugin \"%SCRIPT_PATH%\\{0}\" --user \"{1}\" --publish-timestamp {2}", pluginFileName, plugin.Publisher, plugin.PublishTimestamp.ToString(CultureInfo.InvariantCulture)); } writer.WriteLine("endlocal"); } return(ExitCode.Success); }