Skip to content

Commit

Permalink
Merge pull request #298 from cmu-sei/v8
Browse files Browse the repository at this point in the history
changes machineupdateview to use a pregenerated example and not the s…
  • Loading branch information
sei-dupdyke authored Mar 23, 2024
2 parents 0850088 + fe562bb commit ac52034
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Ghosts.Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Ghosts.Api.Infrastructure.Data;
using Ghosts.Api.Infrastructure.Extensions;
using ghosts.api.Infrastructure.Services;
using Ghosts.Api.ViewModels;
using Ghosts.Domain.Code;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
Expand All @@ -20,7 +21,6 @@
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models;
using Npgsql;
using Swashbuckle.AspNetCore.Filters;

namespace Ghosts.Api
Expand Down Expand Up @@ -70,6 +70,8 @@ public void ConfigureServices(IServiceCollection services)
c.ExampleFilters();
});
services.AddSwaggerExamplesFromAssemblies(Assembly.GetEntryAssembly());
services.AddSwaggerExamplesFromAssemblyOf<MachineUpdateViewModelExample>();


// Add application services.
services.AddScoped<IMachineService, MachineService>();
Expand Down
42 changes: 42 additions & 0 deletions src/Ghosts.Api/ViewModels/MachineUpdateViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Copyright 2017 Carnegie Mellon University. All Rights Reserved. See LICENSE.md file for terms.

using System;
using System.Collections.Generic;
using ghosts.api.Infrastructure.Models;
using Ghosts.Domain;
using Newtonsoft.Json;
using Swashbuckle.AspNetCore.Filters;

namespace Ghosts.Api.ViewModels
{
Expand Down Expand Up @@ -33,4 +35,44 @@ public MachineUpdate ToMachineUpdate()
return machineUpdate;
}
}

public class MachineUpdateViewModelExample : IExamplesProvider<MachineUpdateViewModel>
{
public MachineUpdateViewModel GetExamples()
{
return new MachineUpdateViewModel
{
MachineId = Guid.NewGuid(),
Type = UpdateClientConfig.UpdateType.TimelinePartial,
ActiveUtc = DateTime.UtcNow,
Status = StatusType.Active,
Update = new Timeline
{
Id = Guid.NewGuid(),
Status = Timeline.TimelineStatus.Run,
TimeLineHandlers = new List<TimelineHandler>
{
new TimelineHandler
{
HandlerType = HandlerType.BrowserFirefox,
Initial = "https://cmu.edu",
UtcTimeOn = TimeSpan.FromHours(0),
UtcTimeOff = TimeSpan.FromHours(24),
Loop = true,
TimeLineEvents = new List<TimelineEvent>
{
new TimelineEvent
{
Command = "Navigate",
CommandArgs = new List<object> { "https://sei.cmu.edu" },
DelayAfter = 30000,
DelayBefore = 0
}
}
}
}
}
};
}
}
}
4 changes: 2 additions & 2 deletions src/Ghosts.Api/ghosts.api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<AssemblyName>ghosts.api</AssemblyName>

<AssemblyVersion>8.0.0.0</AssemblyVersion>
<FileVersion>8.0.7.0</FileVersion>
<FileVersion>8.0.7.25</FileVersion>

<Authors>Dustin Updyke for CERT > Software Engineering Institute > Carnegie Mellon University</Authors>
<Authors>GHOSTS Development Squad for CERT > Software Engineering Institute > Carnegie Mellon University</Authors>
<Company>Carnegie Mellon University</Company>
<Product>GHOSTS</Product>
<Description>GHOSTS NPC Platform - please email ddupdyke[-at-]sei.cmu.edu with bugs/requests/other</Description>
Expand Down

0 comments on commit ac52034

Please sign in to comment.