public void CanCreateSqlPrivateEndpoint()
        {
            using (var context = FluentMockContext.Start(GetType().FullName))
            {
                var dbName            = SdkContext.RandomResourceName("cosmosdb", 22);
                var rgName            = SdkContext.RandomResourceName("cosmosdbRg", 22);
                var networkName       = SdkContext.RandomResourceName("network", 22);
                var subnetName        = SdkContext.RandomResourceName("subnet", 22);
                var plsConnectionName = SdkContext.RandomResourceName("plsconnect", 22);
                var pedName           = SdkContext.RandomResourceName("ped", 22);
                var region            = Region.USWest;

                var azure = TestHelper.CreateRollupClient();

                try
                {
                    azure.ResourceGroups.Define(rgName)
                    .WithRegion(region)
                    .Create();

                    var network = azure.Networks.Define(networkName)
                                  .WithRegion(region)
                                  .WithExistingResourceGroup(rgName)
                                  .WithAddressSpace("10.0.0.0/16")
                                  .DefineSubnet(subnetName)
                                  .WithAddressPrefix("10.0.0.0/24")
                                  .WithAccessFromService(ServiceEndpointType.MicrosoftAzureCosmosDB)
                                  .Attach()
                                  .Create();

                    network.Subnets[subnetName].Inner.PrivateEndpointNetworkPolicies    = "Disabled";
                    network.Subnets[subnetName].Inner.PrivateLinkServiceNetworkPolicies = "Disabled";

                    network.Update()
                    .UpdateSubnet(subnetName)
                    .Parent()
                    .Apply();

                    var databaseAccount = azure.CosmosDBAccounts.Define(dbName)
                                          .WithRegion(region)
                                          .WithExistingResourceGroup(rgName)
                                          .WithDataModelSql()
                                          .WithStrongConsistency()
                                          .WithDisableKeyBaseMetadataWriteAccess(true)
                                          .Create();

                    Assert.True(databaseAccount.KeyBasedMetadataWriteAccessDisabled);

                    var privateLinkServiceConnection = new PrivateLinkServiceConnectionInner(name: plsConnectionName)
                    {
                        PrivateLinkServiceId = databaseAccount.Id,
                        GroupIds             = new List <string> {
                            "Sql"
                        },
                        PrivateLinkServiceConnectionState = new PrivateLinkServiceConnectionState("Approved"),
                    };

                    var privateEndpoint = new PrivateEndpointInner(name: pedName)
                    {
                        Location = region.ToString(),
                        Subnet   = network.Subnets[subnetName].Inner,
                        PrivateLinkServiceConnections = new List <PrivateLinkServiceConnectionInner> {
                            privateLinkServiceConnection
                        },
                    };

                    azure.Networks.Manager.Inner.PrivateEndpoints
                    .CreateOrUpdateWithHttpMessagesAsync(rgName, pedName, privateEndpoint).Wait();

                    Assert.Equal("Approved", databaseAccount.GetPrivateEndpointConnection(pedName).PrivateLinkServiceConnectionState.Status);

                    databaseAccount.Update()
                    .UpdatePrivateEndpointConnection(pedName)
                    .WithStatus("Rejected")
                    .WithDescription("Rej")
                    .Parent()
                    .Apply();

                    var connections = databaseAccount.ListPrivateEndpointConnection();
                    Assert.True(connections.ContainsKey(pedName));
                    Assert.Equal("Rejected", connections[pedName].PrivateLinkServiceConnectionState.Status);

                    Assert.Equal(1, databaseAccount.ListPrivateLinkResources().Count);
                }
                finally
                {
                    try
                    {
                        azure.ResourceGroups.BeginDeleteByName(rgName);
                    }
                    catch { }
                }
            }
        }
Ejemplo n.º 2
0
 PrivateLinkService.Update.IWithPrivateEndpointConnectionSettings PrivateLinkService.Update.IWithPrivateEndpointConnectionSettings.WithPrivateEndpoint(string privateEndpointId)
 {
     privateEndpointInner = new PrivateEndpointInner(id: privateEndpointId);
     return(this);
 }
Ejemplo n.º 3
0
 private void ResetPrivateEndpointConnectionParams()
 {
     privateConnectionName  = null;
     privateEndpointInner   = null;
     privateConnectionState = null;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates or updates an private endpoint in the specified resource group.
 /// </summary>
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='resourceGroupName'>
 /// The name of the resource group.
 /// </param>
 /// <param name='privateEndpointName'>
 /// The name of the private endpoint.
 /// </param>
 /// <param name='parameters'>
 /// Parameters supplied to the create or update private endpoint operation.
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <PrivateEndpointInner> CreateOrUpdateAsync(this IPrivateEndpointsOperations operations, string resourceGroupName, string privateEndpointName, PrivateEndpointInner parameters, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.CreateOrUpdateWithHttpMessagesAsync(resourceGroupName, privateEndpointName, parameters, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }