Skip to content
This repository has been archived by the owner on Aug 28, 2021. It is now read-only.

Commit

Permalink
Merge pull request #3 from cmu-sei/feature/sddc
Browse files Browse the repository at this point in the history
Feature/sddc
  • Loading branch information
sei-jmattson authored Aug 21, 2020
2 parents b20520f + b8080c4 commit 0eb6bf2
Show file tree
Hide file tree
Showing 26 changed files with 643 additions and 175 deletions.
7 changes: 3 additions & 4 deletions src/TopoMojo.Abstractions/Interfaces/ITopoMojoClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Copyright 2020 Carnegie Mellon University.
// Released under a MIT (SEI) license. See LICENSE.md in the project root.
// Copyright 2020 Carnegie Mellon University.
// Released under a MIT (SEI) license. See LICENSE.md in the project root.

using System;
using System.Threading.Tasks;
Expand All @@ -9,14 +9,13 @@ namespace TopoMojo.Abstractions
{
public interface ITopoMojoClient
{
[Obsolete]
Task<string> Start(string problemId, GamespaceSpec workspace);
Task<GameState> Start(GamespaceSpec workspace);
Task Stop(string problemId);
Task<ConsoleSummary> Ticket(string vmId);
Task ChangeVm(VmAction vmAction);
Task BuildIso(IsoBuildSpec spec);
Task<string> Templates(int id);
Task<WorkspaceSummary[]> List(Search search);
}

}
8 changes: 6 additions & 2 deletions src/TopoMojo.Abstractions/Models/GamespaceSpec.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright 2020 Carnegie Mellon University.
// Released under a MIT (SEI) license. See LICENSE.md in the project root.
// Copyright 2020 Carnegie Mellon University.
// Released under a MIT (SEI) license. See LICENSE.md in the project root.

using System;

namespace TopoMojo.Models
{
Expand All @@ -12,7 +14,9 @@ public class NewGamespace
public class GamespaceSpec
{
public string IsolationId { get; set; }
[Obsolete]
public int WorkspaceId { get; set; }
public string WorkspaceGuid { get; set; }
public VmSpec[] Vms { get; set; } = new VmSpec[] {};
public bool CustomizeTemplates { get; set; }
public string Templates { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,21 @@ public class HypervisorServiceConfiguration {
public string VmStore { get; set; } = "[topomojo] _run/";
public string DiskStore { get; set; } = "[topomojo]";
public string IsoStore { get; set; } = "[topomojo] iso/";
public string ConsoleUrl { get; set; }
public string TicketUrlHandler { get; set; } = "querystring"; //"local-app", "external-domain", "host-map", "none"
public Dictionary<string,string> TicketUrlHostMap { get; set; } = new Dictionary<string, string>();
public VlanConfiguration Vlan { get; set; } = new VlanConfiguration();
public int KeepAliveMinutes { get; set; } = 10;
public string ExcludeNetworkMask { get; set; } = "topomojo";
public SddcConfiguration Sddc { get; set; } = new SddcConfiguration();
}

public class SddcConfiguration
{
public string Url { get; set; }
public string AuthUrl { get; set; }
public string OrgId { get; set; }
public string SddcId { get; set; }
public string ApiKey { get; set; }
}

public class VlanConfiguration
Expand Down
1 change: 1 addition & 0 deletions src/TopoMojo.Abstractions/Models/VmTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class VmNet
{
public int Id { get; set; }
public string Net { get; set; }
public string Key { get; set; }
public string Type { get; set; }
public string Mac { get; set; }
public string Ip { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/TopoMojo.Abstractions/TopoMojo.Abstractions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageId>TopoMojo.Abstractions</PackageId>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/cmu-sei/TopoMojo</RepositoryUrl>
<Version>1.3.1</Version>
<Version>1.3.3</Version>
</PropertyGroup>

</Project>
2 changes: 1 addition & 1 deletion src/TopoMojo.Client/TopoMojo.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<PackageId>TopoMojo.Client</PackageId>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryUrl>https://github.com/cmu-sei/TopoMojo</RepositoryUrl>
<Version>1.3.1</Version>
<Version>1.3.3</Version>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.1'">
Expand Down
48 changes: 1 addition & 47 deletions src/TopoMojo.Client/TopoMojoClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,9 @@ public async Task<GameState> Start(GamespaceSpec spec)
{
try
{
string mdText = "> Gamespace Resources: " + String.Join(" | ", game.Vms.Select(v => $"[{v.Name}](/console/{v.Id}/{v.Name}/{spec.IsolationId})"));

data = await Client.GetStringAsync(game.WorkspaceDocument);

mdText += "\n\n" + data;

game.Markdown = mdText;
game.Markdown = data;
}
catch
{
Expand All @@ -72,48 +68,6 @@ public async Task<GameState> Start(GamespaceSpec spec)
return game;
}

[Obsolete]
public async Task<string> Start(string isolationTag, GamespaceSpec spec)
{
string mdText = "";

var model = new NewGamespace
{
Id = isolationTag,
Workspace = spec
};

var result = await Client.PostAsync("gamespace", Json(model));

if (result.IsSuccessStatusCode)
{

string data = await result.Content.ReadAsStringAsync();

var game = JsonConvert.DeserializeObject<GameState>(data);

mdText = "> Gamespace Resources: " + String.Join(" | ", game.Vms.Select(v => $"[{v.Name}](/console/{v.Id}/{v.Name}/{isolationTag})"));

if (spec.AppendMarkdown)
{
try
{
data = await Client.GetStringAsync(game.WorkspaceDocument);

mdText += "\n\n" + data;
}
catch
{

}
}

}

return mdText;

}

public async Task Stop(string problemId)
{
await Client.DeleteAsync($"gamespace/{problemId}");
Expand Down
8 changes: 5 additions & 3 deletions src/TopoMojo.Core/Services/EngineService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ public async Task<GameState> Launch(GamespaceSpec spec)

if (game == null)
{
var workspace = await _workspaceStore.Load(spec.WorkspaceId);
var workspace = string.IsNullOrEmpty(spec.WorkspaceGuid)
? await _workspaceStore.Load(spec.WorkspaceId)
: await _workspaceStore.Load(spec.WorkspaceGuid);

if (workspace == null || !workspace.HasScope(Client.Scope))
{
_logger.LogInformation($"No audience match for workspace {spec?.WorkspaceId}: [{workspace?.Audience}] [{Client?.Scope}]");
_logger.LogInformation($"No audience match for workspace {spec?.WorkspaceGuid}: [{workspace?.Audience}] [{Client?.Scope}]");
throw new InvalidOperationException();
}

Expand Down Expand Up @@ -189,7 +191,7 @@ private void ApplyIso(ICollection<ConvergedTemplate> templates, GamespaceSpec sp
if (vmspec != null && vmspec.SkipIso)
continue;

template.Iso = $"{_pod.Options.IsoStore}/{_options.GameEngineIsoFolder}/{spec.Iso}";
template.Iso = $"{_options.GameEngineIsoFolder}/{spec.Iso}";
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/TopoMojo.Web/Controllers/VmController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,11 @@ public async Task<ActionResult<ConsoleSummary>> Ticket(string id)
{
case "querystring":
qs = $"?vmhost={src.Host}";
target = _pod.Options.ConsoleUrl;
target = _options.ConsoleHost;
break;

case "local-app":
target = $"{Request.Host.Value}/{internalHost}";
target = $"{Request.Host.Value}{Request.PathBase}/{internalHost}";
break;

case "external-domain":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ILogger<HeaderInspectionMiddleware> logger

public async Task Invoke(HttpContext context)
{
var sb = new StringBuilder($"Request Headers: {context.Request.Scheme}://{context.Request.Host} from {context.Connection.RemoteIpAddress}\n");
var sb = new StringBuilder($"Request Headers: {context.Request.Scheme}://{context.Request.Host}{context.Request.PathBase} from {context.Connection.RemoteIpAddress}\n");

sb.AppendLine($"\t{context.Request.Method} {context.Request.Path.Value} {context.Request.Protocol}");

Expand Down
8 changes: 7 additions & 1 deletion src/TopoMojo.Web/Infrastructure/JsonExceptionMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,23 @@
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using TopoMojo.Web;

namespace TopoMojo.Web
{
public class JsonExceptionMiddleware
{
public JsonExceptionMiddleware(
RequestDelegate next
RequestDelegate next,
ILogger<JsonExceptionMiddleware> logger
)
{
_next = next;
_logger = logger;
}
private readonly RequestDelegate _next;
private readonly ILogger _logger;

public async Task Invoke(HttpContext context)
{
Expand All @@ -27,6 +31,8 @@ public async Task Invoke(HttpContext context)
}
catch (Exception ex)
{
_logger.LogError(ex, "Error");

if (!context.Response.HasStarted)
{
context.Response.StatusCode = 500;
Expand Down
2 changes: 1 addition & 1 deletion src/TopoMojo.Web/Options/BrandingOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public class BrandingOptions
};

public bool IncludeSwagger { get; set; } = true;

public string PathBase { get; set; }
}
}
3 changes: 3 additions & 0 deletions src/TopoMojo.Web/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ public void Configure(IApplicationBuilder app)
{
app.UseJsonExceptions();

if (!string.IsNullOrEmpty(Branding.PathBase))
app.UsePathBase(Branding.PathBase);

if (Headers.LogHeaders)
app.UseHeaderInspection();

Expand Down
9 changes: 4 additions & 5 deletions src/TopoMojo.Web/appsettings.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
# Branding__Title = TopoMojo
# Branding__LogoUrl =

## If hosting in virtual directory, specify path base
# Branding__PathBase =

## Disable the Swagger OpenApi host by setting to false
# Branding__IncludeSwagger = true


####################
## Caching
####################
Expand Down Expand Up @@ -110,12 +112,9 @@ Authorization__SwaggerClient__ClientId = topomojo-swagger
## datastore path of workspace folders and template disks
# Pod__DiskStore =

## Url for console connections
# Pod__ConsoleUrl =

## TicketUrlHandler: console url transform method
## "none" : wss://<host>.<internal-domain>/ticket/123455
## "querystring" : wss://<consoleUrl>/ticket/123455?vmhost=<internalHost>
## "querystring" : wss://<Core.ConsoleHost>/ticket/123455?vmhost=<internalHost>
# Pod__TicketUrlHandler = querystring

## range of vlan id's available to topomojo; i.e. [200-399]
Expand Down
Loading

0 comments on commit 0eb6bf2

Please sign in to comment.