Skip to content

Commit

Permalink
Merge pull request #39 from cmu-sei/8.7.2020
Browse files Browse the repository at this point in the history
Update 8.7.2020
  • Loading branch information
sei-ebram authored Aug 7, 2020
2 parents 54465b4 + bfaee47 commit b2d106e
Show file tree
Hide file tree
Showing 46 changed files with 2,053 additions and 167 deletions.
12 changes: 11 additions & 1 deletion caster.api/src/Caster.Api/Domain/Services/TerraformService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class TerraformService : ITerraformService
private readonly TerraformOptions _options;
private readonly ILogger<TerraformService> _logger;
private StringBuilder _outputBuilder = new StringBuilder();
private string _workspaceName = null;

public TerraformService(TerraformOptions options, ILogger<TerraformService> logger)
{
Expand All @@ -62,11 +63,16 @@ private TerraformResult Run(string workingDirectory, IEnumerable<string> argumen

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = _options.BinaryPath;
startInfo.EnvironmentVariables.Add("TF_IN_AUTOMATION", "true");
startInfo.WorkingDirectory = workingDirectory;
startInfo.CreateNoWindow = true;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = redirectStandardError;
startInfo.EnvironmentVariables.Add("TF_IN_AUTOMATION", "true");

if (!string.IsNullOrEmpty(_workspaceName))
{
startInfo.EnvironmentVariables.Add("TF_WORKSPACE", _workspaceName);
}

using (Process process = new Process())
{
Expand Down Expand Up @@ -123,7 +129,11 @@ private void OutputHandler(object sender, DataReceivedEventArgs e)
/// </summary>
public TerraformResult InitializeWorkspace(string workingDirectory, string workspaceName, bool defaultWorkspace, DataReceivedEventHandler outputHandler)
{
// Set TF_WORKSPACE env var for init to workaround bug with an empty configuration
// Will need to avoid this for a remote state init
_workspaceName = workspaceName;
var result = this.Init(workingDirectory, outputHandler);
_workspaceName = null;

if (!result.IsError)
{
Expand Down
19 changes: 19 additions & 0 deletions player.api/S3.Player.Api/Controllers/RoleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,25 @@ public async Task<IActionResult> Get(Guid id)
return Ok(Role);
}

/// <summary>
/// Gets a specific Role by name
/// </summary>
/// <remarks>
/// Returns the Role with the name specified
/// <para />
/// Accessible to all authenticated Users
/// </remarks>
/// <param name="name">The name of the Role</param>
/// <returns></returns>
[HttpGet("Roles/name/{name}")]
[ProducesResponseType(typeof(Role), (int)HttpStatusCode.OK)]
[SwaggerOperation(operationId: "getRoleByName")]
public async Task<IActionResult> Get(string name)
{
var role = await _RoleService.GetAsync(name);
return Ok(role);
}

/// <summary>
/// Creates a new Role
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion player.api/S3.Player.Api/Controllers/ViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public async Task<IActionResult> Get(Guid id, CancellationToken ct)
[HttpPost("views")]
[ProducesResponseType(typeof(View), (int)HttpStatusCode.Created)]
[SwaggerOperation(operationId: "createView")]
public async Task<IActionResult> Create([FromBody] View view, CancellationToken ct)
public async Task<IActionResult> Create([FromBody] ViewForm view, CancellationToken ct)
{
var createdView = await _viewService.CreateAsync(view, ct);
return CreatedAtAction(nameof(this.Get), new { id = createdView.Id }, createdView);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public ViewProfile()
.ForMember(dest => dest.CanManage, opt => opt.ResolveUsing<ManageViewResolver>());

CreateMap<View, ViewEntity>();

CreateMap<ViewForm, ViewEntity>();
}
}

Expand Down
15 changes: 15 additions & 0 deletions player.api/S3.Player.Api/Services/RoleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public interface IRoleService
{
Task<IEnumerable<Role>> GetAsync();
Task<Role> GetAsync(Guid id);
Task<Role> GetAsync(string name);
Task<Role> CreateAsync(RoleForm form);
Task<Role> UpdateAsync(Guid id, RoleForm form);
Task<bool> DeleteAsync(Guid id);
Expand Down Expand Up @@ -72,6 +73,20 @@ public async Task<Role> GetAsync(Guid id)
return item;
}

public async Task<Role> GetAsync(string name)
{
var item = await _context.Roles
.ProjectTo<Role>()
.SingleOrDefaultAsync(o => o.Name == name);

if (item == null)
{
throw new EntityNotFoundException<Role>();
}

return item;
}

public async Task<Role> CreateAsync(RoleForm form)
{
if (!(await _authorizationService.AuthorizeAsync(_user, null, new FullRightsRequirement())).Succeeded)
Expand Down
33 changes: 22 additions & 11 deletions player.api/S3.Player.Api/Services/ViewService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public interface IViewService
Task<IEnumerable<ViewModels.View>> GetAsync(CancellationToken ct);
Task<ViewModels.View> GetAsync(Guid id, CancellationToken ct);
Task<IEnumerable<ViewModels.View>> GetByUserIdAsync(Guid userId, CancellationToken ct);
Task<ViewModels.View> CreateAsync(ViewModels.View view, CancellationToken ct);
Task<ViewModels.View> CreateAsync(ViewModels.ViewForm view, CancellationToken ct);
Task<View> CloneAsync(Guid id, CancellationToken ct);
Task<ViewModels.View> UpdateAsync(Guid id, ViewModels.View view, CancellationToken ct);
Task<bool> DeleteAsync(Guid id, CancellationToken ct);
Expand Down Expand Up @@ -97,7 +97,7 @@ public ViewService(PlayerContext context, IAuthorizationService authorizationSer
return _mapper.Map<IEnumerable<ViewModels.View>>(views);
}

public async Task<ViewModels.View> CreateAsync(ViewModels.View view, CancellationToken ct)
public async Task<ViewModels.View> CreateAsync(ViewModels.ViewForm view, CancellationToken ct)
{
if (!(await _authorizationService.AuthorizeAsync(_user, null, new ViewCreationRequirement())).Succeeded)
throw new ForbiddenException();
Expand All @@ -113,21 +113,32 @@ public ViewService(PlayerContext context, IAuthorizationService authorizationSer

var userId = _user.GetId();

TeamEntity teamEntity = null;
ViewMembershipEntity viewMembershipEntity = null;
// Create an Admin team with the caller as a member
var teamEntity = new TeamEntity() { Name = "Admin" };
teamEntity.Permissions.Add(new TeamPermissionEntity() { Permission = viewAdminPermission });
if (view.CreateAdminTeam)
{
teamEntity = new TeamEntity() { Name = "Admin" };
teamEntity.Permissions.Add(new TeamPermissionEntity() { Permission = viewAdminPermission });

viewMembershipEntity = new ViewMembershipEntity { View = viewEntity, UserId = userId };
viewEntity.Teams.Add(teamEntity);
viewEntity.Memberships.Add(viewMembershipEntity);

var viewMembershipEntity = new ViewMembershipEntity { View = viewEntity, UserId = userId };
viewEntity.Teams.Add(teamEntity);
viewEntity.Memberships.Add(viewMembershipEntity);
}

_context.Views.Add(viewEntity);
await _context.SaveChangesAsync(ct);

if (view.CreateAdminTeam)
{
var teamMembershipEntity = new TeamMembershipEntity { Team = teamEntity, UserId = userId, ViewMembership = viewMembershipEntity };
viewMembershipEntity.PrimaryTeamMembership = teamMembershipEntity;
_context.TeamMemberships.Add(teamMembershipEntity);
_context.ViewMemberships.Update(viewMembershipEntity);
await _context.SaveChangesAsync(ct);
}

var teamMembershipEntity = new TeamMembershipEntity { Team = teamEntity, UserId = userId, ViewMembership = viewMembershipEntity };
viewMembershipEntity.PrimaryTeamMembership = teamMembershipEntity;
_context.TeamMemberships.Add(teamMembershipEntity);
_context.ViewMemberships.Update(viewMembershipEntity);
await _context.SaveChangesAsync(ct);

return await GetAsync(viewEntity.Id, ct);
Expand Down
24 changes: 24 additions & 0 deletions player.api/S3.Player.Api/ViewModels/ViewForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
Crucible
Copyright 2020 Carnegie Mellon University.
NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT.
Released under a MIT (SEI)-style license, please see license.txt or contact [email protected] for full terms.
[DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution.
Carnegie Mellon(R) and CERT(R) are registered in the U.S. Patent and Trademark Office by Carnegie Mellon University.
DM20-0181
*/

using S3.Player.Api.Data.Data.Models;
using System;

namespace S3.Player.Api.ViewModels
{
public class ViewForm
{
public Guid Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public ViewStatus Status { get; set; }
public bool CreateAdminTeam { get; set; } = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<div fxLayout="row" fxLayoutAlign="end" class="top-button">
<button
[hidden]="viewApplications === undefined || viewApplications.length === 0"
*ngIf="viewApplications != null && viewApplications.length > 0"
mat-stroked-button
[matMenuTriggerFor]="teamAppsMenu"
>
Expand Down Expand Up @@ -56,7 +56,9 @@
<div fxflex fxLayoutAlign="space-between center">
Display order:&nbsp;&nbsp;<b>{{ app.displayOrder }}</b>
<button
[hidden]="app.displayOrder === 0"
*ngIf="{ disabled: app.displayOrder === 0 } as moveUp"
[disabled]="moveUp.disabled"
[ngClass]="moveUp.disabled ? 'disabled-button' : null"
mat-icon-button
title="Move Up"
(click)="swapDisplayOrders(app, applications[i - 1])"
Expand All @@ -67,43 +69,20 @@
></mat-icon>
</button>
<button
[hidden]="app.displayOrder > 0"
mat-icon-button
title="Move Up"
style="opacity: 0.3; filter: alpha(opacity=30);"
>
<mat-icon
svgIcon="ic_expand_more_black_24px"
style="transform: rotate(180deg);"
></mat-icon>
</button>
<button
[hidden]="app.displayOrder >= applications.length - 1"
*ngIf="{
disabled: app.displayOrder >= applications.length - 1
} as moveDown"
[disabled]="moveDown.disabled"
[ngClass]="moveDown.disabled ? 'disabled-button' : null"
title="Move Down"
mat-icon-button
(click)="swapDisplayOrders(app, applications[i + 1])"
>
<mat-icon svgIcon="ic_expand_more_black_24px"></mat-icon>
</button>
<button
[hidden]="app.displayOrder < applications.length - 1"
title="Move Down"
mat-icon-button
style="opacity: 0.3; filter: alpha(opacity=30);"
>
<mat-icon svgIcon="ic_expand_more_black_24px"></mat-icon>
</button>
</div>
<div fxFlex fxLayoutAlign="end">
<button
[hidden]="subjectType !== objTypes.View"
mat-stroked-button
(click)="deleteViewApplication(app)"
>
Delete Application
</button>
<button
[hidden]="subjectType !== objTypes.Team"
mat-stroked-button
(click)="removeApplicationInstanceFromTeam(app)"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ DM20-0181
.top-button {
margin-bottom: 10px;
}

.disabled-button {
opacity: 0.3;
filter: alpha(opacity=30);
}
1 change: 0 additions & 1 deletion steamfitter.api/Steamfitter.Api.Data/Models/Result.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public void Configure(EntityTypeBuilder<ResultEntity> builder)
builder
.HasOne(w => w.Task)
.WithMany(d => d.Results)
.IsRequired()
.OnDelete(DeleteBehavior.SetNull);
}
}
Expand Down
2 changes: 1 addition & 1 deletion steamfitter.api/Steamfitter.Api.Data/Models/Scenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void Configure(EntityTypeBuilder<ScenarioEntity> builder)
builder
.HasOne(d => d.ScenarioTemplate)
.WithMany(d => d.Scenarios)
.OnDelete(DeleteBehavior.ClientSetNull);
.OnDelete(DeleteBehavior.SetNull);
}
}

Expand Down
Loading

0 comments on commit b2d106e

Please sign in to comment.