Create Firewall Rule support with a simple Resource Provider implementation

Implementation of the resource provider APIs in order to support Create Firewall Rule. Provides definition for a ResourceProvider and Authentication service. The ResourceProvider supports firewall rules for now, and since authentication is routed through that method it will call into the auth service to set up the current account to be used.

Additional notes:
- Fixed deserialization by adding an Accept header. This shouldn't be necessary, but for some reason the firewall rule defaults to XML without this
- Use generic server list and parse the ID to get the resource group, avoiding a large number of extra calls for each RG
- Errors now include error message from the API
This commit is contained in:
Kevin Cunnane
2017-10-09 15:45:33 -07:00
committed by GitHub
parent fecf56bce2
commit 7acc668c04
49 changed files with 1844 additions and 556 deletions

View File

@@ -25,8 +25,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Azure
public void SubscriptionNameShouldReturnCorrectValueGivenValidSubscription()
{
string name = Guid.NewGuid().ToString();
AzureSubscriptionContext subscriptionContext = new AzureSubscriptionContext(new AzureSubscriptionIdentifier(null, name, null));
string tenantId = Guid.NewGuid().ToString();
AzureSubscriptionContext subscriptionContext = new AzureSubscriptionContext(new AzureSubscriptionIdentifier(null, null, name, null));
Assert.True(subscriptionContext.SubscriptionName == name);
Assert.True(subscriptionContext.Subscription != null);
}

View File

@@ -30,7 +30,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider.Azure
foreach (string subscriptionName in subscriptionToDatabaseMap.Keys)
{
var azureAccount = new AzureUserAccount();
AzureSubscriptionIdentifier subId = new AzureSubscriptionIdentifier(azureAccount, subscriptionName, null);
string tenantId = Guid.NewGuid().ToString();
AzureSubscriptionIdentifier subId = new AzureSubscriptionIdentifier(azureAccount, tenantId, subscriptionName, null);
var subscription = new AzureUserAccountSubscriptionContext(subId, new TokenCredentials("dummy"));
accountSubscriptions.Add(subscription);

View File

@@ -3,7 +3,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using Microsoft.SqlTools.ResourceProvider.Core.FirewallRule;
using Microsoft.SqlTools.ResourceProvider.Core.Firewall;
using Xunit;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider

View File

@@ -8,7 +8,7 @@ using System.Linq;
using System.Threading.Tasks;
using Microsoft.SqlTools.ResourceProvider.Core;
using Microsoft.SqlTools.ResourceProvider.Core.Authentication;
using Microsoft.SqlTools.ResourceProvider.Core.FirewallRule;
using Microsoft.SqlTools.ResourceProvider.Core.Firewall;
using Moq;
using Xunit;

View File

@@ -0,0 +1,40 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Microsoft.SqlTools.Hosting.Protocol;
using Microsoft.SqlTools.Extensibility;
using Microsoft.SqlTools.ResourceProvider.Core;
using Moq;
using Microsoft.SqlTools.ResourceProvider;
using Microsoft.SqlTools.ResourceProvider.Core.Authentication;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Formatter
{
public class ResourceProviderServiceTests
{
public ResourceProviderServiceTests()
{
HostMock = new Mock<IProtocolEndpoint>();
AuthenticationManagerMock = new Mock<IAzureAuthenticationManager>();
ResourceManagerMock = new Mock<IAzureResourceManager>();
ServiceProvider = ExtensionServiceProvider.CreateFromAssembliesInDirectory(ResourceProviderHostLoader.GetResourceProviderExtensionDlls());
ServiceProvider.RegisterSingleService<IAzureAuthenticationManager>(AuthenticationManagerMock.Object);
ServiceProvider.RegisterSingleService<IAzureResourceManager>(ResourceManagerMock.Object);
HostLoader.InitializeHostedServices(ServiceProvider, HostMock.Object);
ResourceProviderService = ServiceProvider.GetService<ResourceProviderService>();
}
protected RegisteredServiceProvider ServiceProvider { get; private set; }
protected Mock<IProtocolEndpoint> HostMock { get; private set; }
protected Mock<IAzureAuthenticationManager> AuthenticationManagerMock { get; set; }
protected Mock<IAzureResourceManager> ResourceManagerMock { get; set; }
protected ResourceProviderService ResourceProviderService { get; private set; }
}
}