Skip to content

Commit

Permalink
Merge pull request #309 from microsoft/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
colbylwilliams authored Feb 3, 2022
2 parents 8e8fb04 + c4c71a9 commit 9b1294a
Show file tree
Hide file tree
Showing 42 changed files with 207 additions and 194 deletions.
16 changes: 14 additions & 2 deletions .github/workflows/deploy_demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v2
with:
token: ${{ secrets.TEAMCLOUD_PAT }}
fetch-depth: 0

- name: Resolve Tag
id: resolve-tag
uses: actions/github-script@v4
Expand Down Expand Up @@ -79,11 +85,14 @@ jobs:
- name: Reset Demo environment
if: github.event.inputs.reset_demo == 'true'
run: |
az group delete --subscription ${{ secrets.TEAMCLOUD_SUBSCRIPTION }} -n TeamCloud -y
while read SUBSCRIPTIONID; do
echo "Cleaning up subscripton '$( az account show --subscription $SUBSCRIPTIONID --query name -o tsv )'"
az util group delete --subscription $SUBSCRIPTIONID --prefix T --skip TeamCloud-Registry
az util group delete --subscription $SUBSCRIPTIONID --prefix T
az util keyvault purge --subscription $SUBSCRIPTIONID
done < <( az account list --refresh --only-show-errors --query "[?(starts_with(@.name, 'TeamCloud DEMO'))].id" -o tsv )
Expand All @@ -95,7 +104,10 @@ jobs:
az extension add -s ${{steps.get-cli.outputs.result}} -y
echo "deploying demo teamcloud instance"
az tc deploy --subscription ${{ secrets.TEAMCLOUD_SUBSCRIPTION }} -l eastus --principal-name ${{ secrets.TEAMCLOUD_RM_USERNAME }} --principal-password ${{ secrets.TEAMCLOUD_RM_PASSWORD }} --client-id ${{ secrets.TEAMCLOUD_WEB_USERNAME }} --scope ${{ secrets.TEAMCLOUD_WEB_SCOPE }} -v ${{steps.resolve-tag.outputs.result}} --skip-name-validation -n teamclouddemo
az tc deploy --subscription ${{ secrets.TEAMCLOUD_SUBSCRIPTION }} -l eastus --principal-name ${{ secrets.TEAMCLOUD_RM_USERNAME }} --principal-password ${{ secrets.TEAMCLOUD_RM_PASSWORD }} --client-id ${{ secrets.TEAMCLOUD_WEB_USERNAME }} --scope ${{ secrets.TEAMCLOUD_WEB_SCOPE }} -v ${{steps.resolve-tag.outputs.result}} --skip-name-validation ${{ github.event.inputs.reset_demo }} -n teamclouddemo
echo "adding webhooks to acr"
az deployment group create --subscription ${{ secrets.TEAMCLOUD_SUBSCRIPTION }} -g TeamCloud -f ./deploy/bicep/webhooks.bicep -p registrySubscriptionId=${{ secrets.TEAMCLOUD_ACR_SUBSCRIPTION }}
- name: Logout Azure CLI
if: ${{ always() }}
Expand Down
14 changes: 14 additions & 0 deletions deploy/bicep/appInsights.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ resource ai 'Microsoft.Insights/components@2020-02-02' = {
kind: 'web'
properties: {
Application_Type: 'web'
WorkspaceResourceId: workspace.id
}
}

resource workspace 'Microsoft.OperationalInsights/workspaces@2021-06-01' = {
name: name
location: resourceGroup().location
properties: {
sku: {
name: 'PerGB2018'
}
features: {
enableLogAccessUsingOnlyResourcePermissions: true
}
}
}

Expand Down
5 changes: 1 addition & 4 deletions deploy/bicep/webhooks.bicep
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
param registryName string = 'TeamCloud'
param registryResourceGroupName string = 'TeamCloud-Registry'
param registrySubscriptionId string = 'b6de8d3f-8477-45fe-8d60-f30c6db2cb06'
param registrySubscriptionId string

param apiAppName string = 'teamclouddemo-api'
param orchestratorAppName string = 'teamclouddemo-orchestrator'
param webAppName string = 'teamclouddemo'

// param resourceGroupName string = 'TeamCloud'
// param subscriptionId string = '12223725-70b0-45a6-96c4-a13c344fdc57'

resource api 'Microsoft.Web/sites@2021-02-01' existing = {
name: apiAppName
}
Expand Down
5 changes: 2 additions & 3 deletions scripts/get-url.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ def get_new_uri():
res = requests.get(tunnels_uri)
res_unicode = res.content.decode("utf-8")
res_json = json.loads(res_unicode)
public_url = res_json["tunnels"][0]["public_url"]
print(public_url)
return public_url
https_url = next((t['public_url'] for t in res_json["tunnels"] if t['public_url'].startswith('https')), None)
return https_url
except requests.exceptions.ConnectionError:
return None

Expand Down
16 changes: 8 additions & 8 deletions src/TeamCloud.API/Data/Results/ErrorResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public sealed class ErrorResult : IErrorResult
public IList<ResultError> Errors { get; set; }

public static ErrorResult BadRequest(List<ResultError> errors = null)
=> new ErrorResult { Code = StatusCodes.Status400BadRequest, Status = "BadRequest", Errors = errors };
=> new() { Code = StatusCodes.Status400BadRequest, Status = "BadRequest", Errors = errors };

public static ErrorResult BadRequest(string message, ResultErrorCode code)
=> BadRequest(new List<ResultError> { new ResultError { Code = code, Message = message } });
Expand All @@ -39,13 +39,13 @@ public static ErrorResult BadRequest(ValidationError validationError)
=> BadRequest(new List<ResultError> { ResultError.ValidationFailure(validationError) });

public static ErrorResult NotFound(string message)
=> new ErrorResult { Code = StatusCodes.Status404NotFound, Status = "NotFound", Errors = new List<ResultError> { ResultError.NotFound(message) } };
=> new() { Code = StatusCodes.Status404NotFound, Status = "NotFound", Errors = new List<ResultError> { ResultError.NotFound(message) } };

public static ErrorResult Conflict(string message)
=> new ErrorResult { Code = StatusCodes.Status409Conflict, Status = "Conflict", Errors = new List<ResultError> { ResultError.Conflict(message) } };
=> new() { Code = StatusCodes.Status409Conflict, Status = "Conflict", Errors = new List<ResultError> { ResultError.Conflict(message) } };

public static ErrorResult ServerError(IList<ResultError> errors = null)
=> new ErrorResult { Code = StatusCodes.Status500InternalServerError, Status = "ServerError", Errors = errors ?? new List<ResultError>() };
=> new() { Code = StatusCodes.Status500InternalServerError, Status = "ServerError", Errors = errors ?? new List<ResultError>() };

public static ErrorResult ServerError(Exception error)
=> error is null
Expand All @@ -62,14 +62,14 @@ public static ErrorResult ServerError(IList<Exception> errors)
}

public static ErrorResult ServerError(IList<CommandError> errors)
=> new ErrorResult { Code = StatusCodes.Status500InternalServerError, Status = "ServerError", Errors = errors?.Select(e => ResultError.Failed(e)).ToList() ?? new List<ResultError>() };
=> new() { Code = StatusCodes.Status500InternalServerError, Status = "ServerError", Errors = errors?.Select(e => ResultError.Failed(e)).ToList() ?? new List<ResultError>() };

public static ErrorResult Unauthorized()
=> new ErrorResult { Code = StatusCodes.Status401Unauthorized, Status = "Unauthorized", Errors = new List<ResultError> { ResultError.Unauthorized() } };
=> new() { Code = StatusCodes.Status401Unauthorized, Status = "Unauthorized", Errors = new List<ResultError> { ResultError.Unauthorized() } };

public static ErrorResult Forbidden()
=> new ErrorResult { Code = StatusCodes.Status403Forbidden, Status = "Forbidden", Errors = new List<ResultError> { ResultError.Forbidden() } };
=> new() { Code = StatusCodes.Status403Forbidden, Status = "Forbidden", Errors = new List<ResultError> { ResultError.Forbidden() } };

public static ErrorResult Unknown(int? code)
=> new ErrorResult { Code = code ?? StatusCodes.Status500InternalServerError, Status = "Unknown", Errors = new List<ResultError> { ResultError.Unknown() } };
=> new() { Code = code ?? StatusCodes.Status500InternalServerError, Status = "Unknown", Errors = new List<ResultError> { ResultError.Unknown() } };
}
17 changes: 0 additions & 17 deletions src/TeamCloud.API/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Security.Claims;
Expand All @@ -15,7 +14,6 @@
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Newtonsoft.Json;
using TeamCloud.API.Data.Results;
using TeamCloud.API.Initialization;
using TeamCloud.API.Services;
Expand Down Expand Up @@ -139,21 +137,6 @@ public static string GetTenantId(this ClaimsPrincipal claimsPrincipal)
return tenantId;
}

// TODO: Update to use teamcloud serializer
public static Task<T> ReadAsAsync<T>(this HttpContent httpContent, JsonSerializerSettings serializerSettings = null)
=> httpContent.ReadAsAsync<T>(JsonSerializer.CreateDefault(serializerSettings));

public static async Task<T> ReadAsAsync<T>(this HttpContent httpContent, JsonSerializer serializer)
{
using var stream = await httpContent.ReadAsStreamAsync().ConfigureAwait(false);
using var streamReader = new StreamReader(stream);
using var jsonReader = new JsonTextReader(streamReader);

return serializer.Deserialize<T>(jsonReader);
}



public static bool IsUserIdentifier(this string identifier)
=> !string.IsNullOrWhiteSpace(identifier);

Expand Down
19 changes: 11 additions & 8 deletions src/TeamCloud.API/Services/OrchestratorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Flurl;
using Flurl.Http;
using Microsoft.AspNetCore.Http;
using TeamCloud.Http;
using TeamCloud.Model.Commands.Core;
using TeamCloud.Validation;
using TeamCloud.Validation.Providers;
Expand Down Expand Up @@ -42,17 +43,18 @@ public async Task<ICommandResult> QueryAsync(Guid commandId, string projectId)
.AppendPathSegment($"api/command/{commandId}")
.WithHeader("x-functions-key", options.AuthCode)
.AllowHttpStatus(HttpStatusCode.NotFound)
.UseTeamCloudSerializer()
.GetAsync()
.ConfigureAwait(false);

if (commandResponse.StatusCode == HttpStatusCode.NotFound)
if (commandResponse.StatusCode == StatusCodes.Status404NotFound)
return null;

var commandResult = await commandResponse.Content
.ReadAsAsync<ICommandResult>()
var commandResult = await commandResponse
.GetJsonAsync<ICommandResult>()
.ConfigureAwait(false);

commandResult.SetResultLinks(httpContextAccessor, commandResponse, projectId);
commandResult.SetResultLinks(httpContextAccessor, commandResponse.ResponseMessage, projectId);

return commandResult;
}
Expand All @@ -76,21 +78,22 @@ public async Task<ICommandResult> InvokeAsync(ICommand command)
var commandResponse = await options.Url
.AppendPathSegment("api/command")
.WithHeader("x-functions-key", options.AuthCode)
.UseTeamCloudSerializer()
.PostJsonAsync(command)
.ConfigureAwait(false);

commandResult = await commandResponse.Content
.ReadAsAsync<ICommandResult>()
commandResult = await commandResponse
.GetJsonAsync<ICommandResult>()
.ConfigureAwait(false);

commandResult.SetResultLinks(httpContextAccessor, commandResponse, command.ProjectId);
commandResult.SetResultLinks(httpContextAccessor, commandResponse.ResponseMessage, command.ProjectId);
}
catch (FlurlHttpTimeoutException timeoutExc)
{
commandResult ??= command.CreateResult();
commandResult.Errors.Add(timeoutExc);
}
catch (FlurlHttpException serviceUnavailableExc) when (serviceUnavailableExc.Call.HttpStatus == HttpStatusCode.ServiceUnavailable)
catch (FlurlHttpException serviceUnavailableExc) when (serviceUnavailableExc.StatusCode == StatusCodes.Status503ServiceUnavailable)
{
commandResult ??= command.CreateResult();
commandResult.Errors.Add(serviceUnavailableExc);
Expand Down
10 changes: 5 additions & 5 deletions src/TeamCloud.API/TeamCloud.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PackageReference Include="Azure.Extensions.AspNetCore.DataProtection.Keys" Version="1.1.0" />
<PackageReference Include="FluentValidation" Version="9.2.2" />
<PackageReference Include="FluentValidation.AspNetCore" Version="9.2.0" />
<PackageReference Include="Flurl.Http" Version="2.4.2" />
<PackageReference Include="Flurl.Http" Version="3.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.WebApiCompatShim" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json.Schema" Version="3.0.14" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.20.0" />
Expand All @@ -35,12 +35,12 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="6.2.3" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.2.3" />
<PackageReference Include="System.Interactive.Async" Version="5.1.0" />
<PackageReference Include="System.Linq.Async" Version="5.1.0" />
<PackageReference Include="System.Interactive.Async" Version="6.0.1" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
<PackageReference Include="Microsoft.Azure.SignalR" Version="1.15.0" />
<PackageReference Include="Microsoft.Azure.SignalR.Management" Version="1.15.0" />
<PackageReference Include="Microsoft.Identity.Web" Version="1.22.1" />
<PackageReference Include="Microsoft.Identity.Web.UI" Version="1.22.1" />
<PackageReference Include="Microsoft.Identity.Web" Version="1.22.2" />
<PackageReference Include="Microsoft.Identity.Web.UI" Version="1.22.2" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit 9b1294a

Please sign in to comment.