Ejemplo n.º 1
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);
        }
        /// <summary>
        /// Create a property pointing to an active key
        /// </summary>
        /// <param name="keyVaultUri">The Resource Uri to the KeyVault where the key is interned</param>
        /// <param name="keyVaultKeyUri">The absolute Uri to the key in the KeyVault</param>
        public DiskEncryptionSetProperties(ResourceUri keyVaultUri, string keyVaultKeyUri)
        {
            if ((!keyVaultUri.IsValid) || (!keyVaultUri.Is(ResourceUriCompareLevel.Provider, "Microsoft.KeyVault")) || (!keyVaultUri.Is(ResourceUriCompareLevel.Type, "vaults")))
            {
                throw new ArgumentException(nameof(keyVaultUri));
            }

            ActiveKey = new KeyVaultAndKeyReference()
            {
                Vault = new SourceVault()
                {
                    KeyVaultResourceId = keyVaultUri.ToString()
                },
                KeyUrl = keyVaultKeyUri
            };
        }
 internal EncryptionSettingsElement(KeyVaultAndSecretReference diskEncryptionKey, KeyVaultAndKeyReference keyEncryptionKey)
 {
     DiskEncryptionKey = diskEncryptionKey;
     KeyEncryptionKey  = keyEncryptionKey;
 }
Ejemplo n.º 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);
        }