예제 #1
0
 public PSRoleDefinition RemoveRoleDefinition(FilterRoleDefinitionOptions options)
 {
     if (options.RoleDefinitionId != Guid.Empty)
     {
         return(this.RemoveRoleDefinition(options.RoleDefinitionId, options.Scope));
     }
     else if (!string.IsNullOrEmpty(options.RoleDefinitionName))
     {
         return(this.RemoveRoleDefinition(options.RoleDefinitionName, options.Scope));
     }
     else
     {
         throw new InvalidOperationException("RoleDefinition Name or Id should be specified.");
     }
 }
        public override void ExecuteCmdlet()
        {
            FilterRoleDefinitionOptions options = new FilterRoleDefinitionOptions
            {
                CustomOnly = Custom.IsPresent ? true : false,
                ScopeAndBelow = AtScopeAndBelow.IsPresent ? true : false,
                Scope = Scope,
                ResourceIdentifier = new ResourceIdentifier
                {
                    Subscription = DefaultProfile.Context.Subscription.Id.ToString()
                },
                RoleDefinitionId = Id,
                RoleDefinitionName = Name,
            };

            WriteObject(PoliciesClient.FilterRoleDefinitions(options), enumerateCollection: true);
        }
 public List<PSRoleDefinition> FilterRoleDefinitions(FilterRoleDefinitionOptions options)
 {
     if (options.RoleDefinitionId != Guid.Empty)
     {
         return new List<PSRoleDefinition> { GetRoleDefinition(options.RoleDefinitionId, options.Scope) };
     }
     else if(options.CustomOnly)
     {
         // Special case - if custom only flag is specified then you don't need to lookup on a specific id or name since it will be a bit redundant
         return FilterRoleDefinitionsByCustom(options.Scope, options.ScopeAndBelow);
     }
     else
     {
         // If RoleDefinition name is not specified (null/empty), service will handle it and return all roles
         return FilterRoleDefinitions(options.RoleDefinitionName, options.Scope, options.ScopeAndBelow);
     }
 }
        public override void ExecuteCmdlet()
        {
            PSRoleDefinition roleDefinition = null;
            string confirmMessage = null;

            if (Id != Guid.Empty)
            {
                confirmMessage = string.Format(ProjectResources.RemoveRoleDefinition, Id);
            }
            else
            {
                confirmMessage = string.Format(ProjectResources.RemoveRoleDefinitionWithName, Name);
            }

            FilterRoleDefinitionOptions options = new FilterRoleDefinitionOptions
            {
                RoleDefinitionId = Id,
                RoleDefinitionName = Name,
                Scope = Scope,
                ResourceIdentifier = new ResourceIdentifier
                {
                    Subscription = DefaultProfile.Context.Subscription.Id.ToString()
                }
            };

            Action action = (() => roleDefinition = PoliciesClient.RemoveRoleDefinition(options));

            ConfirmAction(
                Force.IsPresent,
                confirmMessage,
                ProjectResources.RemoveRoleDefinition,
                Id.ToString(),
                action);

            if (PassThru)
            {
                WriteObject(roleDefinition);
            }
        }
 public PSRoleDefinition RemoveRoleDefinition(FilterRoleDefinitionOptions options)
 {
     if (options.RoleDefinitionId != Guid.Empty)
     {
         return this.RemoveRoleDefinition(options.RoleDefinitionId, options.Scope);
     }
     else if(!string.IsNullOrEmpty(options.RoleDefinitionName))
     {
         return this.RemoveRoleDefinition(options.RoleDefinitionName, options.Scope);
     }
     else
     {
         throw new InvalidOperationException("RoleDefinition Name or Id should be specified.");
     }
 }
 public List<PSRoleDefinition> FilterRoleDefinitions(FilterRoleDefinitionOptions options)
 {
     if (options.RoleDefinitionId != Guid.Empty)
     {
         return new List<PSRoleDefinition> { GetRoleDefinition(options.RoleDefinitionId, options.Scope) };
     }
     else if(options.CustomOnly)
     {
         // Special case - if custom only flag is specified then you don't need to lookup on a specific id or name since it will be a bit redundant
         return FilterRoleDefinitionsByCustom(options.Scope, options.ScopeAndBelow);
     }
     else
     {
         // If RoleDefinition name is not specified (null/empty), service will handle it and return all roles
         return FilterRoleDefinitions(options.RoleDefinitionName, options.Scope, options.ScopeAndBelow);
     }
 }