Пример #1
0
        public override void ExecuteCmdlet()
        {
            DatabaseAccountGetResults databaseAccountGetResults = null;

            try
            {
                databaseAccountGetResults = CosmosDBManagementClient.DatabaseAccounts.Get(ResourceGroupName, Name);
            }
            catch (CloudException e)
            {
                if (e.Response.StatusCode != System.Net.HttpStatusCode.NotFound)
                {
                    throw;
                }
            }

            if (databaseAccountGetResults != null)
            {
                throw new ConflictingResourceException(message: string.Format(ExceptionMessage.Conflict, Name));
            }

            ConsistencyPolicy     consistencyPolicy  = base.PopoulateConsistencyPolicy(DefaultConsistencyLevel, MaxStalenessIntervalInSeconds, MaxStalenessPrefix);
            string                writeLocation      = null;
            Collection <Location> LocationCollection = new Collection <Location>();

            if (Location != null && Location.Length > 0)
            {
                int failoverPriority = 0;
                foreach (string l in Location)
                {
                    Location loc = new Location(locationName: l, failoverPriority: failoverPriority);
                    LocationCollection.Add(loc);
                    if (failoverPriority == 0)
                    {
                        writeLocation = l;
                    }

                    failoverPriority++;
                }
            }
            else if (LocationObject != null && LocationObject.Length > 0)
            {
                if (writeLocation != null)
                {
                    WriteWarning("Cannot accept Location and LocationObject simultaneously as parameters");
                    return;
                }

                foreach (PSLocation psLocation in LocationObject)
                {
                    LocationCollection.Add(PSLocation.ToSDKModel(psLocation));
                    if (psLocation.FailoverPriority == 0)
                    {
                        writeLocation = psLocation.LocationName;
                    }
                }
            }

            if (string.IsNullOrEmpty(writeLocation))
            {
                WriteWarning("Cannot create Account without a Write Location.");
                return;
            }

            Dictionary <string, string> tags = new Dictionary <string, string>();

            if (Tag != null)
            {
                tags = base.PopulateTags(Tag);
            }

            Collection <VirtualNetworkRule> virtualNetworkRule = new Collection <VirtualNetworkRule>();

            if (VirtualNetworkRule != null && VirtualNetworkRule.Length > 0)
            {
                foreach (string id in VirtualNetworkRule)
                {
                    virtualNetworkRule.Add(new VirtualNetworkRule(id: id));
                }
            }
            if (VirtualNetworkRuleObject != null && VirtualNetworkRuleObject.Length > 0)
            {
                foreach (PSVirtualNetworkRule psVirtualNetworkRule in VirtualNetworkRuleObject)
                {
                    virtualNetworkRule.Add(PSVirtualNetworkRule.ToSDKModel(psVirtualNetworkRule));
                }
            }

            DatabaseAccountCreateUpdateParameters databaseAccountCreateUpdateParameters = new DatabaseAccountCreateUpdateParameters(locations: LocationCollection, location: writeLocation, name: Name, tags: tags);

            if (FromPointInTimeBackup)
            {
                PSRestoreParameters restoreParameters = restoreContext.GetRestoreParameters(CosmosDBManagementClient);
                if (restoreParameters == null)
                {
                    WriteWarning("Please provide valid parameters to restore");
                    return;
                }

                databaseAccountCreateUpdateParameters.CreateMode        = CreateMode.Restore;
                databaseAccountCreateUpdateParameters.RestoreParameters = restoreParameters.ToSDKModel();
            }

            databaseAccountCreateUpdateParameters.ConsistencyPolicy                  = consistencyPolicy;
            databaseAccountCreateUpdateParameters.EnableMultipleWriteLocations       = EnableMultipleWriteLocations;
            databaseAccountCreateUpdateParameters.IsVirtualNetworkFilterEnabled      = EnableVirtualNetwork;
            databaseAccountCreateUpdateParameters.EnableAutomaticFailover            = EnableAutomaticFailover;
            databaseAccountCreateUpdateParameters.VirtualNetworkRules                = virtualNetworkRule;
            databaseAccountCreateUpdateParameters.DisableKeyBasedMetadataWriteAccess = DisableKeyBasedMetadataWriteAccess;
            databaseAccountCreateUpdateParameters.PublicNetworkAccess                = PublicNetworkAccess;
            databaseAccountCreateUpdateParameters.EnableFreeTier          = EnableFreeTier;
            databaseAccountCreateUpdateParameters.EnableAnalyticalStorage = EnableAnalyticalStorage;
            Collection <string> networkAclBypassResourceId = NetworkAclBypassResourceId != null ? new Collection <string>(NetworkAclBypassResourceId) : new Collection <string>();

            databaseAccountCreateUpdateParameters.NetworkAclBypassResourceIds = networkAclBypassResourceId;

            if (IpRule != null && IpRule.Length > 0)
            {
                databaseAccountCreateUpdateParameters.IpRules = base.PopulateIpRules(IpRule);
            }

            if (KeyVaultKeyUri != null)
            {
                databaseAccountCreateUpdateParameters.KeyVaultKeyUri = KeyVaultKeyUri;
            }

            if (NetworkAclBypass != null)
            {
                databaseAccountCreateUpdateParameters.NetworkAclBypass =
                    NetworkAclBypass == "AzureServices" ? SDKModel.NetworkAclBypass.AzureServices : SDKModel.NetworkAclBypass.None;
            }

            if (!string.IsNullOrEmpty(ApiKind))
            {
                if (ApiKind.Equals("MongoDB", StringComparison.OrdinalIgnoreCase))
                {
                    if (ServerVersion != null)
                    {
                        databaseAccountCreateUpdateParameters.ApiProperties = new ApiProperties
                        {
                            ServerVersion = ServerVersion
                        };
                    }
                }
                else
                {
                    switch (ApiKind)
                    {
                    case "Cassandra":
                        databaseAccountCreateUpdateParameters.Capabilities = new List <Capability> {
                            new Capability {
                                Name = "EnableCassandra"
                            }
                        };
                        break;

                    case "Gremlin":
                        databaseAccountCreateUpdateParameters.Capabilities = new List <Capability> {
                            new Capability {
                                Name = "EnableGremlin"
                            }
                        };
                        break;

                    case "Table":
                        databaseAccountCreateUpdateParameters.Capabilities = new List <Capability> {
                            new Capability {
                                Name = "EnableTable"
                            }
                        };
                        break;

                    case "Sql":
                        break;
                    }

                    ApiKind = null;
                }
            }
            else
            {
                ApiKind = "GlobalDocumentDB";
            }
            databaseAccountCreateUpdateParameters.Kind = ApiKind;

            if (!string.IsNullOrEmpty(BackupPolicyType))
            {
                PSBackupPolicy backupPolicy = new PSBackupPolicy()
                {
                    BackupType = BackupPolicyType,
                    BackupIntervalInMinutes        = BackupIntervalInMinutes,
                    BackupRetentionIntervalInHours = BackupRetentionIntervalInHours
                };

                if (BackupPolicyType.Equals(PSBackupPolicy.ContinuousModeBackupType, StringComparison.OrdinalIgnoreCase) &&
                    (BackupIntervalInMinutes.HasValue || BackupRetentionIntervalInHours.HasValue))
                {
                    WriteWarning("Cannot accept BackupInterval or BackupRetention parameters for ContinuousModeBackupType");
                    return;
                }

                databaseAccountCreateUpdateParameters.BackupPolicy = backupPolicy.ToSDKModel();
            }
            else if (BackupIntervalInMinutes.HasValue || BackupRetentionIntervalInHours.HasValue)
            {
                databaseAccountCreateUpdateParameters.BackupPolicy = new PeriodicModeBackupPolicy()
                {
                    PeriodicModeProperties = new PeriodicModeProperties()
                    {
                        BackupIntervalInMinutes        = BackupIntervalInMinutes,
                        BackupRetentionIntervalInHours = BackupRetentionIntervalInHours
                    }
                };
            }

            // Update analytical storage schema type.
            databaseAccountCreateUpdateParameters.AnalyticalStorageConfiguration = CreateAnalyticalStorageConfiguration(AnalyticalStorageSchemaType);

            if (ShouldProcess(Name, "Creating Database Account"))
            {
                DatabaseAccountGetResults cosmosDBAccount = CosmosDBManagementClient.DatabaseAccounts.CreateOrUpdateWithHttpMessagesAsync(ResourceGroupName, Name, databaseAccountCreateUpdateParameters).GetAwaiter().GetResult().Body;
                WriteObject(new PSDatabaseAccountGetResults(cosmosDBAccount));
            }

            return;
        }
        public override void ExecuteCmdlet()
        {
            ConsistencyPolicy consistencyPolicy = new ConsistencyPolicy();
            {
                switch (DefaultConsistencyLevel)
                {
                case "Strong":
                    consistencyPolicy.DefaultConsistencyLevel = Management.CosmosDB.Models.DefaultConsistencyLevel.Strong;
                    break;

                case "Session":
                    consistencyPolicy.DefaultConsistencyLevel = Management.CosmosDB.Models.DefaultConsistencyLevel.Session;
                    break;

                case "Eventual":
                    consistencyPolicy.DefaultConsistencyLevel = Management.CosmosDB.Models.DefaultConsistencyLevel.Eventual;
                    break;

                case "ConsistentPrefix":
                    consistencyPolicy.DefaultConsistencyLevel = Management.CosmosDB.Models.DefaultConsistencyLevel.ConsistentPrefix;
                    break;

                case "BoundedStaleness":
                    consistencyPolicy.DefaultConsistencyLevel = Management.CosmosDB.Models.DefaultConsistencyLevel.BoundedStaleness;
                    consistencyPolicy.MaxIntervalInSeconds    = MaxStalenessIntervalInSeconds;
                    consistencyPolicy.MaxStalenessPrefix      = MaxStalenessPrefix;
                    break;

                default:
                    consistencyPolicy.DefaultConsistencyLevel = Management.CosmosDB.Models.DefaultConsistencyLevel.Session;
                    break;
                }
            }

            string writeLocation = null;
            Collection <Location> LocationCollection = new Collection <Location>();

            if (Location != null && Location.Length > 0)
            {
                int failoverPriority = 0;
                foreach (string l in Location)
                {
                    Location loc = new Location(locationName: l, failoverPriority: failoverPriority);
                    LocationCollection.Add(loc);
                    if (failoverPriority == 0)
                    {
                        writeLocation = l;
                    }

                    failoverPriority++;
                }
            }
            else if (LocationObject != null && LocationObject.Length > 0)
            {
                if (writeLocation != null)
                {
                    WriteWarning("Cannot accept Location and LocationObject simultaneously as parameters");
                    return;
                }

                foreach (PSLocation psLocation in LocationObject)
                {
                    LocationCollection.Add(PSLocation.ConvertPSLocationToLocation(psLocation));
                    if (psLocation.FailoverPriority == 0)
                    {
                        writeLocation = psLocation.LocationName;
                    }
                }
            }

            if (string.IsNullOrEmpty(writeLocation))
            {
                WriteWarning("Cannot create Account without a Write Location.");
                return;
            }

            Dictionary <string, string> tags = new Dictionary <string, string>();

            if (Tag != null)
            {
                foreach (string key in Tag.Keys)
                {
                    tags.Add(key, Tag[key].ToString());
                }
            }

            Collection <VirtualNetworkRule> virtualNetworkRule = new Collection <VirtualNetworkRule>();

            if (VirtualNetworkRule != null && VirtualNetworkRule.Length > 0)
            {
                foreach (string id in VirtualNetworkRule)
                {
                    virtualNetworkRule.Add(new VirtualNetworkRule(id: id));
                }
            }
            if (VirtualNetworkRuleObject != null && VirtualNetworkRuleObject.Length > 0)
            {
                foreach (PSVirtualNetworkRule psVirtualNetworkRule in VirtualNetworkRuleObject)
                {
                    virtualNetworkRule.Add(PSVirtualNetworkRule.ConvertPSVirtualNetworkRuleToVirtualNetworkRule(psVirtualNetworkRule));
                }
            }

            string IpRangeFilterAsString = null;

            if (IpRangeFilter != null && IpRangeFilter.Length > 0)
            {
                for (int i = 0; i < IpRangeFilter.Length; i++)
                {
                    if (i == 0)
                    {
                        IpRangeFilterAsString = IpRangeFilter[0];
                    }
                    else
                    {
                        IpRangeFilterAsString = string.Concat(IpRangeFilterAsString, ",", IpRangeFilter[i]);
                    }
                }
            }

            DatabaseAccountCreateUpdateParameters databaseAccountCreateUpdateParameters = new DatabaseAccountCreateUpdateParameters(locations: LocationCollection, location: writeLocation, name: Name, consistencyPolicy: consistencyPolicy, tags: tags, ipRangeFilter: IpRangeFilterAsString);

            databaseAccountCreateUpdateParameters.EnableMultipleWriteLocations  = EnableMultipleWriteLocations;
            databaseAccountCreateUpdateParameters.IsVirtualNetworkFilterEnabled = EnableVirtualNetwork;
            databaseAccountCreateUpdateParameters.EnableAutomaticFailover       = EnableAutomaticFailover;
            databaseAccountCreateUpdateParameters.VirtualNetworkRules           = virtualNetworkRule;

            if (!string.IsNullOrEmpty(ApiKind))
            {
                if (!ApiKind.Equals("GlobalDocumentDB", StringComparison.OrdinalIgnoreCase) && !ApiKind.Equals("MongoDB", StringComparison.OrdinalIgnoreCase))
                {
                    switch (ApiKind)
                    {
                    case "Cassandra":
                        databaseAccountCreateUpdateParameters.Capabilities = new List <Capability> {
                            new Capability {
                                Name = "EnableCassandra"
                            }
                        };
                        break;

                    case "Gremlin":
                        databaseAccountCreateUpdateParameters.Capabilities = new List <Capability> {
                            new Capability {
                                Name = "EnableGremlin"
                            }
                        };
                        break;

                    case "Table":
                        databaseAccountCreateUpdateParameters.Capabilities = new List <Capability> {
                            new Capability {
                                Name = "EnableTable"
                            }
                        };
                        break;
                    }

                    ApiKind = null;
                }
            }
            else
            {
                ApiKind = "GlobalDocumentDB";
            }
            databaseAccountCreateUpdateParameters.Kind = ApiKind;

            if (ShouldProcess(Name, "Creating Database Account"))
            {
                DatabaseAccountGetResults cosmosDBAccount = CosmosDBManagementClient.DatabaseAccounts.CreateOrUpdateWithHttpMessagesAsync(ResourceGroupName, Name, databaseAccountCreateUpdateParameters).GetAwaiter().GetResult().Body;
                WriteObject(new PSDatabaseAccount(cosmosDBAccount));
            }

            return;
        }
Пример #3
0
        internal static DatabaseAccountData DeserializeDatabaseAccountData(JsonElement element)
        {
            Optional <DatabaseAccountKind>    kind     = default;
            Optional <ManagedServiceIdentity> identity = default;
            IDictionary <string, string>      tags     = default;
            AzureLocation      location                    = default;
            ResourceIdentifier id                          = default;
            string             name                        = default;
            ResourceType       type                        = default;
            SystemData         systemData                  = default;
            Optional <string>  provisioningState           = default;
            Optional <string>  documentEndpoint            = default;
            Optional <string>  databaseAccountOfferType    = default;
            Optional <IList <IPAddressOrRange> > ipRules   = default;
            Optional <bool> isVirtualNetworkFilterEnabled  = default;
            Optional <bool> enableAutomaticFailover        = default;
            Optional <ConsistencyPolicy> consistencyPolicy = default;
            Optional <IList <DatabaseAccountCapability> >       capabilities     = default;
            Optional <IReadOnlyList <DatabaseAccountLocation> > writeLocations   = default;
            Optional <IReadOnlyList <DatabaseAccountLocation> > readLocations    = default;
            Optional <IReadOnlyList <DatabaseAccountLocation> > locations        = default;
            Optional <IReadOnlyList <FailoverPolicy> >          failoverPolicies = default;
            Optional <IList <VirtualNetworkRule> > virtualNetworkRules           = default;
            Optional <IReadOnlyList <CosmosDBPrivateEndpointConnectionData> > privateEndpointConnections = default;
            Optional <bool>                           enableMultipleWriteLocations = default;
            Optional <bool>                           enableCassandraConnector     = default;
            Optional <ConnectorOffer>                 connectorOffer = default;
            Optional <bool>                           disableKeyBasedMetadataWriteAccess = default;
            Optional <Uri>                            keyVaultKeyUri                 = default;
            Optional <string>                         defaultIdentity                = default;
            Optional <PublicNetworkAccess>            publicNetworkAccess            = default;
            Optional <bool>                           enableFreeTier                 = default;
            Optional <ApiProperties>                  apiProperties                  = default;
            Optional <bool>                           enableAnalyticalStorage        = default;
            Optional <AnalyticalStorageConfiguration> analyticalStorageConfiguration = default;
            Optional <string>                         instanceId        = default;
            Optional <CreateMode>                     createMode        = default;
            Optional <RestoreParameters>              restoreParameters = default;
            Optional <BackupPolicy>                   backupPolicy      = default;
            Optional <IList <CorsPolicy> >            cors                        = default;
            Optional <NetworkAclBypass>               networkAclBypass            = default;
            Optional <IList <string> >                networkAclBypassResourceIds = default;
            Optional <bool>                           disableLocalAuth            = default;
            Optional <Capacity>                       capacity                    = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("kind"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    kind = new DatabaseAccountKind(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("identity"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    var serializeOptions = new JsonSerializerOptions {
                        Converters = { new ManagedServiceIdentityTypeV3Converter() }
                    };
                    identity = JsonSerializer.Deserialize <ManagedServiceIdentity>(property.Value.ToString(), serializeOptions);
                    continue;
                }
                if (property.NameEquals("tags"))
                {
                    Dictionary <string, string> dictionary = new Dictionary <string, string>();
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        dictionary.Add(property0.Name, property0.Value.GetString());
                    }
                    tags = dictionary;
                    continue;
                }
                if (property.NameEquals("location"))
                {
                    location = new AzureLocation(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("id"))
                {
                    id = new ResourceIdentifier(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("type"))
                {
                    type = new ResourceType(property.Value.GetString());
                    continue;
                }
                if (property.NameEquals("systemData"))
                {
                    systemData = JsonSerializer.Deserialize <SystemData>(property.Value.ToString());
                    continue;
                }
                if (property.NameEquals("properties"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        if (property0.NameEquals("provisioningState"))
                        {
                            provisioningState = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("documentEndpoint"))
                        {
                            documentEndpoint = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("databaseAccountOfferType"))
                        {
                            databaseAccountOfferType = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("ipRules"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <IPAddressOrRange> array = new List <IPAddressOrRange>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(IPAddressOrRange.DeserializeIPAddressOrRange(item));
                            }
                            ipRules = array;
                            continue;
                        }
                        if (property0.NameEquals("isVirtualNetworkFilterEnabled"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            isVirtualNetworkFilterEnabled = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("enableAutomaticFailover"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            enableAutomaticFailover = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("consistencyPolicy"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            consistencyPolicy = ConsistencyPolicy.DeserializeConsistencyPolicy(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("capabilities"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <DatabaseAccountCapability> array = new List <DatabaseAccountCapability>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(DatabaseAccountCapability.DeserializeDatabaseAccountCapability(item));
                            }
                            capabilities = array;
                            continue;
                        }
                        if (property0.NameEquals("writeLocations"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <DatabaseAccountLocation> array = new List <DatabaseAccountLocation>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(DatabaseAccountLocation.DeserializeDatabaseAccountLocation(item));
                            }
                            writeLocations = array;
                            continue;
                        }
                        if (property0.NameEquals("readLocations"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <DatabaseAccountLocation> array = new List <DatabaseAccountLocation>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(DatabaseAccountLocation.DeserializeDatabaseAccountLocation(item));
                            }
                            readLocations = array;
                            continue;
                        }
                        if (property0.NameEquals("locations"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <DatabaseAccountLocation> array = new List <DatabaseAccountLocation>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(DatabaseAccountLocation.DeserializeDatabaseAccountLocation(item));
                            }
                            locations = array;
                            continue;
                        }
                        if (property0.NameEquals("failoverPolicies"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <FailoverPolicy> array = new List <FailoverPolicy>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(FailoverPolicy.DeserializeFailoverPolicy(item));
                            }
                            failoverPolicies = array;
                            continue;
                        }
                        if (property0.NameEquals("virtualNetworkRules"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <VirtualNetworkRule> array = new List <VirtualNetworkRule>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(VirtualNetworkRule.DeserializeVirtualNetworkRule(item));
                            }
                            virtualNetworkRules = array;
                            continue;
                        }
                        if (property0.NameEquals("privateEndpointConnections"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <CosmosDBPrivateEndpointConnectionData> array = new List <CosmosDBPrivateEndpointConnectionData>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(CosmosDBPrivateEndpointConnectionData.DeserializeCosmosDBPrivateEndpointConnectionData(item));
                            }
                            privateEndpointConnections = array;
                            continue;
                        }
                        if (property0.NameEquals("enableMultipleWriteLocations"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            enableMultipleWriteLocations = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("enableCassandraConnector"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            enableCassandraConnector = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("connectorOffer"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            connectorOffer = new ConnectorOffer(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("disableKeyBasedMetadataWriteAccess"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            disableKeyBasedMetadataWriteAccess = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("keyVaultKeyUri"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                keyVaultKeyUri = null;
                                continue;
                            }
                            keyVaultKeyUri = new Uri(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("defaultIdentity"))
                        {
                            defaultIdentity = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("publicNetworkAccess"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            publicNetworkAccess = new PublicNetworkAccess(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("enableFreeTier"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            enableFreeTier = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("apiProperties"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            apiProperties = ApiProperties.DeserializeApiProperties(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("enableAnalyticalStorage"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            enableAnalyticalStorage = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("analyticalStorageConfiguration"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            analyticalStorageConfiguration = AnalyticalStorageConfiguration.DeserializeAnalyticalStorageConfiguration(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("instanceId"))
                        {
                            instanceId = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("createMode"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            createMode = new CreateMode(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("restoreParameters"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            restoreParameters = RestoreParameters.DeserializeRestoreParameters(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("backupPolicy"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            backupPolicy = BackupPolicy.DeserializeBackupPolicy(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("cors"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <CorsPolicy> array = new List <CorsPolicy>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(CorsPolicy.DeserializeCorsPolicy(item));
                            }
                            cors = array;
                            continue;
                        }
                        if (property0.NameEquals("networkAclBypass"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            networkAclBypass = property0.Value.GetString().ToNetworkAclBypass();
                            continue;
                        }
                        if (property0.NameEquals("networkAclBypassResourceIds"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <string> array = new List <string>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(item.GetString());
                            }
                            networkAclBypassResourceIds = array;
                            continue;
                        }
                        if (property0.NameEquals("disableLocalAuth"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            disableLocalAuth = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("capacity"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            capacity = Capacity.DeserializeCapacity(property0.Value);
                            continue;
                        }
                    }
                    continue;
                }
            }
            return(new DatabaseAccountData(id, name, type, systemData, tags, location, Optional.ToNullable(kind), identity, provisioningState.Value, documentEndpoint.Value, databaseAccountOfferType.Value, Optional.ToList(ipRules), Optional.ToNullable(isVirtualNetworkFilterEnabled), Optional.ToNullable(enableAutomaticFailover), consistencyPolicy.Value, Optional.ToList(capabilities), Optional.ToList(writeLocations), Optional.ToList(readLocations), Optional.ToList(locations), Optional.ToList(failoverPolicies), Optional.ToList(virtualNetworkRules), Optional.ToList(privateEndpointConnections), Optional.ToNullable(enableMultipleWriteLocations), Optional.ToNullable(enableCassandraConnector), Optional.ToNullable(connectorOffer), Optional.ToNullable(disableKeyBasedMetadataWriteAccess), keyVaultKeyUri.Value, defaultIdentity.Value, Optional.ToNullable(publicNetworkAccess), Optional.ToNullable(enableFreeTier), apiProperties.Value, Optional.ToNullable(enableAnalyticalStorage), analyticalStorageConfiguration.Value, instanceId.Value, Optional.ToNullable(createMode), restoreParameters.Value, backupPolicy.Value, Optional.ToList(cors), Optional.ToNullable(networkAclBypass), Optional.ToList(networkAclBypassResourceIds), Optional.ToNullable(disableLocalAuth), capacity.Value));
        }
 internal DatabaseAccountData(ResourceIdentifier id, string name, ResourceType type, SystemData systemData, IDictionary <string, string> tags, AzureLocation location, DatabaseAccountKind?kind, ManagedServiceIdentity identity, string provisioningState, string documentEndpoint, string databaseAccountOfferType, IList <IpAddressOrRange> ipRules, bool?isVirtualNetworkFilterEnabled, bool?enableAutomaticFailover, ConsistencyPolicy consistencyPolicy, IList <DatabaseAccountCapability> capabilities, IReadOnlyList <DatabaseAccountLocation> writeLocations, IReadOnlyList <DatabaseAccountLocation> readLocations, IReadOnlyList <DatabaseAccountLocation> locations, IReadOnlyList <FailoverPolicy> failoverPolicies, IList <VirtualNetworkRule> virtualNetworkRules, IReadOnlyList <PrivateEndpointConnectionData> privateEndpointConnections, bool?enableMultipleWriteLocations, bool?enableCassandraConnector, ConnectorOffer?connectorOffer, bool?disableKeyBasedMetadataWriteAccess, string keyVaultKeyUri, string defaultIdentity, PublicNetworkAccess?publicNetworkAccess, bool?enableFreeTier, ApiProperties apiProperties, bool?enableAnalyticalStorage, AnalyticalStorageConfiguration analyticalStorageConfiguration, string instanceId, CreateMode?createMode, RestoreParameters restoreParameters, BackupPolicy backupPolicy, IList <CorsPolicy> cors, NetworkAclBypass?networkAclBypass, IList <string> networkAclBypassResourceIds, bool?disableLocalAuth, Capacity capacity) : base(id, name, type, systemData, tags, location)
 {
     Kind                               = kind;
     Identity                           = identity;
     ProvisioningState                  = provisioningState;
     DocumentEndpoint                   = documentEndpoint;
     DatabaseAccountOfferType           = databaseAccountOfferType;
     IpRules                            = ipRules;
     IsVirtualNetworkFilterEnabled      = isVirtualNetworkFilterEnabled;
     EnableAutomaticFailover            = enableAutomaticFailover;
     ConsistencyPolicy                  = consistencyPolicy;
     Capabilities                       = capabilities;
     WriteLocations                     = writeLocations;
     ReadLocations                      = readLocations;
     Locations                          = locations;
     FailoverPolicies                   = failoverPolicies;
     VirtualNetworkRules                = virtualNetworkRules;
     PrivateEndpointConnections         = privateEndpointConnections;
     EnableMultipleWriteLocations       = enableMultipleWriteLocations;
     EnableCassandraConnector           = enableCassandraConnector;
     ConnectorOffer                     = connectorOffer;
     DisableKeyBasedMetadataWriteAccess = disableKeyBasedMetadataWriteAccess;
     KeyVaultKeyUri                     = keyVaultKeyUri;
     DefaultIdentity                    = defaultIdentity;
     PublicNetworkAccess                = publicNetworkAccess;
     EnableFreeTier                     = enableFreeTier;
     ApiProperties                      = apiProperties;
     EnableAnalyticalStorage            = enableAnalyticalStorage;
     AnalyticalStorageConfiguration     = analyticalStorageConfiguration;
     InstanceId                         = instanceId;
     CreateMode                         = createMode;
     RestoreParameters                  = restoreParameters;
     BackupPolicy                       = backupPolicy;
     Cors                               = cors;
     NetworkAclBypass                   = networkAclBypass;
     NetworkAclBypassResourceIds        = networkAclBypassResourceIds;
     DisableLocalAuth                   = disableLocalAuth;
     Capacity                           = capacity;
 }
Пример #5
0
        public override void ExecuteCmdlet()
        {
            ConsistencyPolicy     consistencyPolicy  = base.PopoulateConsistencyPolicy(DefaultConsistencyLevel, MaxStalenessIntervalInSeconds, MaxStalenessPrefix);
            string                writeLocation      = null;
            Collection <Location> LocationCollection = new Collection <Location>();

            if (Location != null && Location.Length > 0)
            {
                int failoverPriority = 0;
                foreach (string l in Location)
                {
                    Location loc = new Location(locationName: l, failoverPriority: failoverPriority);
                    LocationCollection.Add(loc);
                    if (failoverPriority == 0)
                    {
                        writeLocation = l;
                    }

                    failoverPriority++;
                }
            }
            else if (LocationObject != null && LocationObject.Length > 0)
            {
                if (writeLocation != null)
                {
                    WriteWarning("Cannot accept Location and LocationObject simultaneously as parameters");
                    return;
                }

                foreach (PSLocation psLocation in LocationObject)
                {
                    LocationCollection.Add(PSLocation.ToSDKModel(psLocation));
                    if (psLocation.FailoverPriority == 0)
                    {
                        writeLocation = psLocation.LocationName;
                    }
                }
            }

            if (string.IsNullOrEmpty(writeLocation))
            {
                WriteWarning("Cannot create Account without a Write Location.");
                return;
            }

            Dictionary <string, string> tags = new Dictionary <string, string>();

            if (Tag != null)
            {
                tags = base.PopulateTags(Tag);
            }

            Collection <VirtualNetworkRule> virtualNetworkRule = new Collection <VirtualNetworkRule>();

            if (VirtualNetworkRule != null && VirtualNetworkRule.Length > 0)
            {
                foreach (string id in VirtualNetworkRule)
                {
                    virtualNetworkRule.Add(new VirtualNetworkRule(id: id));
                }
            }
            if (VirtualNetworkRuleObject != null && VirtualNetworkRuleObject.Length > 0)
            {
                foreach (PSVirtualNetworkRule psVirtualNetworkRule in VirtualNetworkRuleObject)
                {
                    virtualNetworkRule.Add(PSVirtualNetworkRule.ToSDKModel(psVirtualNetworkRule));
                }
            }

            DatabaseAccountCreateUpdateParameters databaseAccountCreateUpdateParameters = new DatabaseAccountCreateUpdateParameters(locations: LocationCollection, location: writeLocation, name: Name, consistencyPolicy: consistencyPolicy, tags: tags);

            databaseAccountCreateUpdateParameters.EnableMultipleWriteLocations       = EnableMultipleWriteLocations;
            databaseAccountCreateUpdateParameters.IsVirtualNetworkFilterEnabled      = EnableVirtualNetwork;
            databaseAccountCreateUpdateParameters.EnableAutomaticFailover            = EnableAutomaticFailover;
            databaseAccountCreateUpdateParameters.VirtualNetworkRules                = virtualNetworkRule;
            databaseAccountCreateUpdateParameters.DisableKeyBasedMetadataWriteAccess = DisableKeyBasedMetadataWriteAccess;
            databaseAccountCreateUpdateParameters.PublicNetworkAccess                = PublicNetworkAccess;
            databaseAccountCreateUpdateParameters.EnableFreeTier          = EnableFreeTier;
            databaseAccountCreateUpdateParameters.EnableAnalyticalStorage = EnableAnalyticalStorage;

            if (IpRule != null && IpRule.Length > 0)
            {
                databaseAccountCreateUpdateParameters.IpRules = base.PopulateIpRules(IpRule);
            }

            if (KeyVaultKeyUri != null)
            {
                databaseAccountCreateUpdateParameters.KeyVaultKeyUri = KeyVaultKeyUri;
            }

            if (!string.IsNullOrEmpty(ApiKind))
            {
                if (ApiKind.Equals("MongoDB", StringComparison.OrdinalIgnoreCase))
                {
                    if (ServerVersion != null)
                    {
                        databaseAccountCreateUpdateParameters.ApiProperties = new ApiProperties
                        {
                            ServerVersion = ServerVersion
                        };
                    }
                }
                else
                {
                    switch (ApiKind)
                    {
                    case "Cassandra":
                        databaseAccountCreateUpdateParameters.Capabilities = new List <Capability> {
                            new Capability {
                                Name = "EnableCassandra"
                            }
                        };
                        break;

                    case "Gremlin":
                        databaseAccountCreateUpdateParameters.Capabilities = new List <Capability> {
                            new Capability {
                                Name = "EnableGremlin"
                            }
                        };
                        break;

                    case "Table":
                        databaseAccountCreateUpdateParameters.Capabilities = new List <Capability> {
                            new Capability {
                                Name = "EnableTable"
                            }
                        };
                        break;

                    case "Sql":
                        break;
                    }

                    ApiKind = null;
                }
            }
            else
            {
                ApiKind = "GlobalDocumentDB";
            }

            databaseAccountCreateUpdateParameters.Kind = ApiKind;

            if (ShouldProcess(Name, "Creating Database Account"))
            {
                DatabaseAccountGetResults cosmosDBAccount = CosmosDBManagementClient.DatabaseAccounts.CreateOrUpdateWithHttpMessagesAsync(ResourceGroupName, Name, databaseAccountCreateUpdateParameters).GetAwaiter().GetResult().Body;
                WriteObject(new PSDatabaseAccountGetResults(cosmosDBAccount));
            }

            return;
        }
Пример #6
0
        public override void ExecuteCmdlet()
        {
            if (!ParameterSetName.Equals(NameParameterSet, StringComparison.Ordinal))
            {
                ResourceIdentifier resourceIdentifier = null;
                if (ParameterSetName.Equals(ResourceIdParameterSet, StringComparison.Ordinal))
                {
                    resourceIdentifier = new ResourceIdentifier(ResourceId);
                }
                else if (ParameterSetName.Equals(ObjectParameterSet, StringComparison.Ordinal))
                {
                    resourceIdentifier = new ResourceIdentifier(InputObject.Id);
                }
                ResourceGroupName = resourceIdentifier.ResourceGroupName;
                Name = resourceIdentifier.ResourceName;
            }

            DatabaseAccountGetResults readDatabase = CosmosDBManagementClient.DatabaseAccounts.GetWithHttpMessagesAsync(ResourceGroupName, Name).GetAwaiter().GetResult().Body;

            DatabaseAccountUpdateParameters databaseAccountUpdateParameters = new DatabaseAccountUpdateParameters(locations: readDatabase.Locations, location: readDatabase.WriteLocations.ElementAt(0).LocationName);

            if (EnableMultipleWriteLocations != null)
            {
                databaseAccountUpdateParameters.EnableMultipleWriteLocations = EnableMultipleWriteLocations;
            }
            if (EnableVirtualNetwork != null)
            {
                databaseAccountUpdateParameters.IsVirtualNetworkFilterEnabled = EnableVirtualNetwork;
            }
            if (EnableAutomaticFailover != null)
            {
                databaseAccountUpdateParameters.EnableAutomaticFailover = EnableAutomaticFailover;
            }
            if (DisableKeyBasedMetadataWriteAccess != null)
            {
                databaseAccountUpdateParameters.DisableKeyBasedMetadataWriteAccess = DisableKeyBasedMetadataWriteAccess;
            }
            if (PublicNetworkAccess != null)
            {
                databaseAccountUpdateParameters.PublicNetworkAccess = PublicNetworkAccess;
            }
            if (KeyVaultKeyUri != null)
            {
                databaseAccountUpdateParameters.KeyVaultKeyUri = KeyVaultKeyUri;
            }

            if (!string.IsNullOrEmpty(DefaultConsistencyLevel))
            {
                ConsistencyPolicy consistencyPolicy = new ConsistencyPolicy();
                {
                    switch (DefaultConsistencyLevel)
                    {
                    case "Strong":
                        consistencyPolicy.DefaultConsistencyLevel = Management.CosmosDB.Models.DefaultConsistencyLevel.Strong;
                        break;

                    case "Session":
                        consistencyPolicy.DefaultConsistencyLevel = Management.CosmosDB.Models.DefaultConsistencyLevel.Session;
                        break;

                    case "Eventual":
                        consistencyPolicy.DefaultConsistencyLevel = Management.CosmosDB.Models.DefaultConsistencyLevel.Eventual;
                        break;

                    case "ConsistentPrefix":
                        consistencyPolicy.DefaultConsistencyLevel = Management.CosmosDB.Models.DefaultConsistencyLevel.ConsistentPrefix;
                        break;

                    case "BoundedStaleness":
                        consistencyPolicy.DefaultConsistencyLevel = Management.CosmosDB.Models.DefaultConsistencyLevel.BoundedStaleness;
                        consistencyPolicy.MaxIntervalInSeconds    = MaxStalenessIntervalInSeconds;
                        consistencyPolicy.MaxStalenessPrefix      = MaxStalenessPrefix;
                        break;

                    default:
                        consistencyPolicy.DefaultConsistencyLevel = Management.CosmosDB.Models.DefaultConsistencyLevel.Session;
                        break;
                    }

                    databaseAccountUpdateParameters.ConsistencyPolicy = consistencyPolicy;
                }
            }

            if (Tag != null)
            {
                Dictionary <string, string> tags = new Dictionary <string, string>();

                foreach (string key in Tag.Keys)
                {
                    tags.Add(key, Tag[key].ToString());
                }

                databaseAccountUpdateParameters.Tags = tags;
            }

            if (VirtualNetworkRule != null || VirtualNetworkRuleObject != null)
            {
                Collection <VirtualNetworkRule> virtualNetworkRule = new Collection <VirtualNetworkRule>();
                if (VirtualNetworkRule != null && VirtualNetworkRule.Length > 0)
                {
                    foreach (string id in VirtualNetworkRule)
                    {
                        virtualNetworkRule.Add(new VirtualNetworkRule(id: id));
                    }
                }
                if (VirtualNetworkRuleObject != null && VirtualNetworkRuleObject.Length > 0)
                {
                    foreach (PSVirtualNetworkRule psVirtualNetworkRule in VirtualNetworkRuleObject)
                    {
                        virtualNetworkRule.Add(PSVirtualNetworkRule.ToSDKModel(psVirtualNetworkRule));
                    }
                }
                databaseAccountUpdateParameters.VirtualNetworkRules = virtualNetworkRule;
            }

            if (IpRangeFilter != null)
            {
                string IpRangeFilterAsString = IpRangeFilter?.Aggregate(string.Empty, (output, next) => string.Concat(output, (!string.IsNullOrWhiteSpace(output) && !string.IsNullOrWhiteSpace(next) ? "," : string.Empty), next)) ?? string.Empty;
                databaseAccountUpdateParameters.IpRangeFilter = IpRangeFilterAsString;
            }

            if (ShouldProcess(Name, "Updating Database Account"))
            {
                DatabaseAccountGetResults cosmosDBAccount = CosmosDBManagementClient.DatabaseAccounts.UpdateWithHttpMessagesAsync(ResourceGroupName, Name, databaseAccountUpdateParameters).GetAwaiter().GetResult().Body;
                WriteObject(new PSDatabaseAccountGetResults(cosmosDBAccount));
            }

            return;
        }
        public override void ExecuteCmdlet()
        {
            if (!ParameterSetName.Equals(NameParameterSet, StringComparison.Ordinal))
            {
                ResourceIdentifier resourceIdentifier = null;
                if (ParameterSetName.Equals(ResourceIdParameterSet, StringComparison.Ordinal))
                {
                    resourceIdentifier = new ResourceIdentifier(ResourceId);
                }
                else if (ParameterSetName.Equals(ObjectParameterSet, StringComparison.Ordinal))
                {
                    resourceIdentifier = new ResourceIdentifier(InputObject.Id);
                }
                ResourceGroupName = resourceIdentifier.ResourceGroupName;
                Name = resourceIdentifier.ResourceName;
            }

            DatabaseAccountGetResults readDatabase = CosmosDBManagementClient.DatabaseAccounts.GetWithHttpMessagesAsync(ResourceGroupName, Name).GetAwaiter().GetResult().Body;

            DatabaseAccountUpdateParameters databaseAccountUpdateParameters = new DatabaseAccountUpdateParameters(locations: readDatabase.ReadLocations, location: readDatabase.WriteLocations.ElementAt(0).LocationName);

            databaseAccountUpdateParameters.EnableMultipleWriteLocations  = EnableMultipleWriteLocations;
            databaseAccountUpdateParameters.IsVirtualNetworkFilterEnabled = EnableVirtualNetwork;
            databaseAccountUpdateParameters.EnableAutomaticFailover       = EnableAutomaticFailover;

            if (!string.IsNullOrEmpty(DefaultConsistencyLevel))
            {
                ConsistencyPolicy consistencyPolicy = new ConsistencyPolicy();
                {
                    switch (DefaultConsistencyLevel)
                    {
                    case "Strong":
                        consistencyPolicy.DefaultConsistencyLevel = Management.CosmosDB.Models.DefaultConsistencyLevel.Strong;
                        break;

                    case "Session":
                        consistencyPolicy.DefaultConsistencyLevel = Management.CosmosDB.Models.DefaultConsistencyLevel.Session;
                        break;

                    case "Eventual":
                        consistencyPolicy.DefaultConsistencyLevel = Management.CosmosDB.Models.DefaultConsistencyLevel.Eventual;
                        break;

                    case "ConsistentPrefix":
                        consistencyPolicy.DefaultConsistencyLevel = Management.CosmosDB.Models.DefaultConsistencyLevel.ConsistentPrefix;
                        break;

                    case "BoundedStaleness":
                        consistencyPolicy.DefaultConsistencyLevel = Management.CosmosDB.Models.DefaultConsistencyLevel.BoundedStaleness;
                        consistencyPolicy.MaxIntervalInSeconds    = MaxStalenessIntervalInSeconds;
                        consistencyPolicy.MaxStalenessPrefix      = MaxStalenessPrefix;
                        break;

                    default:
                        consistencyPolicy.DefaultConsistencyLevel = Management.CosmosDB.Models.DefaultConsistencyLevel.Session;
                        break;
                    }

                    databaseAccountUpdateParameters.ConsistencyPolicy = consistencyPolicy;
                }
            }

            if (Tag != null)
            {
                Dictionary <string, string> tags = new Dictionary <string, string>();

                foreach (string key in Tag.Keys)
                {
                    tags.Add(key, Tag[key].ToString());
                }

                databaseAccountUpdateParameters.Tags = tags;
            }

            if ((VirtualNetworkRule != null && VirtualNetworkRule.Length > 0) ||
                (VirtualNetworkRuleObject != null && VirtualNetworkRuleObject.Length > 0))
            {
                Collection <VirtualNetworkRule> virtualNetworkRule = new Collection <VirtualNetworkRule>();

                foreach (string id in VirtualNetworkRule)
                {
                    virtualNetworkRule.Add(new VirtualNetworkRule(id: id));
                }

                foreach (PSVirtualNetworkRule psVirtualNetworkRule in VirtualNetworkRuleObject)
                {
                    virtualNetworkRule.Add(PSVirtualNetworkRule.ConvertPSVirtualNetworkRuleToVirtualNetworkRule(psVirtualNetworkRule));
                }

                databaseAccountUpdateParameters.VirtualNetworkRules = virtualNetworkRule;
            }

            if (IpRangeFilter != null && IpRangeFilter.Length > 0)
            {
                string IpRangeFilterAsString = null;

                for (int i = 0; i < IpRangeFilter.Length; i++)
                {
                    if (i == 0)
                    {
                        IpRangeFilterAsString = IpRangeFilter[0];
                    }
                    else
                    {
                        IpRangeFilterAsString = string.Concat(IpRangeFilterAsString, ",", IpRangeFilter[i]);
                    }
                }

                databaseAccountUpdateParameters.IpRangeFilter = IpRangeFilterAsString;
            }

            if (ShouldProcess(Name, "Updating Database Account"))
            {
                DatabaseAccountGetResults cosmosDBAccount = CosmosDBManagementClient.DatabaseAccounts.UpdateWithHttpMessagesAsync(ResourceGroupName, Name, databaseAccountUpdateParameters).GetAwaiter().GetResult().Body;
                WriteObject(new PSDatabaseAccount(cosmosDBAccount));
            }

            return;
        }