示例#1
0
 internal DiskEncryptionSetData(ResourceIdentifier id, string name, ResourceType type, IDictionary <string, string> tags, AzureLocation location, EncryptionSetIdentity identity, DiskEncryptionSetType?encryptionType, KeyForDiskEncryptionSet activeKey, IReadOnlyList <KeyForDiskEncryptionSet> previousKeys, string provisioningState, bool?rotationToLatestKeyVersionEnabled, DateTimeOffset?lastKeyRotationTimestamp) : base(id, name, type, tags, location)
 {
     Identity          = identity;
     EncryptionType    = encryptionType;
     ActiveKey         = activeKey;
     PreviousKeys      = previousKeys;
     ProvisioningState = provisioningState;
     RotationToLatestKeyVersionEnabled = rotationToLatestKeyVersionEnabled;
     LastKeyRotationTimestamp          = lastKeyRotationTimestamp;
 }
示例#2
0
        private void Run()
        {
            // Identity
            EncryptionSetIdentity vIdentity = null;

            // ActiveKey
            KeyVaultAndKeyReference vActiveKey = null;

            if (this.IsParameterBound(c => c.IdentityType))
            {
                if (vIdentity == null)
                {
                    vIdentity = new EncryptionSetIdentity();
                }
                vIdentity.Type = this.IdentityType;
            }

            if (this.IsParameterBound(c => c.SourceVaultId))
            {
                if (vActiveKey == null)
                {
                    vActiveKey = new KeyVaultAndKeyReference();
                }
                if (vActiveKey.SourceVault == null)
                {
                    vActiveKey.SourceVault = new SourceVault();
                }
                vActiveKey.SourceVault.Id = this.SourceVaultId;
            }

            if (this.IsParameterBound(c => c.KeyUrl))
            {
                if (vActiveKey == null)
                {
                    vActiveKey = new KeyVaultAndKeyReference();
                }
                vActiveKey.KeyUrl = this.KeyUrl;
            }

            var vDiskEncryptionSet = new PSDiskEncryptionSet
            {
                Location       = this.IsParameterBound(c => c.Location) ? this.Location : null,
                Tags           = this.IsParameterBound(c => c.Tag) ? this.Tag.Cast <DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value) : null,
                EncryptionType = this.IsParameterBound(c => c.EncryptionType) ? this.EncryptionType : null,
                Identity       = vIdentity,
                ActiveKey      = vActiveKey,
                RotationToLatestKeyVersionEnabled = this.IsParameterBound(c => c.RotationToLatestKeyVersionEnabled) ? this.RotationToLatestKeyVersionEnabled : null
            };

            WriteObject(vDiskEncryptionSet);
        }
示例#3
0
        internal static DiskEncryptionSetData DeserializeDiskEncryptionSetData(JsonElement element)
        {
            Optional <EncryptionSetIdentity> identity = default;
            IDictionary <string, string>     tags     = default;
            AzureLocation      location = default;
            ResourceIdentifier id       = default;
            string             name     = default;
            ResourceType       type     = default;
            Optional <DiskEncryptionSetType>   encryptionType = default;
            Optional <KeyForDiskEncryptionSet> activeKey      = default;
            Optional <IReadOnlyList <KeyForDiskEncryptionSet> > previousKeys = default;
            Optional <string>         provisioningState = default;
            Optional <bool>           rotationToLatestKeyVersionEnabled = default;
            Optional <DateTimeOffset> lastKeyRotationTimestamp          = default;
            Optional <ApiError>       autoKeyRotationError = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("identity"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    identity = EncryptionSetIdentity.DeserializeEncryptionSetIdentity(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 = 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("encryptionType"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            encryptionType = new DiskEncryptionSetType(property0.Value.GetString());
                            continue;
                        }
                        if (property0.NameEquals("activeKey"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            activeKey = KeyForDiskEncryptionSet.DeserializeKeyForDiskEncryptionSet(property0.Value);
                            continue;
                        }
                        if (property0.NameEquals("previousKeys"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            List <KeyForDiskEncryptionSet> array = new List <KeyForDiskEncryptionSet>();
                            foreach (var item in property0.Value.EnumerateArray())
                            {
                                array.Add(KeyForDiskEncryptionSet.DeserializeKeyForDiskEncryptionSet(item));
                            }
                            previousKeys = array;
                            continue;
                        }
                        if (property0.NameEquals("provisioningState"))
                        {
                            provisioningState = property0.Value.GetString();
                            continue;
                        }
                        if (property0.NameEquals("rotationToLatestKeyVersionEnabled"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            rotationToLatestKeyVersionEnabled = property0.Value.GetBoolean();
                            continue;
                        }
                        if (property0.NameEquals("lastKeyRotationTimestamp"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            lastKeyRotationTimestamp = property0.Value.GetDateTimeOffset("O");
                            continue;
                        }
                        if (property0.NameEquals("autoKeyRotationError"))
                        {
                            if (property0.Value.ValueKind == JsonValueKind.Null)
                            {
                                property0.ThrowNonNullablePropertyIsNull();
                                continue;
                            }
                            autoKeyRotationError = ApiError.DeserializeApiError(property0.Value);
                            continue;
                        }
                    }
                    continue;
                }
            }
            return(new DiskEncryptionSetData(id, name, type, tags, location, identity.Value, Optional.ToNullable(encryptionType), activeKey.Value, Optional.ToList(previousKeys), provisioningState.Value, Optional.ToNullable(rotationToLatestKeyVersionEnabled), Optional.ToNullable(lastKeyRotationTimestamp), autoKeyRotationError.Value));
        }
示例#4
0
        private void Run()
        {
            // Identity
            EncryptionSetIdentity vIdentity = null;

            // ActiveKey
            KeyVaultAndKeyReference vActiveKey = null;

            if (this.IsParameterBound(c => c.IdentityType))
            {
                if (vIdentity == null)
                {
                    vIdentity = new EncryptionSetIdentity();
                }
                vIdentity.Type = this.IdentityType;
            }

            if (this.IsParameterBound(c => c.SourceVaultId))
            {
                if (vActiveKey == null)
                {
                    vActiveKey = new KeyVaultAndKeyReference();
                }
                if (vActiveKey.SourceVault == null)
                {
                    vActiveKey.SourceVault = new SourceVault();
                }
                vActiveKey.SourceVault.Id = this.SourceVaultId;
            }

            if (this.IsParameterBound(c => c.KeyUrl))
            {
                if (vActiveKey == null)
                {
                    vActiveKey = new KeyVaultAndKeyReference();
                }
                vActiveKey.KeyUrl = this.KeyUrl;
            }

            if (this.IsParameterBound(c => c.UserAssignedIdentity))
            {
                if (vIdentity == null)
                {
                    vIdentity = new EncryptionSetIdentity();
                }
                if (vIdentity.UserAssignedIdentities == null)
                {
                    vIdentity.UserAssignedIdentities = new Dictionary <string, EncryptionSetIdentityUserAssignedIdentitiesValue>();
                }

                foreach (DictionaryEntry de in this.UserAssignedIdentity)
                {
                    if (((Hashtable)de.Value).Count == 0)
                    {
                        vIdentity.UserAssignedIdentities.Add(de.Key.ToString(), new EncryptionSetIdentityUserAssignedIdentitiesValue());
                    }
                    else
                    {
                        string principalId = ((Hashtable)de.Value)["principalId"]?.ToString();
                        string clientId    = ((Hashtable)de.Value)["clientId"]?.ToString();
                        vIdentity.UserAssignedIdentities.Add(de.Key.ToString(), new EncryptionSetIdentityUserAssignedIdentitiesValue(principalId, clientId));
                    }
                }
            }

            var vDiskEncryptionSet = new PSDiskEncryptionSet
            {
                Location       = this.IsParameterBound(c => c.Location) ? this.Location : null,
                Tags           = this.IsParameterBound(c => c.Tag) ? this.Tag.Cast <DictionaryEntry>().ToDictionary(ht => (string)ht.Key, ht => (string)ht.Value) : null,
                EncryptionType = this.IsParameterBound(c => c.EncryptionType) ? this.EncryptionType : null,
                Identity       = vIdentity,
                ActiveKey      = vActiveKey,
                RotationToLatestKeyVersionEnabled = this.IsParameterBound(c => c.RotationToLatestKeyVersionEnabled) ? this.RotationToLatestKeyVersionEnabled : null,
                FederatedClientId = this.IsParameterBound(c => c.FederatedClientId) ? this.FederatedClientId : null
            };

            WriteObject(vDiskEncryptionSet);
        }