Beispiel #1
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);
        }
Beispiel #2
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="platformIdentifier">The value of <see cref="platformIdentifier"/></param>
 /// <param name="portAllocator">The value of <see cref="IPortAllocator"/>.</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 <see cref="ILogger"/> for the <see cref="ApiController"/>.</param>
 public InstanceController(
     IDatabaseContext databaseContext,
     IAuthenticationContextFactory authenticationContextFactory,
     IJobManager jobManager,
     IInstanceManager instanceManager,
     IIOManager ioManager,
     IPortAllocator portAllocator,
     IPlatformIdentifier platformIdentifier,
     IOptions <GeneralConfiguration> generalConfigurationOptions,
     IOptions <SwarmConfiguration> swarmConfigurationOptions,
     ILogger <InstanceController> logger)
     : base(
         databaseContext,
         authenticationContextFactory,
         logger,
         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.platformIdentifier = platformIdentifier ?? throw new ArgumentNullException(nameof(platformIdentifier));
     this.portAllocator      = portAllocator ?? throw new ArgumentNullException(nameof(portAllocator));
     generalConfiguration    = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions));
     swarmConfiguration      = swarmConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(swarmConfigurationOptions));
 }
Beispiel #3
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;
 }
Beispiel #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AuthenticationContextFactory"/> class.
 /// </summary>
 /// <param name="databaseContext">The value of <see cref="databaseContext"/>.</param>
 /// <param name="identityCache">The value of <see cref="identityCache"/>.</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 AuthenticationContextFactory(
     IDatabaseContext databaseContext,
     IIdentityCache identityCache,
     IOptions <SwarmConfiguration> swarmConfigurationOptions,
     ILogger <AuthenticationContextFactory> logger)
 {
     this.databaseContext = databaseContext ?? throw new ArgumentNullException(nameof(databaseContext));
     this.identityCache   = identityCache ?? throw new ArgumentNullException(nameof(identityCache));
     swarmConfiguration   = swarmConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(swarmConfigurationOptions));
     this.logger          = logger ?? throw new ArgumentNullException(nameof(logger));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PortAllocator"/> class.
 /// </summary>
 /// <param name="serverPortProvider">The value of <see cref="serverPortProvider"/>.</param>
 /// <param name="databaseContext">The value of <see cref="databaseContext"/>.</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 PortAllocator(
     IServerPortProvider serverPortProvider,
     IDatabaseContext databaseContext,
     IOptions <SwarmConfiguration> swarmConfigurationOptions,
     ILogger <PortAllocator> logger)
 {
     this.serverPortProvider = serverPortProvider ?? throw new ArgumentNullException(nameof(serverPortProvider));
     this.databaseContext    = databaseContext ?? throw new ArgumentNullException(nameof(databaseContext));
     swarmConfiguration      = swarmConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(swarmConfigurationOptions));
     this.logger             = logger ?? throw new ArgumentNullException(nameof(logger));
 }
Beispiel #6
0
        public TestingServer(SwarmConfiguration swarmConfiguration, bool enableOAuth, ushort port = 5010)
        {
            Directory = Environment.GetEnvironmentVariable("TGS4_TEST_TEMP_DIRECTORY");
            if (String.IsNullOrWhiteSpace(Directory))
            {
                Directory = Path.Combine(Path.GetTempPath(), "TGS4_INTEGRATION_TEST");
                if (System.IO.Directory.Exists(Directory) && swarmConfiguration == null)
                {
                    try
                    {
                        System.IO.Directory.Delete(Directory, true);
                    }
                    catch { }
                }
            }

            Directory = Path.Combine(Directory, Guid.NewGuid().ToString());
            System.IO.Directory.CreateDirectory(Directory);
            string urlString = $"http://localhost:{port}";

            Url = new Uri(urlString);

            //so we need a db
            //we have to rely on env vars
            DatabaseType = Environment.GetEnvironmentVariable("TGS4_TEST_DATABASE_TYPE");
            var connectionString          = Environment.GetEnvironmentVariable("TGS4_TEST_CONNECTION_STRING");
            var gitHubAccessToken         = Environment.GetEnvironmentVariable("TGS4_TEST_GITHUB_TOKEN");
            var dumpOpenAPISpecPathEnvVar = Environment.GetEnvironmentVariable("TGS4_TEST_DUMP_API_SPEC");

            if (String.IsNullOrEmpty(DatabaseType))
            {
                Assert.Inconclusive("No database type configured in env var TGS4_TEST_DATABASE_TYPE!");
            }

            if (String.IsNullOrEmpty(connectionString))
            {
                Assert.Inconclusive("No connection string configured in env var TGS4_TEST_CONNECTION_STRING!");
            }

            if (String.IsNullOrEmpty(gitHubAccessToken))
            {
                Console.WriteLine("WARNING: No GitHub access token configured, test may fail due to rate limits!");
            }

            DumpOpenApiSpecpath = !String.IsNullOrEmpty(dumpOpenAPISpecPathEnvVar);

            var args = new List <string>()
            {
                String.Format(CultureInfo.InvariantCulture, "Database:DropDatabase={0}", true),
                String.Format(CultureInfo.InvariantCulture, "General:ApiPort={0}", port),
                String.Format(CultureInfo.InvariantCulture, "Database:DatabaseType={0}", DatabaseType),
                String.Format(CultureInfo.InvariantCulture, "Database:ConnectionString={0}", connectionString),
                String.Format(CultureInfo.InvariantCulture, "General:SetupWizardMode={0}", SetupWizardMode.Never),
                String.Format(CultureInfo.InvariantCulture, "General:MinimumPasswordLength={0}", 10),
                String.Format(CultureInfo.InvariantCulture, "General:InstanceLimit={0}", 11),
                String.Format(CultureInfo.InvariantCulture, "General:UserLimit={0}", 150),
                String.Format(CultureInfo.InvariantCulture, "General:UserGroupLimit={0}", 47),
                String.Format(CultureInfo.InvariantCulture, "General:HostApiDocumentation={0}", DumpOpenApiSpecpath),
                String.Format(CultureInfo.InvariantCulture, "FileLogging:Directory={0}", Path.Combine(Directory, "Logs")),
                String.Format(CultureInfo.InvariantCulture, "FileLogging:LogLevel={0}", "Trace"),
                String.Format(CultureInfo.InvariantCulture, "General:ValidInstancePaths:0={0}", Directory),
                "General:ByondTopicTimeout=3000"
            };

            if (swarmConfiguration != null)
            {
                args.Add($"Swarm:PrivateKey={swarmConfiguration.PrivateKey}");
                args.Add($"Swarm:Identifier={swarmConfiguration.Identifier}");
                args.Add($"Swarm:Address={swarmConfiguration.Address}");
                if (swarmConfiguration.ControllerAddress != null)
                {
                    args.Add($"Swarm:ControllerAddress={swarmConfiguration.ControllerAddress}");
                }
            }

            // enable all oauth providers
            if (enableOAuth)
            {
                foreach (var I in Enum.GetValues(typeof(OAuthProvider)))
                {
                    args.Add($"Security:OAuth:{I}:ClientId=Fake");
                    args.Add($"Security:OAuth:{I}:ClientSecret=Faker");
                    args.Add($"Security:OAuth:{I}:RedirectUrl=https://fakest.com");
                    args.Add($"Security:OAuth:{I}:ServerUrl=https://fakestest.com");
                }
            }
            else
            {
                args.Add($"Security:OAuth=null");
            }

            // SPECIFICALLY DELETE THE DEV APPSETTINGS, WE DON'T WANT IT IN THE WAY
            File.Delete("appsettings.Development.json");

            if (!String.IsNullOrEmpty(gitHubAccessToken))
            {
                args.Add(String.Format(CultureInfo.InvariantCulture, "General:GitHubAccessToken={0}", gitHubAccessToken));
            }

            if (DumpOpenApiSpecpath)
            {
                Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");
            }

            UpdatePath = Path.Combine(Directory, Guid.NewGuid().ToString());
            this.args  = args.ToArray();
        }