示例#1
0
        internal static MhsmPrivateEndpointConnectionData DeserializeMhsmPrivateEndpointConnectionData(JsonElement element)
        {
            Optional <string>            etag              = default;
            Optional <ManagedHsmSku>     sku               = default;
            Optional <SystemData>        systemData        = default;
            IDictionary <string, string> tags              = default;
            Location                       location        = default;
            ResourceIdentifier             id              = default;
            string                         name            = default;
            ResourceType                   type            = default;
            Optional <MhsmPrivateEndpoint> privateEndpoint = default;
            Optional <MhsmPrivateLinkServiceConnectionState>      privateLinkServiceConnectionState = default;
            Optional <PrivateEndpointConnectionProvisioningState> provisioningState = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("etag"))
                {
                    etag = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("sku"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    sku = ManagedHsmSku.DeserializeManagedHsmSku(property.Value);
                    continue;
                }
                if (property.NameEquals("systemData"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    systemData = SystemData.DeserializeSystemData(property.Value);
                    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 = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("id"))
                {
                    id = 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("privateEndpoint"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            privateEndpoint = MhsmPrivateEndpoint.DeserializeMhsmPrivateEndpoint(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("privateLinkServiceConnectionState"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            privateLinkServiceConnectionState = MhsmPrivateLinkServiceConnectionState.DeserializeMhsmPrivateLinkServiceConnectionState(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("provisioningState"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            provisioningState = new PrivateEndpointConnectionProvisioningState(property0.Value.GetString());
                            continue;
                        }
                    }
                    continue;
                }
            }
            return(new MhsmPrivateEndpointConnectionData(id, name, type, tags, location, sku.Value, systemData.Value, etag.Value, privateEndpoint.Value, privateLinkServiceConnectionState.Value, Optional.ToNullable(provisioningState)));
        }
示例#2
0
        internal static ManagedHsmData DeserializeManagedHsmData(JsonElement element)
        {
            Optional <ManagedHsmProperties> properties = default;
            Optional <ManagedHsmSku>        sku        = default;
            Optional <SystemData>           systemData = default;
            IDictionary <string, string>    tags       = default;
            Location           location = default;
            ResourceIdentifier id       = default;
            string             name     = default;
            ResourceType       type     = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("properties"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    properties = ManagedHsmProperties.DeserializeManagedHsmProperties(property.Value);
                    continue;
                }
                if (property.NameEquals("sku"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    sku = ManagedHsmSku.DeserializeManagedHsmSku(property.Value);
                    continue;
                }
                if (property.NameEquals("systemData"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    systemData = SystemData.DeserializeSystemData(property.Value);
                    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 = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("id"))
                {
                    id = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("name"))
                {
                    name = property.Value.GetString();
                    continue;
                }
                if (property.NameEquals("type"))
                {
                    type = property.Value.GetString();
                    continue;
                }
            }
            return(new ManagedHsmData(id, name, type, tags, location, sku.Value, systemData.Value, properties.Value));
        }
        /// <summary>
        /// Create a Managed HSM pool
        /// </summary>
        /// <param name="parameters">vault creation parameters</param>
        /// <param name="adClient">the active directory client</param>
        /// <returns></returns>
        public PSManagedHsm CreateNewManagedHsm(VaultCreationOrUpdateParameters parameters, ActiveDirectoryClient adClient = null)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            if (string.IsNullOrWhiteSpace(parameters.Name))
            {
                throw new ArgumentNullException("parameters.Name");
            }
            if (string.IsNullOrWhiteSpace(parameters.ResourceGroupName))
            {
                throw new ArgumentNullException("parameters.ResourceGroupName");
            }
            if (string.IsNullOrWhiteSpace(parameters.Location))
            {
                throw new ArgumentNullException("parameters.Location");
            }
            if (parameters.Administrator.Length == 0)
            {
                throw new ArgumentNullException("parameters.Administrator");
            }

            var properties    = new ManagedHsmProperties();
            var managedHsmSku = new ManagedHsmSku();

            if (parameters.CreateMode != CreateMode.Recover)
            {
                if (string.IsNullOrWhiteSpace(parameters.SkuFamilyName))
                {
                    throw new ArgumentNullException("parameters.SkuFamilyName");
                }
                if (parameters.TenantId == Guid.Empty)
                {
                    throw new ArgumentException("parameters.TenantId");
                }
                if (!string.IsNullOrWhiteSpace(parameters.SkuName))
                {
                    if (Enum.TryParse(parameters.SkuName, true, out ManagedHsmSkuName skuName))
                    {
                        managedHsmSku.Name = skuName;
                    }
                    else
                    {
                        throw new InvalidEnumArgumentException("parameters.SkuName");
                    }
                }
                properties.TenantId = parameters.TenantId;
                properties.InitialAdminObjectIds = parameters.Administrator;
                properties.HsmUri                    = "";
                properties.EnableSoftDelete          = parameters.EnableSoftDelete;
                properties.SoftDeleteRetentionInDays = parameters.SoftDeleteRetentionInDays;
                properties.EnablePurgeProtection     = parameters.EnablePurgeProtection;
            }
            else
            {
                properties.CreateMode = CreateMode.Recover;
            }

            var response = KeyVaultManagementClient.ManagedHsms.CreateOrUpdate(
                resourceGroupName: parameters.ResourceGroupName,
                name: parameters.Name,
                parameters: new ManagedHsm
            {
                Location   = parameters.Location,
                Sku        = managedHsmSku,
                Tags       = TagsConversionHelper.CreateTagDictionary(parameters.Tags, validate: true),
                Properties = properties
            });

            return(new PSManagedHsm(response, adClient));
        }
示例#4
0
 internal MhsmPrivateEndpointConnectionData(ResourceIdentifier id, string name, ResourceType resourceType, SystemData systemData, IDictionary <string, string> tags, AzureLocation location, ManagedHsmSku sku, string etag, SubResource privateEndpoint, MhsmPrivateLinkServiceConnectionState privateLinkServiceConnectionState, PrivateEndpointConnectionProvisioningState?provisioningState) : base(id, name, resourceType, systemData, tags, location, sku)
 {
     Etag            = etag;
     PrivateEndpoint = privateEndpoint;
     PrivateLinkServiceConnectionState = privateLinkServiceConnectionState;
     ProvisioningState = provisioningState;
 }
 internal ManagedHsmData(ResourceIdentifier id, string name, ResourceType resourceType, SystemData systemData, IDictionary <string, string> tags, AzureLocation location, ManagedHsmSku sku, ManagedHsmProperties properties) : base(id, name, resourceType, systemData, tags, location, sku)
 {
     Properties = properties;
 }