public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            ExecuteClientAction(() =>
            {
                string resourceGroupName     = this.ResourceGroupName;
                string diskEncryptionSetName = this.Name;

                if (ShouldGetByName(resourceGroupName, diskEncryptionSetName))
                {
                    var result   = DiskEncryptionSetsClient.Get(resourceGroupName, diskEncryptionSetName);
                    var psObject = new PSDiskEncryptionSet();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <DiskEncryptionSet, PSDiskEncryptionSet>(result, psObject);
                    WriteObject(psObject);
                }
                else if (ShouldListByResourceGroup(resourceGroupName, diskEncryptionSetName))
                {
                    var result       = DiskEncryptionSetsClient.ListByResourceGroup(resourceGroupName);
                    var resultList   = result.ToList();
                    var nextPageLink = result.NextPageLink;
                    while (!string.IsNullOrEmpty(nextPageLink))
                    {
                        var pageResult = DiskEncryptionSetsClient.ListByResourceGroupNext(nextPageLink);
                        foreach (var pageItem in pageResult)
                        {
                            resultList.Add(pageItem);
                        }
                        nextPageLink = pageResult.NextPageLink;
                    }
                    var psObject = new List <PSDiskEncryptionSetList>();
                    foreach (var r in resultList)
                    {
                        psObject.Add(ComputeAutomationAutoMapperProfile.Mapper.Map <DiskEncryptionSet, PSDiskEncryptionSetList>(r));
                    }
                    WriteObject(TopLevelWildcardFilter(resourceGroupName, diskEncryptionSetName, psObject), true);
                }
                else
                {
                    var result       = DiskEncryptionSetsClient.List();
                    var resultList   = result.ToList();
                    var nextPageLink = result.NextPageLink;
                    while (!string.IsNullOrEmpty(nextPageLink))
                    {
                        var pageResult = DiskEncryptionSetsClient.ListNext(nextPageLink);
                        foreach (var pageItem in pageResult)
                        {
                            resultList.Add(pageItem);
                        }
                        nextPageLink = pageResult.NextPageLink;
                    }
                    var psObject = new List <PSDiskEncryptionSetList>();
                    foreach (var r in resultList)
                    {
                        psObject.Add(ComputeAutomationAutoMapperProfile.Mapper.Map <DiskEncryptionSet, PSDiskEncryptionSetList>(r));
                    }
                    WriteObject(TopLevelWildcardFilter(resourceGroupName, diskEncryptionSetName, psObject), true);
                }
            });
        }
Exemple #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);
        }
Exemple #3
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            ExecuteClientAction(() =>
            {
                if (ShouldProcess(this.Name, VerbsData.Update))
                {
                    string resourceGroupName;
                    string diskEncryptionSetName;
                    switch (this.ParameterSetName)
                    {
                    case "ResourceIdParameter":
                        resourceGroupName     = GetResourceGroupName(this.ResourceId);
                        diskEncryptionSetName = GetResourceName(this.ResourceId, "Microsoft.Compute/diskEncryptionSets");
                        break;

                    case "ObjectParameter":
                        resourceGroupName     = GetResourceGroupName(this.InputObject.Id);
                        diskEncryptionSetName = GetResourceName(this.InputObject.Id, "Microsoft.Compute/diskEncryptionSets");
                        break;

                    default:
                        resourceGroupName     = this.ResourceGroupName;
                        diskEncryptionSetName = this.Name;
                        break;
                    }

                    if (this.InputObject == null)
                    {
                        BuildPatchObject();
                    }
                    else
                    {
                        BuildPutObject();
                    }
                    DiskEncryptionSetUpdate diskEncryptionSetupdate = this.DiskEncryptionSetUpdate;
                    DiskEncryptionSet parameter = new DiskEncryptionSet();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <PSDiskEncryptionSet, DiskEncryptionSet>(this.InputObject, parameter);

                    var result = (this.DiskEncryptionSetUpdate == null)
                                 ? DiskEncryptionSetsClient.CreateOrUpdate(resourceGroupName, diskEncryptionSetName, parameter)
                                 : DiskEncryptionSetsClient.Update(resourceGroupName, diskEncryptionSetName, diskEncryptionSetupdate);
                    var psObject = new PSDiskEncryptionSet();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <DiskEncryptionSet, PSDiskEncryptionSet>(result, psObject);
                    WriteObject(psObject);
                }
            });
        }
Exemple #4
0
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();
            ExecuteClientAction(() =>
            {
                if (ShouldProcess(this.Name, VerbsCommon.New))
                {
                    string resourceGroupName            = this.ResourceGroupName;
                    string diskEncryptionSetName        = this.Name;
                    DiskEncryptionSet diskEncryptionSet = new DiskEncryptionSet();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <PSDiskEncryptionSet, DiskEncryptionSet>(this.InputObject, diskEncryptionSet);

                    var result   = DiskEncryptionSetsClient.CreateOrUpdate(resourceGroupName, diskEncryptionSetName, diskEncryptionSet);
                    var psObject = new PSDiskEncryptionSet();
                    ComputeAutomationAutoMapperProfile.Mapper.Map <DiskEncryptionSet, PSDiskEncryptionSet>(result, psObject);
                    WriteObject(psObject);
                }
            });
        }
Exemple #5
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);
        }