Example #1
0
 /// <summary>
 /// Construct an <see cref="AdministrationController"/>
 /// </summary>
 /// <param name="databaseContext">The <see cref="IDatabaseContext"/> for the <see cref="ApiController"/></param>
 /// <param name="authenticationContextFactory">The <see cref="IAuthenticationContextFactory"/> for the <see cref="ApiController"/></param>
 /// <param name="gitHubClientFactory">The value of <see cref="gitHubClientFactory"/></param>
 /// <param name="serverUpdater">The value of <see cref="serverUpdater"/></param>
 /// <param name="assemblyInformationProvider">The value of <see cref="assemblyInformationProvider"/></param>
 /// <param name="ioManager">The value of <see cref="ioManager"/></param>
 /// <param name="platformIdentifier">The value of <see cref="platformIdentifier"/></param>
 /// <param name="logger">The <see cref="ILogger"/> for the <see cref="ApiController"/></param>
 /// <param name="updatesConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing value of <see cref="updatesConfiguration"/></param>
 /// <param name="generalConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing value of <see cref="generalConfiguration"/></param>
 /// <param name="fileLoggingConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing value of <see cref="fileLoggingConfiguration"/></param>
 public AdministrationController(
     IDatabaseContext databaseContext,
     IAuthenticationContextFactory authenticationContextFactory,
     IGitHubClientFactory gitHubClientFactory,
     IServerControl serverUpdater,
     IAssemblyInformationProvider assemblyInformationProvider,
     IIOManager ioManager,
     IPlatformIdentifier platformIdentifier,
     ILogger <AdministrationController> logger,
     IOptions <UpdatesConfiguration> updatesConfigurationOptions,
     IOptions <GeneralConfiguration> generalConfigurationOptions,
     IOptions <FileLoggingConfiguration> fileLoggingConfigurationOptions)
     : base(
         databaseContext,
         authenticationContextFactory,
         logger,
         false)
 {
     this.gitHubClientFactory         = gitHubClientFactory ?? throw new ArgumentNullException(nameof(gitHubClientFactory));
     this.serverUpdater               = serverUpdater ?? throw new ArgumentNullException(nameof(serverUpdater));
     this.assemblyInformationProvider = assemblyInformationProvider ?? throw new ArgumentNullException(nameof(assemblyInformationProvider));
     this.ioManager           = ioManager ?? throw new ArgumentNullException(nameof(ioManager));
     this.platformIdentifier  = platformIdentifier ?? throw new ArgumentNullException(nameof(platformIdentifier));
     updatesConfiguration     = updatesConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(updatesConfigurationOptions));
     generalConfiguration     = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions));
     fileLoggingConfiguration = fileLoggingConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(fileLoggingConfigurationOptions));
 }
        /// <summary>
        /// Construct a <see cref="TokenFactory"/>
        /// </summary>
        /// <param name="asyncDelayer">The value of <see cref="asyncDelayer"/></param>
        /// <param name="cryptographySuite">The <see cref="ICryptographySuite"/> used for generating the <see cref="ValidationParameters"/></param>
        /// <param name="assemblyInformationProvider">The <see cref="IAssemblyInformationProvider"/> used to generate the issuer name.</param>
        public TokenFactory(
            IAsyncDelayer asyncDelayer,
            ICryptographySuite cryptographySuite,
            IAssemblyInformationProvider assemblyInformationProvider)
        {
            ValidationParameters = new TokenValidationParameters
            {
                ValidateIssuerSigningKey = true,
                IssuerSigningKey         = new SymmetricSecurityKey(cryptographySuite.GetSecureBytes(TokenSigningKeyByteAmount)),

                ValidateIssuer = true,
                ValidIssuer    = assemblyInformationProvider.Name.Name,

                ValidateLifetime = true,
                ValidateAudience = true,
                ValidAudience    = typeof(Token).Assembly.GetName().Name,

                ClockSkew = TimeSpan.FromMinutes(TokenClockSkewMinutes),

                RequireSignedTokens = true,

                RequireExpirationTime = true
            };

            this.asyncDelayer = asyncDelayer ?? throw new ArgumentNullException(nameof(asyncDelayer));
        }
        /// <summary>
        /// Gets the evaluated log <see cref="Directory"/>.
        /// </summary>
        /// <param name="ioManager">The <see cref="IIOManager"/> to use.</param>
        /// <param name="assemblyInformationProvider">The <see cref="IAssemblyInformationProvider"/> to use.</param>
        /// <param name="platformIdentifier">The <see cref="IPlatformIdentifier"/> to use</param>
        /// <returns>The evaluated log <see cref="Directory"/>.</returns>
        public string GetFullLogDirectory(
            IIOManager ioManager,
            IAssemblyInformationProvider assemblyInformationProvider,
            IPlatformIdentifier platformIdentifier)
        {
            if (ioManager == null)
            {
                throw new ArgumentNullException(nameof(ioManager));
            }
            if (assemblyInformationProvider == null)
            {
                throw new ArgumentNullException(nameof(assemblyInformationProvider));
            }
            if (platformIdentifier == null)
            {
                throw new ArgumentNullException(nameof(platformIdentifier));
            }

            var directoryToUse = platformIdentifier.IsWindows
                                ? Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) // C:/ProgramData
                                : "/var/log";                                                                // :pain:

            return(!String.IsNullOrEmpty(Directory)
                                ? Directory
                                : ioManager.ConcatPath(
                       directoryToUse,
                       assemblyInformationProvider.VersionPrefix));
        }
Example #4
0
        /// <summary>
        /// Construct an <see cref="InstanceManager"/>
        /// </summary>
        /// <param name="instanceFactory">The value of <see cref="instanceFactory"/></param>
        /// <param name="ioManager">The value of <paramref name="ioManager"/></param>
        /// <param name="databaseContextFactory">The value of <paramref name="databaseContextFactory"/></param>
        /// <param name="assemblyInformationProvider">The value of <see cref="assemblyInformationProvider"/></param>
        /// <param name="jobManager">The value of <see cref="jobManager"/></param>
        /// <param name="serverControl">The value of <see cref="serverControl"/></param>
        /// <param name="systemIdentityFactory">The value of <see cref="systemIdentityFactory"/>.</param>
        /// <param name="asyncDelayer">The value of <see cref="asyncDelayer"/>.</param>
        /// <param name="generalConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="generalConfiguration"/>.</param>
        /// <param name="logger">The value of <see cref="logger"/></param>
        public InstanceManager(
            IInstanceFactory instanceFactory,
            IIOManager ioManager,
            IDatabaseContextFactory databaseContextFactory,
            IAssemblyInformationProvider assemblyInformationProvider,
            IJobManager jobManager,
            IServerControl serverControl,
            ISystemIdentityFactory systemIdentityFactory,
            IAsyncDelayer asyncDelayer,
            IOptions <GeneralConfiguration> generalConfigurationOptions,
            ILogger <InstanceManager> logger)
        {
            this.instanceFactory             = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory));
            this.ioManager                   = ioManager ?? throw new ArgumentNullException(nameof(ioManager));
            this.databaseContextFactory      = databaseContextFactory ?? throw new ArgumentNullException(nameof(databaseContextFactory));
            this.assemblyInformationProvider = assemblyInformationProvider ?? throw new ArgumentNullException(nameof(assemblyInformationProvider));
            this.jobManager                  = jobManager ?? throw new ArgumentNullException(nameof(jobManager));
            this.serverControl               = serverControl ?? throw new ArgumentNullException(nameof(serverControl));
            this.systemIdentityFactory       = systemIdentityFactory ?? throw new ArgumentNullException(nameof(systemIdentityFactory));
            this.asyncDelayer                = asyncDelayer ?? throw new ArgumentNullException(nameof(asyncDelayer));
            generalConfiguration             = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions));
            this.logger = logger ?? throw new ArgumentNullException(nameof(logger));

            serverControl.RegisterForRestart(this);

            instances      = new Dictionary <long, IInstance>();
            bridgeHandlers = new Dictionary <string, IBridgeHandler>();
            readyTcs       = new TaskCompletionSource <object>();
        }
Example #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InstanceManager"/> class.
        /// </summary>
        /// <param name="instanceFactory">The value of <see cref="instanceFactory"/>.</param>
        /// <param name="ioManager">The value of <paramref name="ioManager"/>.</param>
        /// <param name="databaseContextFactory">The value of <paramref name="databaseContextFactory"/>.</param>
        /// <param name="assemblyInformationProvider">The value of <see cref="assemblyInformationProvider"/>.</param>
        /// <param name="jobManager">The value of <see cref="jobManager"/>.</param>
        /// <param name="serverControl">The value of <see cref="serverControl"/>.</param>
        /// <param name="systemIdentityFactory">The value of <see cref="systemIdentityFactory"/>.</param>
        /// <param name="asyncDelayer">The value of <see cref="asyncDelayer"/>.</param>
        /// <param name="serverPortProvider">The value of <see cref="serverPortProvider"/>.</param>
        /// <param name="swarmService">The value of <see cref="swarmService"/>.</param>
        /// <param name="generalConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="generalConfiguration"/>.</param>
        /// <param name="swarmConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="swarmConfiguration"/>.</param>
        /// <param name="logger">The value of <see cref="logger"/>.</param>
        public InstanceManager(
            IInstanceFactory instanceFactory,
            IIOManager ioManager,
            IDatabaseContextFactory databaseContextFactory,
            IAssemblyInformationProvider assemblyInformationProvider,
            IJobManager jobManager,
            IServerControl serverControl,
            ISystemIdentityFactory systemIdentityFactory,
            IAsyncDelayer asyncDelayer,
            IServerPortProvider serverPortProvider,
            ISwarmService swarmService,
            IOptions <GeneralConfiguration> generalConfigurationOptions,
            IOptions <SwarmConfiguration> swarmConfigurationOptions,
            ILogger <InstanceManager> logger)
        {
            this.instanceFactory             = instanceFactory ?? throw new ArgumentNullException(nameof(instanceFactory));
            this.ioManager                   = ioManager ?? throw new ArgumentNullException(nameof(ioManager));
            this.databaseContextFactory      = databaseContextFactory ?? throw new ArgumentNullException(nameof(databaseContextFactory));
            this.assemblyInformationProvider = assemblyInformationProvider ?? throw new ArgumentNullException(nameof(assemblyInformationProvider));
            this.jobManager                  = jobManager ?? throw new ArgumentNullException(nameof(jobManager));
            this.serverControl               = serverControl ?? throw new ArgumentNullException(nameof(serverControl));
            this.systemIdentityFactory       = systemIdentityFactory ?? throw new ArgumentNullException(nameof(systemIdentityFactory));
            this.asyncDelayer                = asyncDelayer ?? throw new ArgumentNullException(nameof(asyncDelayer));
            this.serverPortProvider          = serverPortProvider ?? throw new ArgumentNullException(nameof(serverPortProvider));
            this.swarmService                = swarmService ?? throw new ArgumentNullException(nameof(swarmService));
            generalConfiguration             = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions));
            swarmConfiguration               = swarmConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(swarmConfigurationOptions));
            this.logger = logger ?? throw new ArgumentNullException(nameof(logger));

            instances      = new Dictionary <long, InstanceContainer>();
            bridgeHandlers = new Dictionary <string, IBridgeHandler>();
            readyTcs       = new TaskCompletionSource <object>();
            instanceStateChangeSemaphore = new SemaphoreSlim(1);
        }
 /// <summary>
 /// Construct a <see cref="HomeController"/>
 /// </summary>
 /// <param name="databaseContext">The <see cref="IDatabaseContext"/> for the <see cref="ApiController"/></param>
 /// <param name="authenticationContextFactory">The <see cref="IAuthenticationContextFactory"/> for the <see cref="ApiController"/></param>
 /// <param name="tokenFactory">The value of <see cref="tokenFactory"/></param>
 /// <param name="systemIdentityFactory">The value of <see cref="systemIdentityFactory"/></param>
 /// <param name="cryptographySuite">The value of <see cref="cryptographySuite"/></param>
 /// <param name="assemblyInformationProvider">The value of <see cref="assemblyInformationProvider"/></param>
 /// <param name="identityCache">The value of <see cref="identityCache"/></param>
 /// <param name="oAuthProviders">The value of <see cref="oAuthProviders"/>.</param>
 /// <param name="platformIdentifier">The value of <see cref="platformIdentifier"/>.</param>
 /// <param name="browserResolver">The value of <see cref="browserResolver"/></param>
 /// <param name="swarmService">The value of <see cref="swarmService"/>.</param>
 /// <param name="serverControl">The value of <see cref="serverControl"/>.</param>
 /// <param name="generalConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="generalConfiguration"/>.</param>
 /// <param name="controlPanelConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="controlPanelConfiguration"/></param>
 /// <param name="logger">The <see cref="ILogger"/> for the <see cref="ApiController"/></param>
 public HomeController(
     IDatabaseContext databaseContext,
     IAuthenticationContextFactory authenticationContextFactory,
     ITokenFactory tokenFactory,
     ISystemIdentityFactory systemIdentityFactory,
     ICryptographySuite cryptographySuite,
     IAssemblyInformationProvider assemblyInformationProvider,
     IIdentityCache identityCache,
     IOAuthProviders oAuthProviders,
     IPlatformIdentifier platformIdentifier,
     IBrowserResolver browserResolver,
     ISwarmService swarmService,
     IServerControl serverControl,
     IOptions <GeneralConfiguration> generalConfigurationOptions,
     IOptions <ControlPanelConfiguration> controlPanelConfigurationOptions,
     ILogger <HomeController> logger)
     : base(
         databaseContext,
         authenticationContextFactory,
         logger,
         false)
 {
     this.tokenFactory                = tokenFactory ?? throw new ArgumentNullException(nameof(tokenFactory));
     this.systemIdentityFactory       = systemIdentityFactory ?? throw new ArgumentNullException(nameof(systemIdentityFactory));
     this.cryptographySuite           = cryptographySuite ?? throw new ArgumentNullException(nameof(cryptographySuite));
     this.assemblyInformationProvider = assemblyInformationProvider ?? throw new ArgumentNullException(nameof(assemblyInformationProvider));
     this.identityCache               = identityCache ?? throw new ArgumentNullException(nameof(identityCache));
     this.platformIdentifier          = platformIdentifier ?? throw new ArgumentNullException(nameof(platformIdentifier));
     this.oAuthProviders              = oAuthProviders ?? throw new ArgumentNullException(nameof(oAuthProviders));
     this.browserResolver             = browserResolver ?? throw new ArgumentNullException(nameof(browserResolver));
     this.swarmService                = swarmService ?? throw new ArgumentNullException(nameof(swarmService));
     this.serverControl               = serverControl ?? throw new ArgumentNullException(nameof(serverControl));
     generalConfiguration             = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions));
     controlPanelConfiguration        = controlPanelConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(controlPanelConfigurationOptions));
 }
Example #7
0
        /// <summary>
        /// The <see cref="Task{TResult}"/> for <see cref="LaunchResult"/>.
        /// </summary>
        /// <param name="assemblyInformationProvider">The <see cref="IAssemblyInformationProvider"/>.</param>
        /// <param name="startupTimeout">The, optional, startup timeout in seconds.</param>
        /// <param name="reattached">If DreamDaemon was reattached.</param>
        /// <param name="apiValidate">If this is a DMAPI validation session.</param>
        /// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="Session.LaunchResult"/> for the operation.</returns>
        async Task <LaunchResult> GetLaunchResult(
            IAssemblyInformationProvider assemblyInformationProvider,
            uint?startupTimeout,
            bool reattached,
            bool apiValidate)
        {
            var startTime = DateTimeOffset.UtcNow;
            var useBridgeRequestForLaunchResult = !reattached && (apiValidate || DMApiAvailable);
            var startupTask = useBridgeRequestForLaunchResult
                                ? initialBridgeRequestTcs.Task
                                : process.Startup;
            var toAwait = Task.WhenAny(startupTask, process.Lifetime);

            if (startupTimeout.HasValue)
            {
                toAwait = Task.WhenAny(toAwait, Task.Delay(TimeSpan.FromSeconds(startupTimeout.Value)));
            }

            logger.LogTrace(
                "Waiting for LaunchResult based on {0}{1}...",
                useBridgeRequestForLaunchResult ? "initial bridge request" : "process startup",
                startupTimeout.HasValue ? $" with a timeout of {startupTimeout.Value}s" : String.Empty);

            await toAwait.ConfigureAwait(false);

            var result = new LaunchResult
            {
                ExitCode    = process.Lifetime.IsCompleted ? (int?)await process.Lifetime.ConfigureAwait(false) : null,
                StartupTime = startupTask.IsCompleted ? (TimeSpan?)(DateTimeOffset.UtcNow - startTime) : null
            };

            logger.LogTrace("Launch result: {0}", result);

            if (!result.ExitCode.HasValue && reattached && !disposed)
            {
                var reattachResponse = await SendCommand(
                    new TopicParameters(
                        assemblyInformationProvider.Version,
                        reattachInformation.RuntimeInformation.ServerPort),
                    reattachTopicCts.Token)
                                       .ConfigureAwait(false);

                if (reattachResponse != null)
                {
                    if (reattachResponse.InteropResponse?.CustomCommands != null)
                    {
                        chatTrackingContext.CustomCommands = reattachResponse.InteropResponse.CustomCommands;
                    }
                    else if (reattachResponse.InteropResponse != null)
                    {
                        logger.LogWarning(
                            "DMAPI v{0} isn't returning the TGS custom commands list. Functionality added in v5.2.0.",
                            CompileJob.DMApiVersion.Semver());
                    }
                }
            }

            return(result);
        }
Example #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="KeycloakOAuthValidator"/> <see langword="class"/>.
 /// </summary>
 /// <param name="httpClientFactory">The <see cref="IHttpClientFactory"/> for the <see cref="GenericOAuthValidator"/>.</param>
 /// <param name="assemblyInformationProvider">The <see cref="IAssemblyInformationProvider"/> for the <see cref="GenericOAuthValidator"/>.</param>
 /// <param name="logger">The <see cref="ILogger"/> for the <see cref="GenericOAuthValidator"/>.</param>
 /// <param name="oAuthConfiguration">The <see cref="OAuthConfiguration"/> for the <see cref="GenericOAuthValidator"/>.</param>
 public KeycloakOAuthValidator(
     IHttpClientFactory httpClientFactory,
     IAssemblyInformationProvider assemblyInformationProvider,
     ILogger <KeycloakOAuthValidator> logger,
     OAuthConfiguration oAuthConfiguration)
     : base(httpClientFactory, assemblyInformationProvider, logger, oAuthConfiguration)
 {
 }
 /// <summary>
 /// Construct a <see cref="ProviderFactory"/>
 /// </summary>
 /// <param name="assemblyInformationProvider">The value of <see cref="assemblyInformationProvider"/></param>
 /// <param name="asyncDelayer">The value of <see cref="asyncDelayer"/></param>
 /// <param name="loggerFactory">The value of <see cref="loggerFactory"/></param>
 public ProviderFactory(
     IAssemblyInformationProvider assemblyInformationProvider,
     IAsyncDelayer asyncDelayer,
     ILoggerFactory loggerFactory)
 {
     this.loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
     this.asyncDelayer = asyncDelayer ?? throw new ArgumentNullException(nameof(asyncDelayer));
     this.assemblyInformationProvider = assemblyInformationProvider ?? throw new ArgumentNullException(nameof(assemblyInformationProvider));
 }
Example #10
0
        public void TestContructor()
        {
            Assert.ThrowsException <ArgumentNullException>(() => new ServerFactory(null, null));
            IAssemblyInformationProvider assemblyInformationProvider = Mock.Of <IAssemblyInformationProvider>();

            Assert.ThrowsException <ArgumentNullException>(() => new ServerFactory(assemblyInformationProvider, null));
            IIOManager ioManager = Mock.Of <IIOManager>();

            new ServerFactory(assemblyInformationProvider, ioManager);
        }
Example #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IrcProvider"/> class.
        /// </summary>
        /// <param name="jobManager">The <see cref="IJobManager"/> for the provider.</param>
        /// <param name="assemblyInformationProvider">The <see cref="IAssemblyInformationProvider"/> to get the <see cref="IAssemblyInformationProvider.VersionString"/> from.</param>
        /// <param name="asyncDelayer">The value of <see cref="asyncDelayer"/>.</param>
        /// <param name="logger">The <see cref="ILogger"/> for the <see cref="Provider"/>.</param>
        /// <param name="chatBot">The <see cref="Models.ChatBot"/> for the <see cref="Provider"/>.</param>
        public IrcProvider(
            IJobManager jobManager,
            IAssemblyInformationProvider assemblyInformationProvider,
            IAsyncDelayer asyncDelayer,
            ILogger <IrcProvider> logger,
            Models.ChatBot chatBot)
            : base(jobManager, logger, chatBot)
        {
            if (assemblyInformationProvider == null)
            {
                throw new ArgumentNullException(nameof(assemblyInformationProvider));
            }

            this.asyncDelayer = asyncDelayer ?? throw new ArgumentNullException(nameof(asyncDelayer));

            var builder = chatBot.CreateConnectionStringBuilder();

            if (builder == null || !builder.Valid || !(builder is IrcConnectionStringBuilder ircBuilder))
            {
                throw new InvalidOperationException("Invalid ChatConnectionStringBuilder!");
            }

            address  = ircBuilder.Address;
            port     = ircBuilder.Port.Value;
            nickname = ircBuilder.Nickname;

            password     = ircBuilder.Password;
            passwordType = ircBuilder.PasswordType;

            client = new IrcFeatures
            {
                SupportNonRfc        = true,
                CtcpUserInfo         = "You are going to play. And I am going to watch. And everything will be just fine...",
                AutoRejoin           = true,
                AutoRejoinOnKick     = true,
                AutoRelogin          = true,
                AutoRetry            = true,
                AutoRetryLimit       = TimeoutSeconds,
                AutoRetryDelay       = TimeoutSeconds,
                ActiveChannelSyncing = true,
                AutoNickHandling     = true,
                CtcpVersion          = assemblyInformationProvider.VersionString,
                UseSsl = ircBuilder.UseSsl.Value,
            };
            if (ircBuilder.UseSsl.Value)
            {
                client.ValidateServerCertificate = true;                 // dunno if it defaults to that or what
            }
            client.OnChannelMessage += Client_OnChannelMessage;
            client.OnQueryMessage   += Client_OnQueryMessage;

            channelIdMap      = new Dictionary <ulong, string>();
            queryChannelIdMap = new Dictionary <ulong, string>();
            channelIdCounter  = 1;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="GenericOAuthValidator"/> <see langword="class"/>.
 /// </summary>
 /// <param name="httpClientFactory">The value of <see cref="httpClientFactory"/>.</param>
 /// <param name="assemblyInformationProvider">The value of <see cref="assemblyInformationProvider"/>.</param>
 /// <param name="logger">The value of <see cref="Logger"/>.</param>
 /// <param name="oAuthConfiguration">The value of <see cref="OAuthConfiguration"/>.</param>
 public BaseOAuthValidator(
     IHttpClientFactory httpClientFactory,
     IAssemblyInformationProvider assemblyInformationProvider,
     ILogger <BaseOAuthValidator> logger,
     OAuthConfiguration oAuthConfiguration)
 {
     this.httpClientFactory           = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory));
     this.assemblyInformationProvider = assemblyInformationProvider ?? throw new ArgumentNullException(nameof(assemblyInformationProvider));
     Logger             = logger ?? throw new ArgumentNullException(nameof(logger));
     OAuthConfiguration = oAuthConfiguration ?? throw new ArgumentNullException(nameof(oAuthConfiguration));
 }
Example #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SwarmController"/> class.
 /// </summary>
 /// <param name="swarmOperations">The value of <see cref="swarmOperations"/>.</param>
 /// <param name="assemblyInformationProvider">The value of <see cref="assemblyInformationProvider"/>.</param>
 /// <param name="swarmConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="swarmConfiguration"/>.</param>
 /// <param name="logger">The value of <see cref="logger"/>.</param>
 public SwarmController(
     ISwarmOperations swarmOperations,
     IAssemblyInformationProvider assemblyInformationProvider,
     IOptions <SwarmConfiguration> swarmConfigurationOptions,
     ILogger <SwarmController> logger)
 {
     this.swarmOperations             = swarmOperations ?? throw new ArgumentNullException(nameof(swarmOperations));
     this.assemblyInformationProvider = assemblyInformationProvider ?? throw new ArgumentNullException(nameof(assemblyInformationProvider));
     swarmConfiguration = swarmConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(swarmConfigurationOptions));
     this.logger        = logger;
 }
Example #14
0
 /// <summary>
 /// Construct a <see cref="DiscordProvider"/>
 /// </summary>
 /// <param name="jobManager">The <see cref="IJobManager"/> for the <see cref="Provider"/>.</param>
 /// <param name="assemblyInformationProvider">The value of <see cref="assemblyInformationProvider"/>.</param>
 /// <param name="logger">The <see cref="ILogger"/> for the <see cref="Provider"/>.</param>
 /// <param name="chatBot">The <see cref="ChatBot"/> for the <see cref="Provider"/>.</param>
 public DiscordProvider(
     IJobManager jobManager,
     IAssemblyInformationProvider assemblyInformationProvider,
     ILogger <DiscordProvider> logger,
     Models.ChatBot chatBot)
     : base(jobManager, logger, chatBot)
 {
     this.assemblyInformationProvider = assemblyInformationProvider ?? throw new ArgumentNullException(nameof(assemblyInformationProvider));
     client = new DiscordSocketClient();
     client.MessageReceived += Client_MessageReceived;
     mappedChannels          = new List <ulong>();
 }
        /// <summary>
        /// Construct a <see cref="SessionController"/>
        /// </summary>
        /// <param name="reattachInformation">The value of <see cref="reattachInformation"/></param>
        /// <param name="process">The value of <see cref="process"/></param>
        /// <param name="byondLock">The value of <see cref="byondLock"/></param>
        /// <param name="byondTopicSender">The value of <see cref="byondTopicSender"/></param>
        /// <param name="bridgeRegistrar">The <see cref="IBridgeRegistrar"/> used to populate <see cref="bridgeRegistration"/>.</param>
        /// <param name="chat">The value of <see cref="chat"/></param>
        /// <param name="chatTrackingContext">The value of <see cref="chatTrackingContext"/></param>
        /// <param name="assemblyInformationProvider">The <see cref="IAssemblyInformationProvider"/> for the <see cref="SessionController"/>.</param>
        /// <param name="logger">The value of <see cref="logger"/></param>
        /// <param name="startupTimeout">The optional time to wait before failing the <see cref="LaunchResult"/></param>
        /// <param name="reattached">If this is a reattached session.</param>
        public SessionController(
            ReattachInformation reattachInformation,
            IProcess process,
            IByondExecutableLock byondLock,
            ITopicClient byondTopicSender,
            IChatTrackingContext chatTrackingContext,
            IBridgeRegistrar bridgeRegistrar,
            IChatManager chat,
            IAssemblyInformationProvider assemblyInformationProvider,
            ILogger <SessionController> logger,
            uint?startupTimeout,
            bool reattached)
        {
            this.reattachInformation = reattachInformation ?? throw new ArgumentNullException(nameof(reattachInformation));
            this.process             = process ?? throw new ArgumentNullException(nameof(process));
            this.byondLock           = byondLock ?? throw new ArgumentNullException(nameof(byondLock));
            this.byondTopicSender    = byondTopicSender ?? throw new ArgumentNullException(nameof(byondTopicSender));
            this.chatTrackingContext = chatTrackingContext ?? throw new ArgumentNullException(nameof(chatTrackingContext));
            bridgeRegistration       = bridgeRegistrar?.RegisterHandler(this) ?? throw new ArgumentNullException(nameof(bridgeRegistrar));
            this.chat   = chat ?? throw new ArgumentNullException(nameof(chat));
            this.logger = logger ?? throw new ArgumentNullException(nameof(logger));

            this.chatTrackingContext.SetChannelSink(this);

            portClosedForReboot = false;
            disposed            = false;
            apiValidationStatus = ApiValidationStatus.NeverValidated;
            released            = false;

            rebootTcs           = new TaskCompletionSource <object>();
            primeTcs            = new TaskCompletionSource <object>();
            reattachTopicCts    = new CancellationTokenSource();
            synchronizationLock = new object();

            _ = process.Lifetime.ContinueWith(
                x =>
            {
                if (!disposed)
                {
                    reattachTopicCts.Cancel();
                }
                chatTrackingContext.Active = false;
            },
                TaskScheduler.Current);

            LaunchResult = GetLaunchResult(
                assemblyInformationProvider,
                startupTimeout,
                reattached);

            logger.LogDebug("Created session controller. Primary: {0}, CommsKey: {1}, Port: {2}", IsPrimary, reattachInformation.AccessIdentifier, Port);
        }
Example #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TGForumsOAuthValidator"/> <see langword="class"/>.
 /// </summary>
 /// <param name="httpClientFactory">The <see cref="IHttpClientFactory"/> for the <see cref="BaseOAuthValidator"/></param>
 /// <param name="assemblyInformationProvider">The <see cref="IAssemblyInformationProvider"/> for the <see cref="BaseOAuthValidator"/></param>
 /// <param name="logger">The <see cref="ILogger"/> for the <see cref="BaseOAuthValidator"/></param>
 /// <param name="oAuthConfiguration">The <see cref="OAuthConfiguration"/> for the <see cref="BaseOAuthValidator"/>.</param>
 public TGForumsOAuthValidator(
     IHttpClientFactory httpClientFactory,
     IAssemblyInformationProvider assemblyInformationProvider,
     ILogger <TGForumsOAuthValidator> logger,
     OAuthConfiguration oAuthConfiguration)
     : base(
         httpClientFactory,
         assemblyInformationProvider,
         logger,
         oAuthConfiguration)
 {
     sessions = new List <Tuple <TGCreateSessionResponse, DateTimeOffset> >();
 }
 /// <summary>
 /// Construct a <see cref="DiscordProvider"/>
 /// </summary>
 /// <param name="assemblyInformationProvider">The value of <see cref="assemblyInformationProvider"/>.</param>
 /// <param name="logger">The value of <see cref="Logger"/></param>
 /// <param name="botToken">The value of <see cref="botToken"/></param>
 /// <param name="reconnectInterval">The initial reconnect interval in minutes.</param>
 public DiscordProvider(
     IAssemblyInformationProvider assemblyInformationProvider,
     ILogger <DiscordProvider> logger,
     string botToken,
     uint reconnectInterval)
     : base(logger, reconnectInterval)
 {
     this.assemblyInformationProvider = assemblyInformationProvider ?? throw new ArgumentNullException(nameof(assemblyInformationProvider));
     this.botToken           = botToken ?? throw new ArgumentNullException(nameof(botToken));
     client                  = new DiscordSocketClient();
     client.MessageReceived += Client_MessageReceived;
     mappedChannels          = new List <ulong>();
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandFactory"/> class.
 /// </summary>
 /// <param name="assemblyInformationProvider">The value of <see cref="assemblyInformationProvider"/>.</param>
 /// <param name="byondManager">The value of <see cref="byondManager"/>.</param>
 /// <param name="repositoryManager">The value of <see cref="repositoryManager"/>.</param>
 /// <param name="databaseContextFactory">The value of <see cref="databaseContextFactory"/>.</param>
 /// <param name="instance">The value of <see cref="instance"/>.</param>
 public CommandFactory(
     IAssemblyInformationProvider assemblyInformationProvider,
     IByondManager byondManager,
     IRepositoryManager repositoryManager,
     IDatabaseContextFactory databaseContextFactory,
     Models.Instance instance)
 {
     this.assemblyInformationProvider = assemblyInformationProvider ?? throw new ArgumentNullException(nameof(assemblyInformationProvider));
     this.byondManager           = byondManager ?? throw new ArgumentNullException(nameof(byondManager));
     this.repositoryManager      = repositoryManager ?? throw new ArgumentNullException(nameof(repositoryManager));
     this.databaseContextFactory = databaseContextFactory ?? throw new ArgumentNullException(nameof(databaseContextFactory));
     this.instance = instance ?? throw new ArgumentNullException(nameof(instance));
 }
Example #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InstanceFactory"/> class.
 /// </summary>
 /// <param name="ioManager">The value of <see cref="ioManager"/>.</param>
 /// <param name="databaseContextFactory">The value of <see cref="databaseContextFactory"/>.</param>
 /// <param name="assemblyInformationProvider">The value of <see cref="assemblyInformationProvider"/>.</param>
 /// <param name="loggerFactory">The value of <see cref="loggerFactory"/>.</param>
 /// <param name="topicClientFactory">The value of <see cref="topicClientFactory"/>.</param>
 /// <param name="cryptographySuite">The value of <see cref="cryptographySuite"/>.</param>
 /// <param name="synchronousIOManager">The value of <see cref="synchronousIOManager"/>.</param>
 /// <param name="symlinkFactory">The value of <see cref="symlinkFactory"/>.</param>
 /// <param name="byondInstaller">The value of <see cref="byondInstaller"/>.</param>
 /// <param name="chatFactory">The value of <see cref="chatFactory"/>.</param>
 /// <param name="processExecutor">The value of <see cref="processExecutor"/>.</param>
 /// <param name="postWriteHandler">The value of <see cref="postWriteHandler"/>.</param>
 /// <param name="watchdogFactory">The value of <see cref="watchdogFactory"/>.</param>
 /// <param name="jobManager">The value of <see cref="jobManager"/>.</param>
 /// <param name="networkPromptReaper">The value of <see cref="networkPromptReaper"/>.</param>
 /// <param name="platformIdentifier">The value of <see cref="platformIdentifier"/>.</param>
 /// <param name="repositoryFactory">The value of <see cref="repositoryFactory"/>.</param>
 /// <param name="repositoryCommands">The value of <see cref="repositoryCommands"/>.</param>
 /// <param name="serverPortProvider">The value of <see cref="serverPortProvider"/>.</param>
 /// <param name="fileTransferService">The value of <see cref="fileTransferService"/>.</param>
 /// <param name="gitRemoteFeaturesFactory">The value of <see cref="gitRemoteFeaturesFactory"/>.</param>
 /// <param name="remoteDeploymentManagerFactory">The value of <see cref="remoteDeploymentManagerFactory"/>.</param>
 /// <param name="generalConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="generalConfiguration"/>.</param>
 public InstanceFactory(
     IIOManager ioManager,
     IDatabaseContextFactory databaseContextFactory,
     IAssemblyInformationProvider assemblyInformationProvider,
     ILoggerFactory loggerFactory,
     ITopicClientFactory topicClientFactory,
     ICryptographySuite cryptographySuite,
     ISynchronousIOManager synchronousIOManager,
     ISymlinkFactory symlinkFactory,
     IByondInstaller byondInstaller,
     IChatManagerFactory chatFactory,
     IProcessExecutor processExecutor,
     IPostWriteHandler postWriteHandler,
     IWatchdogFactory watchdogFactory,
     IJobManager jobManager,
     INetworkPromptReaper networkPromptReaper,
     IPlatformIdentifier platformIdentifier,
     ILibGit2RepositoryFactory repositoryFactory,
     ILibGit2Commands repositoryCommands,
     IServerPortProvider serverPortProvider,
     IFileTransferTicketProvider fileTransferService,
     IGitRemoteFeaturesFactory gitRemoteFeaturesFactory,
     IRemoteDeploymentManagerFactory remoteDeploymentManagerFactory,
     IOptions <GeneralConfiguration> generalConfigurationOptions)
 {
     this.ioManager = ioManager ?? throw new ArgumentNullException(nameof(ioManager));
     this.databaseContextFactory      = databaseContextFactory ?? throw new ArgumentNullException(nameof(databaseContextFactory));
     this.assemblyInformationProvider = assemblyInformationProvider ?? throw new ArgumentNullException(nameof(assemblyInformationProvider));
     this.loggerFactory                  = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
     this.topicClientFactory             = topicClientFactory ?? throw new ArgumentNullException(nameof(topicClientFactory));
     this.cryptographySuite              = cryptographySuite ?? throw new ArgumentNullException(nameof(cryptographySuite));
     this.synchronousIOManager           = synchronousIOManager ?? throw new ArgumentNullException(nameof(synchronousIOManager));
     this.symlinkFactory                 = symlinkFactory ?? throw new ArgumentNullException(nameof(symlinkFactory));
     this.byondInstaller                 = byondInstaller ?? throw new ArgumentNullException(nameof(byondInstaller));
     this.chatFactory                    = chatFactory ?? throw new ArgumentNullException(nameof(chatFactory));
     this.processExecutor                = processExecutor ?? throw new ArgumentNullException(nameof(processExecutor));
     this.postWriteHandler               = postWriteHandler ?? throw new ArgumentNullException(nameof(postWriteHandler));
     this.watchdogFactory                = watchdogFactory ?? throw new ArgumentNullException(nameof(watchdogFactory));
     this.jobManager                     = jobManager ?? throw new ArgumentNullException(nameof(jobManager));
     this.networkPromptReaper            = networkPromptReaper ?? throw new ArgumentNullException(nameof(networkPromptReaper));
     this.platformIdentifier             = platformIdentifier ?? throw new ArgumentNullException(nameof(platformIdentifier));
     this.repositoryFactory              = repositoryFactory ?? throw new ArgumentNullException(nameof(repositoryFactory));
     this.repositoryCommands             = repositoryCommands ?? throw new ArgumentNullException(nameof(repositoryCommands));
     this.serverPortProvider             = serverPortProvider ?? throw new ArgumentNullException(nameof(serverPortProvider));
     this.fileTransferService            = fileTransferService ?? throw new ArgumentNullException(nameof(fileTransferService));
     this.gitRemoteFeaturesFactory       = gitRemoteFeaturesFactory ?? throw new ArgumentNullException(nameof(gitRemoteFeaturesFactory));
     this.remoteDeploymentManagerFactory = remoteDeploymentManagerFactory ?? throw new ArgumentNullException(nameof(remoteDeploymentManagerFactory));
     generalConfiguration                = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions));
 }
        /// <summary>
        /// Construct an <see cref="Application"/>
        /// </summary>
        /// <param name="configuration">The value of <see cref="configuration"/></param>
        /// <param name="assemblyInformationProvider">The <see cref="IAssemblyInformationProvider"/> for the <see cref="Application"/>.</param>
        /// <param name="hostingEnvironment">The value of <see cref="hostingEnvironment"/></param>
        /// <param name="ioManager">The value of <see cref="ioManager"/>.</param>
        public Application(
            IConfiguration configuration,
            IAssemblyInformationProvider assemblyInformationProvider,
            Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnvironment,
            IIOManager ioManager)
        {
            this.configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
            this.assemblyInformationProvider = assemblyInformationProvider ?? throw new ArgumentNullException(nameof(assemblyInformationProvider));
            this.hostingEnvironment          = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment));
            this.ioManager = ioManager ?? throw new ArgumentNullException(nameof(ioManager));

            startupTcs = new TaskCompletionSource <object>();

            Version       = assemblyInformationProvider.Name.Version;
            VersionString = String.Format(CultureInfo.InvariantCulture, "{0} v{1}", VersionPrefix, Version);
        }
        /// <summary>
        /// The <see cref="Task{TResult}"/> for <see cref="LaunchResult"/>.
        /// </summary>
        /// <param name="assemblyInformationProvider">The <see cref="IAssemblyInformationProvider"/>.</param>
        /// <param name="startupTimeout">The, optional, startup timeout in seconds.</param>
        /// <param name="reattached">If DreamDaemon was reattached.</param>
        /// <returns>A <see cref="Task{TResult}"/> resulting in the <see cref="Session.LaunchResult"/> for the operation.</returns>
        async Task <LaunchResult> GetLaunchResult(
            IAssemblyInformationProvider assemblyInformationProvider,
            uint?startupTimeout,
            bool reattached)
        {
            var  startTime = DateTimeOffset.Now;
            Task toAwait   = process.Startup;

            if (startupTimeout.HasValue)
            {
                toAwait = Task.WhenAny(process.Startup, Task.Delay(startTime.AddSeconds(startupTimeout.Value) - startTime));
            }

            await toAwait.ConfigureAwait(false);

            var result = new LaunchResult
            {
                ExitCode    = process.Lifetime.IsCompleted ? (int?)await process.Lifetime.ConfigureAwait(false) : null,
                StartupTime = process.Startup.IsCompleted ? (TimeSpan?)(DateTimeOffset.Now - startTime) : null
            };

            logger.LogTrace("Launch result: {0}", result);

            if (!result.ExitCode.HasValue && reattached && !disposed)
            {
                var reattachResponse = await SendCommand(
                    new TopicParameters(
                        assemblyInformationProvider.Version,
                        reattachInformation.RuntimeInformation.ServerPort),
                    reattachTopicCts.Token)
                                       .ConfigureAwait(false);

                if (reattachResponse.InteropResponse?.CustomCommands != null)
                {
                    chatTrackingContext.CustomCommands = reattachResponse.InteropResponse.CustomCommands;
                }
                else if (reattachResponse.InteropResponse != null)
                {
                    logger.LogWarning(
                        "DMAPI v{0} isn't returning the TGS custom commands list. Functionality added in v5.2.0.",
                        Dmb.CompileJob.DMApiVersion.Semver());
                }
            }

            return(result);
        }
Example #22
0
 /// <summary>
 /// Construct a <see cref="HomeController"/>
 /// </summary>
 /// <param name="databaseContext">The <see cref="IDatabaseContext"/> for the <see cref="ApiController"/></param>
 /// <param name="authenticationContextFactory">The <see cref="IAuthenticationContextFactory"/> for the <see cref="ApiController"/></param>
 /// <param name="tokenFactory">The value of <see cref="tokenFactory"/></param>
 /// <param name="systemIdentityFactory">The value of <see cref="systemIdentityFactory"/></param>
 /// <param name="cryptographySuite">The value of <see cref="cryptographySuite"/></param>
 /// <param name="assemblyInformationProvider">The value of <see cref="assemblyInformationProvider"/></param>
 /// <param name="identityCache">The value of <see cref="identityCache"/></param>
 /// <param name="browserResolver">The value of <see cref="browserResolver"/></param>
 /// <param name="generalConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="generalConfiguration"/>.</param>
 /// <param name="controlPanelConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="controlPanelConfiguration"/></param>
 /// <param name="logger">The <see cref="ILogger"/> for the <see cref="ApiController"/></param>
 public HomeController(
     IDatabaseContext databaseContext,
     IAuthenticationContextFactory authenticationContextFactory,
     ITokenFactory tokenFactory,
     ISystemIdentityFactory systemIdentityFactory,
     ICryptographySuite cryptographySuite,
     IAssemblyInformationProvider assemblyInformationProvider,
     IIdentityCache identityCache,
     IBrowserResolver browserResolver,
     IOptions <GeneralConfiguration> generalConfigurationOptions,
     IOptions <ControlPanelConfiguration> controlPanelConfigurationOptions,
     ILogger <HomeController> logger)
     : base(
         databaseContext,
         authenticationContextFactory,
         logger,
         (browserResolver ?? throw new ArgumentNullException(nameof(browserResolver))).Browser.Type != BrowserType.Generic &&
        /// <summary>
        /// Construct a <see cref="DiscordProvider"/>
        /// </summary>
        /// <param name="jobManager">The <see cref="IJobManager"/> for the <see cref="Provider"/>.</param>
        /// <param name="assemblyInformationProvider">The value of <see cref="assemblyInformationProvider"/>.</param>
        /// <param name="logger">The <see cref="ILogger"/> for the <see cref="Provider"/>.</param>
        /// <param name="chatBot">The <see cref="ChatBot"/> for the <see cref="Provider"/>.</param>
        public DiscordProvider(
            IJobManager jobManager,
            IAssemblyInformationProvider assemblyInformationProvider,
            ILogger <DiscordProvider> logger,
            Models.ChatBot chatBot)
            : base(jobManager, logger, chatBot)
        {
            this.assemblyInformationProvider = assemblyInformationProvider ?? throw new ArgumentNullException(nameof(assemblyInformationProvider));

            var csb = new DiscordConnectionStringBuilder(chatBot.ConnectionString);

            botToken          = csb.BotToken;
            basedMeme         = csb.BasedMeme;
            outputDisplayType = csb.DMOutputDisplay;

            client = new DiscordSocketClient();
            client.MessageReceived += Client_MessageReceived;
            mappedChannels          = new List <ulong>();
        }
Example #24
0
 /// <summary>
 /// Construct a <see cref="InstanceController"/>
 /// </summary>
 /// <param name="databaseContext">The <see cref="IDatabaseContext"/> for the <see cref="ApiController"/></param>
 /// <param name="authenticationContextFactory">The <see cref="IAuthenticationContextFactory"/> for the <see cref="ApiController"/></param>
 /// <param name="jobManager">The value of <see cref="jobManager"/></param>
 /// <param name="instanceManager">The value of <see cref="instanceManager"/></param>
 /// <param name="ioManager">The value of <see cref="ioManager"/></param>
 /// <param name="assemblyInformationProvider">The value of <see cref="assemblyInformationProvider"/></param>
 /// <param name="platformIdentifier">The value of <see cref="platformIdentifier"/></param>
 /// <param name="generalConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="generalConfiguration"/>.</param>
 /// <param name="logger">The <see cref="ILogger"/> for the <see cref="ApiController"/></param>
 public InstanceController(
     IDatabaseContext databaseContext,
     IAuthenticationContextFactory authenticationContextFactory,
     IJobManager jobManager,
     IInstanceManager instanceManager,
     IIOManager ioManager,
     IAssemblyInformationProvider assemblyInformationProvider,
     IPlatformIdentifier platformIdentifier,
     IOptions <GeneralConfiguration> generalConfigurationOptions,
     ILogger <InstanceController> logger)
     : base(databaseContext, authenticationContextFactory, logger, false, true)
 {
     this.jobManager                  = jobManager ?? throw new ArgumentNullException(nameof(jobManager));
     this.instanceManager             = instanceManager ?? throw new ArgumentNullException(nameof(instanceManager));
     this.ioManager                   = ioManager ?? throw new ArgumentNullException(nameof(ioManager));
     this.assemblyInformationProvider = assemblyInformationProvider ?? throw new ArgumentNullException(nameof(assemblyInformationProvider));
     this.platformIdentifier          = platformIdentifier ?? throw new ArgumentNullException(nameof(platformIdentifier));
     generalConfiguration             = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions));
 }
Example #25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RuntimeInformation"/> <see langword="class"/>.
 /// </summary>
 /// <param name="assemblyInformationProvider">The <see cref="IAssemblyInformationProvider"/> to use.</param>
 /// <param name="serverPortProvider">The <see cref="IServerPortProvider"/> used to set the value of <see cref="ServerPort"/>.</param>
 /// <param name="testMerges">An <see cref="IEnumerable{T}"/> used to construct the value of <see cref="TestMerges"/>.</param>
 /// <param name="chatChannels">The <see cref="Chat.ChannelRepresentation"/>s for the <see cref="ChatUpdate"/>.</param>
 /// <param name="instance">The <see cref="Instance"/> used to set <see cref="InstanceName"/>.</param>
 /// <param name="revision">The value of <see cref="RevisionInformation"/>.</param>
 /// <param name="securityLevel">The value of <see cref="SecurityLevel"/>.</param>
 /// <param name="apiValidateOnly">The value of <see cref="ApiValidateOnly"/>.</param>
 public RuntimeInformation(
     IAssemblyInformationProvider assemblyInformationProvider,
     IServerPortProvider serverPortProvider,
     IEnumerable <TestMergeInformation> testMerges,
     IEnumerable <Chat.ChannelRepresentation> chatChannels,
     Api.Models.Instance instance,
     Api.Models.Internal.RevisionInformation revision,
     DreamDaemonSecurity?securityLevel,
     bool apiValidateOnly)
     : base(chatChannels)
 {
     ServerVersion   = assemblyInformationProvider?.Version ?? throw new ArgumentNullException(nameof(assemblyInformationProvider));
     ServerPort      = serverPortProvider?.HttpApiPort ?? throw new ArgumentNullException(nameof(serverPortProvider));
     TestMerges      = testMerges?.ToList() ?? throw new ArgumentNullException(nameof(testMerges));
     InstanceName    = instance?.Name ?? throw new ArgumentNullException(nameof(instance));
     Revision        = revision ?? throw new ArgumentNullException(nameof(revision));
     SecurityLevel   = securityLevel;
     ApiValidateOnly = apiValidateOnly;
 }
Example #26
0
        /// <summary>
        /// Construct a <see cref="TokenFactory"/>
        /// </summary>
        /// <param name="asyncDelayer">The value of <see cref="asyncDelayer"/></param>
        /// <param name="cryptographySuite">The <see cref="ICryptographySuite"/> used for generating the <see cref="ValidationParameters"/></param>
        /// <param name="assemblyInformationProvider">The <see cref="IAssemblyInformationProvider"/> used to generate the issuer name.</param>
        /// <param name="securityConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="securityConfiguration"/>.</param>
        public TokenFactory(
            IAsyncDelayer asyncDelayer,
            ICryptographySuite cryptographySuite,
            IAssemblyInformationProvider assemblyInformationProvider,
            IOptions <SecurityConfiguration> securityConfigurationOptions)
        {
            this.asyncDelayer = asyncDelayer ?? throw new ArgumentNullException(nameof(asyncDelayer));

            if (cryptographySuite == null)
            {
                throw new ArgumentNullException(nameof(cryptographySuite));
            }
            if (assemblyInformationProvider == null)
            {
                throw new ArgumentNullException(nameof(assemblyInformationProvider));
            }

            securityConfiguration = securityConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(securityConfigurationOptions));

            var signingKeyBytes = String.IsNullOrWhiteSpace(securityConfiguration.CustomTokenSigningKeyBase64)
                                ? cryptographySuite.GetSecureBytes(securityConfiguration.TokenSigningKeyByteCount)
                                : Convert.FromBase64String(securityConfiguration.CustomTokenSigningKeyBase64);

            ValidationParameters = new TokenValidationParameters
            {
                ValidateIssuerSigningKey = true,
                IssuerSigningKey         = new SymmetricSecurityKey(signingKeyBytes),

                ValidateIssuer = true,
                ValidIssuer    = assemblyInformationProvider.AssemblyName.Name,

                ValidateLifetime = true,
                ValidateAudience = true,
                ValidAudience    = typeof(Token).Assembly.GetName().Name,

                ClockSkew = TimeSpan.FromMinutes(securityConfiguration.TokenClockSkewMinutes),

                RequireSignedTokens = true,

                RequireExpirationTime = true
            };
        }
Example #27
0
 /// <summary>
 /// Construct a <see cref="SetupWizard"/>
 /// </summary>
 /// <param name="ioManager">The value of <see cref="ioManager"/></param>
 /// <param name="console">The value of <see cref="console"/></param>
 /// <param name="hostingEnvironment">The value of <see cref="hostingEnvironment"/></param>
 /// <param name="assemblyInformationProvider">The value of <see cref="assemblyInformationProvider"/></param>
 /// <param name="dbConnectionFactory">The value of <see cref="dbConnectionFactory"/></param>
 /// <param name="platformIdentifier">The value of <see cref="platformIdentifier"/></param>
 /// <param name="asyncDelayer">The value of <see cref="asyncDelayer"/></param>
 /// <param name="applicationLifetime">The value of <see cref="applicationLifetime"/>.</param>
 /// <param name="generalConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="generalConfiguration"/></param>
 public SetupWizard(
     IIOManager ioManager,
     IConsole console,
     IHostEnvironment hostingEnvironment,
     IAssemblyInformationProvider assemblyInformationProvider,
     IDatabaseConnectionFactory dbConnectionFactory,
     IPlatformIdentifier platformIdentifier,
     IAsyncDelayer asyncDelayer,
     IHostApplicationLifetime applicationLifetime,
     IOptions <GeneralConfiguration> generalConfigurationOptions)
 {
     this.ioManager                   = ioManager ?? throw new ArgumentNullException(nameof(ioManager));
     this.console                     = console ?? throw new ArgumentNullException(nameof(console));
     this.hostingEnvironment          = hostingEnvironment ?? throw new ArgumentNullException(nameof(hostingEnvironment));
     this.assemblyInformationProvider = assemblyInformationProvider ?? throw new ArgumentNullException(nameof(assemblyInformationProvider));
     this.dbConnectionFactory         = dbConnectionFactory ?? throw new ArgumentNullException(nameof(dbConnectionFactory));
     this.platformIdentifier          = platformIdentifier ?? throw new ArgumentNullException(nameof(platformIdentifier));
     this.asyncDelayer                = asyncDelayer ?? throw new ArgumentNullException(nameof(asyncDelayer));
     this.applicationLifetime         = applicationLifetime ?? throw new ArgumentNullException(nameof(applicationLifetime));
     generalConfiguration             = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions));
 }
Example #28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="VersionCommand"/> class.
 /// </summary>
 /// <param name="assemblyInformationProvider">The value of <see cref="assemblyInformationProvider"/>.</param>
 public VersionCommand(IAssemblyInformationProvider assemblyInformationProvider)
 {
     this.assemblyInformationProvider = assemblyInformationProvider ?? throw new ArgumentNullException(nameof(assemblyInformationProvider));
 }
Example #29
0
        /// <summary>
        /// Add the X-Powered-By response header.
        /// </summary>
        /// <param name="applicationBuilder">The <see cref="IApplicationBuilder"/> to configure.</param>
        /// <param name="assemblyInformationProvider">The <see cref="IAssemblyInformationProvider"/> to use.</param>
        public static void UseServerBranding(this IApplicationBuilder applicationBuilder, IAssemblyInformationProvider assemblyInformationProvider)
        {
            if (applicationBuilder == null)
            {
                throw new ArgumentNullException(nameof(applicationBuilder));
            }
            if (assemblyInformationProvider == null)
            {
                throw new ArgumentNullException(nameof(assemblyInformationProvider));
            }

            applicationBuilder.Use(async(context, next) =>
            {
                context.Response.Headers.Add("X-Powered-By", assemblyInformationProvider.VersionPrefix);
                await next().ConfigureAwait(false);
            });
        }
Example #30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ServerFactory"/>.
 /// </summary>
 /// <param name="assemblyInformationProvider">The value of <see cref="assemblyInformationProvider"/>.</param>
 /// <param name="ioManager">The value of <see cref="ioManager"/>.</param>
 internal ServerFactory(IAssemblyInformationProvider assemblyInformationProvider, IIOManager ioManager)
 {
     this.assemblyInformationProvider = assemblyInformationProvider ?? throw new ArgumentNullException(nameof(assemblyInformationProvider));
     this.ioManager = ioManager ?? throw new ArgumentNullException(nameof(ioManager));
 }