Skip to content
This repository has been archived by the owner on May 8, 2023. It is now read-only.

Commit

Permalink
Move Sashimi.Azure into Sashimi.Azure.Accounts (#96)
Browse files Browse the repository at this point in the history
* Merge Sashimi.Azure into Sashimi.Azure.Accounts
  • Loading branch information
flin-8 authored Aug 14, 2020
1 parent 3853e2e commit dbf7694
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 214 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NSubstitute" Version="4.2.1" />
<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.15.1" />
<PackageReference Include="Octopus.Server.Tests.Extensibility" Version="11.0.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using FluentAssertions;
using NSubstitute;
using NUnit.Framework;
using Octopus.Server.Extensibility.Extensions.Infrastructure.Web.Api;
using Sashimi.Azure.Web;
using Sashimi.Azure.Accounts.Web;

namespace Sashimi.Azure.Tests.Web
namespace Sashimi.Azure.Accounts.Tests.Web
{
[TestFixture]
public class AzureEnvironmentsListActionFixture
Expand Down
11 changes: 11 additions & 0 deletions source/Sashimi.Azure.Accounts/AzureAccountModule.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Autofac;
using Octopus.Extensibility.Actions.Sashimi;
using Octopus.Server.Extensibility.Extensions.Infrastructure.Web.Api;
using Octopus.Server.Extensibility.Extensions.Mappings;
using Octopus.Server.Extensibility.HostServices.Web;
using Sashimi.Azure.Accounts.Web;
using Sashimi.Server.Contracts.Accounts;

Expand All @@ -12,6 +14,15 @@ protected override void Load(ContainerBuilder builder)
{
builder.RegisterType<AzureServicePrincipalAccountTypeProvider>().As<IAccountTypeProvider>().As<IContributeMappings>().SingleInstance();

LoadWebSubModule(builder);
}

void LoadWebSubModule(ContainerBuilder builder)
{
builder.RegisterType<AzureApi>().As<RegistersEndpoints>().AsSelf().InstancePerLifetimeScope();
builder.RegisterType<AzureEnvironmentsListAction>().AsSelf().InstancePerDependency();
builder.RegisterType<AzureHomeLinksContributor>().As<IHomeLinksContributor>().InstancePerDependency();

builder.RegisterType<AzureWebSitesListAction>().AsSelf().As<IAccountDetailsEndpoint>().InstancePerLifetimeScope();
builder.RegisterType<AzureWebSitesSlotListAction>().AsSelf().As<IAccountDetailsEndpoint>().InstancePerLifetimeScope();
builder.RegisterType<AzureResourceGroupsListAction>().AsSelf().As<IAccountDetailsEndpoint>().InstancePerLifetimeScope();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
using System.Net.Http;
using System.Net.Http.Headers;
using Microsoft.Azure.Management.ResourceManager;
using Microsoft.Azure.Management.Storage;
using Microsoft.Azure.Management.WebSites;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
using Microsoft.Rest;
using Sashimi.Azure.Accounts;
using IHttpClientFactory = Microsoft.IdentityModel.Clients.ActiveDirectory.IHttpClientFactory;


namespace Sashimi.Azure.Accounts
{
static class AzureServicePrincipalAccountExtensions
{
static ServiceClientCredentials Credentials(this AzureServicePrincipalAccountDetails account, HttpMessageHandler handler)
Expand All @@ -22,6 +23,20 @@ public static ResourceManagementClient CreateResourceManagementClient(this Azure
new ResourceManagementClient(new Uri(account.ResourceManagementEndpointBaseUri), account.Credentials(httpClientHandler), httpClientHandler) { SubscriptionId = account.SubscriptionNumber };
}

public static StorageManagementClient CreateStorageManagementClient(this AzureServicePrincipalAccountDetails account, HttpClientHandler httpClientHandler)
{
return string.IsNullOrWhiteSpace(account.ResourceManagementEndpointBaseUri) ?
new StorageManagementClient(account.Credentials(httpClientHandler), httpClientHandler) { SubscriptionId = account.SubscriptionNumber } :
new StorageManagementClient(new Uri(account.ResourceManagementEndpointBaseUri), account.Credentials(httpClientHandler), httpClientHandler) { SubscriptionId = account.SubscriptionNumber };
}

public static WebSiteManagementClient CreateWebSiteManagementClient(this AzureServicePrincipalAccountDetails account, HttpClientHandler httpClientHandler)
{
return string.IsNullOrWhiteSpace(account.ResourceManagementEndpointBaseUri) ?
new WebSiteManagementClient(account.Credentials(httpClientHandler), httpClientHandler) { SubscriptionId = account.SubscriptionNumber } :
new WebSiteManagementClient(new Uri(account.ResourceManagementEndpointBaseUri), account.Credentials(httpClientHandler), httpClientHandler) { SubscriptionId = account.SubscriptionNumber };
}

static string GetAuthorizationToken(AzureServicePrincipalAccountDetails account, HttpMessageHandler handler)
{
var adDirectory = "https://login.windows.net/";
Expand Down Expand Up @@ -63,3 +78,4 @@ public HttpClient GetHttpClient()
}
}
}
}
33 changes: 18 additions & 15 deletions source/Sashimi.Azure.Accounts/PropertyDictionaryExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,30 @@
using System;
using System.Collections.Generic;

static class PropertyDictionaryExtensions
namespace Sashimi.Azure.Accounts
{
public static bool ContainsPropertyWithValue(this IDictionary<string, string> dictionary, string key)
static class PropertyDictionaryExtensions
{
if (!dictionary.ContainsKey(key))
public static bool ContainsPropertyWithValue(this IDictionary<string, string> dictionary, string key)
{
return false;
}
if (!dictionary.ContainsKey(key))
{
return false;
}

string value = dictionary[key];
return value != null && !string.IsNullOrEmpty(value);
}
string value = dictionary[key];
return value != null && !string.IsNullOrEmpty(value);
}

public static bool ContainsPropertyWithGuid(this IDictionary<string, string> dictionary, string key)
{
if (!ContainsPropertyWithValue(dictionary, key))
public static bool ContainsPropertyWithGuid(this IDictionary<string, string> dictionary, string key)
{
return false;
}
if (!ContainsPropertyWithValue(dictionary, key))
{
return false;
}

string guid = dictionary[key];
return Guid.TryParse(guid, out Guid _);
string guid = dictionary[key];
return Guid.TryParse(guid, out Guid _);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<ItemGroup>
<ProjectReference Include="..\Azure.Common\Sashimi.Azure.Common.csproj" />
<ProjectReference Include="..\Server.Contracts\Sashimi.Server.Contracts.csproj" />
<PackageReference Include="Microsoft.Azure.Management.ResourceManager.Fluent" Version="1.34.0" />
<PackageReference Include="Microsoft.IdentityModel.Clients.ActiveDirectory" Version="5.2.8" />
<PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="3.7.3-preview" />
<PackageReference Include="Microsoft.Azure.Management.Storage" Version="9.0.0-preview" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Net.Http;
using Octopus.Server.Extensibility.Extensions.Infrastructure.Web.Api;

namespace Sashimi.Azure.Web
namespace Sashimi.Azure.Accounts.Web
{
class AzureApi : RegistersEndpoints
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Azure.Management.ResourceManager.Fluent;
using Octopus.Server.Extensibility.Extensions.Infrastructure.Web.Api;

namespace Sashimi.Azure.Web
namespace Sashimi.Azure.Accounts.Web
{
class AzureEnvironmentsListAction : IAsyncApiAction
{
Expand Down Expand Up @@ -80,12 +81,12 @@ static string GetKnownEnvironmentDisplayName(string environmentName)

class AzureEnvironmentResource
{
public string Name { get; set; }
public string DisplayName { get; set; }
public string AuthenticationEndpoint { get; set; }
public string ResourceManagerEndpoint { get; set; }
public string GraphEndpoint { get; set; }
public string ManagementEndpoint { get; set; }
public string StorageEndpointSuffix { get; set; }
public string Name { get; set; } = null!;
public string DisplayName { get; set; } = null!;
public string AuthenticationEndpoint { get; set; } = null!;
public string ResourceManagerEndpoint { get; set; } = null!;
public string GraphEndpoint { get; set; } = null!;
public string ManagementEndpoint { get; set; } = null!;
public string StorageEndpointSuffix { get; set; } = null!;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using Octopus.Server.Extensibility.HostServices.Web;

namespace Sashimi.Azure.Web
namespace Sashimi.Azure.Accounts.Web
{
class AzureHomeLinksContributor : IHomeLinksContributor
{
Expand Down

This file was deleted.

12 changes: 0 additions & 12 deletions source/Sashimi.Azure.Tests/OnlyExposeWhatIsNecessary.cs

This file was deleted.

24 changes: 0 additions & 24 deletions source/Sashimi.Azure.Tests/Sashimi.Azure.Tests.csproj

This file was deleted.

24 changes: 0 additions & 24 deletions source/Sashimi.Azure/AzureModule.cs

This file was deleted.

4 changes: 0 additions & 4 deletions source/Sashimi.Azure/Properties/InternalsVisibleTo.cs

This file was deleted.

20 changes: 0 additions & 20 deletions source/Sashimi.Azure/Sashimi.Azure.csproj

This file was deleted.

Loading

0 comments on commit dbf7694

Please sign in to comment.