-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #239 from microsoft/dev
integrate minor changes +resetdemo
- Loading branch information
Showing
14 changed files
with
409 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
using TeamCloud.Model.Commands.Core; | ||
using TeamCloud.Model.Data; | ||
|
||
namespace TeamCloud.Model.Commands | ||
{ | ||
public sealed class ComponentUpdateCommand : UpdateCommand<Component, ComponentUpdateCommandResult> | ||
{ | ||
public ComponentUpdateCommand(User user, Component payload) : base(user, payload) | ||
=> ProjectId = payload?.ProjectId ?? throw new System.ArgumentNullException(nameof(payload)); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/TeamCloud.Model/Commands/ComponentUpdateCommandResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
using TeamCloud.Model.Commands.Core; | ||
using TeamCloud.Model.Data; | ||
|
||
namespace TeamCloud.Model.Commands | ||
{ | ||
public sealed class ComponentUpdateCommandResult : CommandResult<Component> { } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 0 additions & 73 deletions
73
src/TeamCloud.Orchestrator/Operations/Activities/ComponentEnsureStorageActivity.cs
This file was deleted.
Oops, something went wrong.
99 changes: 99 additions & 0 deletions
99
src/TeamCloud.Orchestrator/Operations/Activities/ComponentEnsureTaggingActivity.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/** | ||
* Copyright (c) Microsoft Corporation. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
using Microsoft.Azure.WebJobs; | ||
using Microsoft.Azure.WebJobs.Extensions.DurableTask; | ||
using Microsoft.Extensions.Logging; | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using TeamCloud.Azure.Resources; | ||
using TeamCloud.Data; | ||
using TeamCloud.Model.Data; | ||
using TeamCloud.Orchestration; | ||
using TeamCloud.Serialization; | ||
|
||
namespace TeamCloud.Orchestrator.Operations.Activities | ||
{ | ||
public sealed class ComponentEnsureTaggingActivity | ||
{ | ||
private readonly IOrganizationRepository organizationRepository; | ||
private readonly IProjectRepository projectRepository; | ||
private readonly IAzureResourceService azureResourceService; | ||
|
||
public ComponentEnsureTaggingActivity(IOrganizationRepository organizationRepository, IProjectRepository projectRepository, IAzureResourceService azureResourceService) | ||
{ | ||
this.organizationRepository = organizationRepository ?? throw new ArgumentNullException(nameof(organizationRepository)); | ||
this.projectRepository = projectRepository ?? throw new ArgumentNullException(nameof(projectRepository)); | ||
this.azureResourceService = azureResourceService ?? throw new ArgumentNullException(nameof(azureResourceService)); | ||
} | ||
|
||
[FunctionName(nameof(ComponentEnsureTaggingActivity))] | ||
[RetryOptions(3)] | ||
public async Task<Component> Run( | ||
[ActivityTrigger] IDurableActivityContext context, | ||
ILogger log) | ||
{ | ||
if (context is null) | ||
throw new ArgumentNullException(nameof(context)); | ||
|
||
if (log is null) | ||
throw new ArgumentNullException(nameof(log)); | ||
|
||
var component = context.GetInput<Input>().Component; | ||
|
||
try | ||
{ | ||
if (AzureResourceIdentifier.TryParse(component.ResourceId, out var azureResourceIdentifier)) | ||
{ | ||
var tenantId = (await azureResourceService.AzureSessionService.GetIdentityAsync().ConfigureAwait(false)).TenantId; | ||
|
||
var organization = await organizationRepository | ||
.GetAsync(tenantId.ToString(), component.Organization, true) | ||
.ConfigureAwait(false); | ||
|
||
var project = await projectRepository | ||
.GetAsync(component.Organization, component.ProjectId, true) | ||
.ConfigureAwait(false); | ||
|
||
var tags = organization.Tags | ||
.Union(project.Tags) | ||
.GroupBy(kvp => kvp.Key) | ||
.ToDictionary(g => g.Key, g => g.First().Value); | ||
|
||
if (string.IsNullOrEmpty(azureResourceIdentifier.ResourceGroup)) | ||
{ | ||
var subscription = await azureResourceService | ||
.GetSubscriptionAsync(azureResourceIdentifier.SubscriptionId) | ||
.ConfigureAwait(false); | ||
|
||
if (subscription != null) | ||
await subscription.SetTagsAsync(tags, true).ConfigureAwait(false); | ||
} | ||
else | ||
{ | ||
var resourceGroup = await azureResourceService | ||
.GetResourceGroupAsync(azureResourceIdentifier.SubscriptionId, azureResourceIdentifier.ResourceGroup) | ||
.ConfigureAwait(false); | ||
|
||
if (resourceGroup != null) | ||
await resourceGroup.SetTagsAsync(tags, true).ConfigureAwait(false); | ||
} | ||
} | ||
} | ||
catch (Exception exc) | ||
{ | ||
throw exc.AsSerializable(); | ||
} | ||
|
||
return component; | ||
} | ||
|
||
internal struct Input | ||
{ | ||
public Component Component { get; set; } | ||
} | ||
} | ||
} |
Oops, something went wrong.