public async Task <IActionResult> Create([FromBody] ExerciseAgent exerciseAgent, CancellationToken ct) { if (exerciseAgent.Id == Guid.Empty) { exerciseAgent.Id = Guid.NewGuid(); } var createdExerciseAgent = await _ExerciseAgentService.CreateAsync(exerciseAgent, ct); return(CreatedAtAction(nameof(this.Get), new { id = createdExerciseAgent.VmWareUuid }, createdExerciseAgent)); }
public async Task <ExerciseAgent> DeleteAsync(Guid id, CancellationToken ct) { if (!(await _authorizationService.AuthorizeAsync(_user, null, new ContentDeveloperRequirement())).Succeeded) { throw new ForbiddenException(); } var deletedExerciseAgent = new ExerciseAgent(); _exerciseAgentStore.ExerciseAgents.Remove(id, out deletedExerciseAgent); return(deletedExerciseAgent); }
private static void DoPost(ClientConfiguration.ReporterOptions config, ExerciseAgent exerciseAgent) { //call home var client = new RestClient(config.PostUrl); var request = new RestRequest(Method.POST) { RequestFormat = DataFormat.Json }; request.AddJsonBody(exerciseAgent); var response = client.Execute(request); _log.Info($"Post response {response.StatusCode}: {response.Content}"); // is there a need for a return here? // return JsonConvert.DeserializeObject<Catalog>(dataString); }
public async Task <ExerciseAgent> UpdateAsync(Guid id, ExerciseAgent exerciseAgent, CancellationToken ct) { if (!(await _authorizationService.AuthorizeAsync(_user, null, new ContentDeveloperRequirement())).Succeeded) { throw new ForbiddenException(); } var exerciseAgentToUpdate = _exerciseAgentStore.ExerciseAgents[id]; if (exerciseAgentToUpdate == null) { throw new EntityNotFoundException <ExerciseAgent>(); } if (!exerciseAgent.CheckinTime.HasValue) { exerciseAgent.CheckinTime = DateTime.UtcNow; } _exerciseAgentStore.ExerciseAgents[id] = exerciseAgent; return(exerciseAgent); }
/// <summary> /// Build the MachineSurvey information /// </summary> /// <returns>MachineSurvey</returns> internal static ExerciseAgent Build() { var exerciseAgent = new ExerciseAgent { MonitoredTools = GetMonitoredTools(), LocalUsers = LoadLocalUsers(), OperatingSystem = new OS(Environment.OSVersion), AgentName = ApplicationDetails.Name, AgentVersion = ApplicationDetails.Version, AgentInstalledPath = ApplicationDetails.InstalledPath, MachineName = Environment.MachineName, FQDN = Dns.GetHostName(), GuestIp = GetLocalIpAddress() }; //machineSurvey.Id = exerciseAgent.VmWareUuid = GetGuestInfoVar(exerciseAgent); exerciseAgent.SshPorts = BondManager.CurrentPorts; return(exerciseAgent); }
public async Task <ExerciseAgent> CreateAsync(ExerciseAgent exerciseAgent, CancellationToken ct) { if (!(await _authorizationService.AuthorizeAsync(_user, null, new ContentDeveloperRequirement())).Succeeded) { throw new ForbiddenException(); } //TODO: add permissions // var ExerciseAgentAdminPermission = await _context.Permissions // .Where(p => p.Key == PlayerClaimTypes.ExerciseAgentAdmin.ToString()) // .FirstOrDefaultAsync(); // if (ExerciseAgentAdminPermission == null) // throw new EntityNotFoundException<Permission>($"{PlayerClaimTypes.ExerciseAgentAdmin.ToString()} Permission not found."); // end of TODO: if (!exerciseAgent.CheckinTime.HasValue) { exerciseAgent.CheckinTime = DateTime.UtcNow; } _exerciseAgentStore.ExerciseAgents[exerciseAgent.VmWareUuid] = exerciseAgent; return(exerciseAgent); }
/// <summary> /// if configured, try to set machine.name based on some vmtools.exe guestinfovars value /// </summary> /// <param name="exerciseAgent">The guestinfovars value</param> private static Guid GetGuestInfoVar(ExerciseAgent exerciseAgent) { try { if (BondManager.Configuration.VmTools.IsEnabled) { var p = new Process { StartInfo = { UseShellExecute = false, RedirectStandardOutput = true, FileName = $"{BondManager.Configuration.VmTools.VmWareToolsLocation}", Arguments = $"--cmd \"info-get {BondManager.Configuration.VmTools.IdFormatKey}\"" } }; p.Start(); var output = p.StandardOutput.ReadToEnd().Trim(); p.WaitForExit(); if (!string.IsNullOrEmpty(output)) { var o = BondManager.Configuration.VmTools.IdFormatValue; o = o.Replace("[formatkeyvalue]", output); o = o.Replace("[machinename]", exerciseAgent.MachineName); return(Guid.Parse(o)); } } } catch (Exception e) { _log.Error(e); } return(Guid.Empty); }
public IActionResult Post(ExerciseAgent model) { _timelineLog.Info($"MACHINE|{DateTime.Now}|{JsonConvert.SerializeObject(model)}"); return(Ok("OK")); }
public async Task <IActionResult> Update([FromRoute] Guid id, [FromBody] ExerciseAgent ExerciseAgent, CancellationToken ct) { var updatedExerciseAgent = await _ExerciseAgentService.UpdateAsync(id, ExerciseAgent, ct); return(Ok(updatedExerciseAgent)); }