Esempio n. 1
0
        private static string ModifySimulatedPlayerLaunchJson(Options.CreateSimulated options)
        {
            var playerAuthServiceClient = ClientFactory.CreatePlayerAuthClient(options);

            // Create development authentication token used by the simulated players.
            var dat = playerAuthServiceClient.CreateDevelopmentAuthenticationToken(
                new CreateDevelopmentAuthenticationTokenRequest
            {
                Description = "DAT for sim worker deployment.",
                Lifetime    = Duration.FromTimeSpan(TimeSpan.FromDays(7)),
                ProjectName = options.ProjectName
            });

            // Add worker flags to sim deployment JSON.
            var devAuthTokenIdFlag = new JObject
            {
                { "name", $"{options.FlagPrefix}_simulated_players_dev_auth_token_id" },
                { "value", dat.TokenSecret }
            };

            var targetDeploymentFlag = new JObject
            {
                { "name", $"{options.FlagPrefix}_simulated_players_target_deployment" },
                { "value", options.TargetDeployment }
            };

            var launchConfigRaw = File.ReadAllText(options.LaunchJsonPath);

            // Dynamically traverse the JSON object. The '.' operator on the dynamic object corresponds to indexing
            // into the JSON fields. The alternative would be to write a model of the configuration file.
            dynamic launchConfig = JObject.Parse(launchConfigRaw);

            for (var i = 0; i < launchConfig.workers.Count; ++i)
            {
                if (launchConfig.workers[i].worker_type == options.SimulatedCoordinatorWorkerType)
                {
                    if (launchConfig.workers[i].flags == null)
                    {
                        launchConfig.workers[i].Add(new JProperty("flags"));
                    }

                    launchConfig.workers[i].flags.Add(devAuthTokenIdFlag);
                    launchConfig.workers[i].flags.Add(targetDeploymentFlag);
                }
            }

            return(launchConfig.ToString());
        }
Esempio n. 2
0
 public static int CreateSimulatedPlayerDeployment(Options.CreateSimulated options)
 {
     return(CreateDeploymentInternal(options, ModifySimulatedPlayerLaunchJson));
 }