/// <summary>
        /// Factory method to create AzureRmSqlManagedInstanceKeyVaultKeyModel from ManagedInstanceKey
        /// </summary>
        /// <param name="managedInstanceKey"></param>
        /// <param name="resourceGroupName"></param>
        /// <param name="managedInstanceName"></param>
        /// <returns></returns>
        public static AzureRmSqlManagedInstanceKeyVaultKeyModel FromManagedInstanceKey(ManagedInstanceKey managedInstanceKey, string resourceGroupName, string managedInstanceName)
        {
            ServerKeyType skType = ServerKeyType.AzureKeyVault;

            Enum.TryParse <ServerKeyType>(managedInstanceKey.ServerKeyType, out skType);

            AzureRmSqlManagedInstanceKeyVaultKeyModel key = new AzureRmSqlManagedInstanceKeyVaultKeyModel()
            {
                ResourceGroupName   = resourceGroupName,
                ManagedInstanceName = managedInstanceName,
                KeyId = managedInstanceKey.Uri,
                ManagedInstanceKeyName = managedInstanceKey.Name,
                Type         = skType,
                Thumbprint   = managedInstanceKey.Thumbprint,
                CreationDate = skType == ServerKeyType.AzureKeyVault ? managedInstanceKey.CreationDate : null
            };

            return(key);
        }
Ejemplo n.º 2
0
        internal static EncryptionProtectorData DeserializeEncryptionProtectorData(JsonElement element)
        {
            Optional <string>        kind                = default;
            Optional <string>        location            = default;
            ResourceIdentifier       id                  = default;
            string                   name                = default;
            ResourceType             type                = default;
            SystemData               systemData          = default;
            Optional <string>        subregion           = default;
            Optional <string>        serverKeyName       = default;
            Optional <ServerKeyType> serverKeyType       = default;
            Optional <Uri>           uri                 = default;
            Optional <string>        thumbprint          = default;
            Optional <bool>          autoRotationEnabled = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("kind"))
                {
                    kind = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("location"))
                {
                    location = 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("subregion"))
                        {
                            subregion = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("serverKeyName"))
                        {
                            serverKeyName = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("serverKeyType"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            serverKeyType = new ServerKeyType(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("uri"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                uri = null;
                                continue;
                            }
                            uri = new Uri(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("thumbprint"))
                        {
                            thumbprint = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("autoRotationEnabled"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            autoRotationEnabled = property0.Value.GetBoolean();
                            continue;
                        }
                    }
                    continue;
                }
            }
            return(new EncryptionProtectorData(id, name, type, systemData, kind.Value, location.Value, subregion.Value, serverKeyName.Value, Optional.ToNullable(serverKeyType), uri.Value, thumbprint.Value, Optional.ToNullable(autoRotationEnabled)));
        }
        internal static ManagedInstanceKeyData DeserializeManagedInstanceKeyData(JsonElement element)
        {
            Optional <string>         kind                = default;
            ResourceIdentifier        id                  = default;
            string                    name                = default;
            ResourceType              type                = default;
            Optional <ServerKeyType>  serverKeyType       = default;
            Optional <string>         uri                 = default;
            Optional <string>         thumbprint          = default;
            Optional <DateTimeOffset> creationDate        = default;
            Optional <bool>           autoRotationEnabled = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("kind"))
                {
                    kind = 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 = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("properties"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    foreach (var property0 in property.Value.EnumerateObject())
                    {
                        if (property0.NameEquals("serverKeyType"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            serverKeyType = new ServerKeyType(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("uri"))
                        {
                            uri = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("thumbprint"))
                        {
                            thumbprint = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("creationDate"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            creationDate = property0.Value.GetDateTimeOffset("O");
                            continue;
                        }
                        if (property0.NameEquals("autoRotationEnabled"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            autoRotationEnabled = property0.Value.GetBoolean();
                            continue;
                        }
                    }
                    continue;
                }
            }
            return(new ManagedInstanceKeyData(id, name, type, kind.Value, Optional.ToNullable(serverKeyType), uri.Value, thumbprint.Value, Optional.ToNullable(creationDate), Optional.ToNullable(autoRotationEnabled)));
        }