Ejemplo n.º 1
0
        public override void ExecuteCmdlet()
        {
            switch (ParameterSetName)
            {
            case ParameterSetNames.SubscriptionScope:
                var tors = SecurityCenterClient.AllowedConnections.ListWithHttpMessagesAsync().GetAwaiter().GetResult().Body;
                WriteObject(tors.ConvertToPSType(), enumerateCollection: true);
                break;

            case ParameterSetNames.ResourceGroupLevelResource:
                SecurityCenterClient.AscLocation = Location;

                var tor = SecurityCenterClient.AllowedConnections.GetWithHttpMessagesAsync(ResourceGroupName, Name).GetAwaiter().GetResult().Body;
                WriteObject(tor.ConvertToPSType(), enumerateCollection: false);
                break;

            case ParameterSetNames.ResourceId:
                SecurityCenterClient.AscLocation = AzureIdUtilities.GetResourceLocation(ResourceId);

                tor = SecurityCenterClient.AllowedConnections.GetWithHttpMessagesAsync(AzureIdUtilities.GetResourceGroup(ResourceId), AzureIdUtilities.GetResourceName(ResourceId)).GetAwaiter().GetResult().Body;
                WriteObject(tor.ConvertToPSType(), enumerateCollection: false);
                break;

            default:
                throw new PSInvalidOperationException();
            }
        }
Ejemplo n.º 2
0
        public override void ExecuteCmdlet()
        {
            switch (ParameterSetName)
            {
            case ParameterSetNames.SubscriptionScope:
                var apsl = SecurityCenterClient.Compliances.ListWithHttpMessagesAsync(GetScope()).GetAwaiter().GetResult().Body;
                WriteObject(apsl.ConvertToPSType(), enumerateCollection: true);
                break;

            case ParameterSetNames.SubscriptionLevelResource:
                SecurityCenterClient.AscLocation = SecurityCenterClient.Locations.ListWithHttpMessagesAsync().GetAwaiter().GetResult().Body.First().Name;

                var aps = SecurityCenterClient.Compliances.GetWithHttpMessagesAsync(GetScope(), Name).GetAwaiter().GetResult().Body;
                WriteObject(aps.ConvertToPSType(), enumerateCollection: false);
                break;

            case ParameterSetNames.ResourceId:
                SecurityCenterClient.AscLocation = AzureIdUtilities.GetResourceLocation(ResourceId);

                aps = SecurityCenterClient.Compliances.GetWithHttpMessagesAsync(GetScope(AzureIdUtilities.GetResourceSubscription(ResourceId)), AzureIdUtilities.GetResourceName(ResourceId)).GetAwaiter().GetResult().Body;
                WriteObject(aps.ConvertToPSType(), enumerateCollection: false);
                break;

            default:
                throw new PSInvalidOperationException();
            }
        }
Ejemplo n.º 3
0
        public override void ExecuteCmdlet()
        {
            switch (ParameterSetName)
            {
            case ParameterSetNames.SubscriptionScope:
                var tasks = SecurityCenterClient.Tasks.ListWithHttpMessagesAsync().GetAwaiter().GetResult().Body;
                WriteObject(tasks.ConvertToPSType(), enumerateCollection: true);
                break;

            case ParameterSetNames.ResourceGroupScope:
                SecurityCenterClient.AscLocation = SecurityCenterClient.Locations.ListWithHttpMessagesAsync().GetAwaiter().GetResult().Body.First().Name;

                tasks = SecurityCenterClient.Tasks.ListByResourceGroupWithHttpMessagesAsync(ResourceGroupName).GetAwaiter().GetResult().Body;
                WriteObject(tasks.ConvertToPSType(), enumerateCollection: true);
                break;

            case ParameterSetNames.SubscriptionLevelResource:
                SecurityCenterClient.AscLocation = SecurityCenterClient.Locations.ListWithHttpMessagesAsync().GetAwaiter().GetResult().Body.First().Name;

                var task = SecurityCenterClient.Tasks.GetSubscriptionLevelTaskWithHttpMessagesAsync(Name).GetAwaiter().GetResult().Body;
                WriteObject(task.ConvertToPSType());
                break;

            case ParameterSetNames.ResourceGroupLevelResource:
                SecurityCenterClient.AscLocation = SecurityCenterClient.Locations.ListWithHttpMessagesAsync().GetAwaiter().GetResult().Body.First().Name;

                task = SecurityCenterClient.Tasks.GetResourceGroupLevelTaskWithHttpMessagesAsync(ResourceGroupName, Name).GetAwaiter().GetResult().Body;
                WriteObject(task.ConvertToPSType());
                break;

            case ParameterSetNames.ResourceId:
                SecurityCenterClient.AscLocation = AzureIdUtilities.GetResourceLocation(ResourceId);

                var rg = AzureIdUtilities.GetResourceGroup(ResourceId);

                if (string.IsNullOrEmpty(rg))
                {
                    task = SecurityCenterClient.Tasks.GetSubscriptionLevelTaskWithHttpMessagesAsync(AzureIdUtilities.GetResourceName(ResourceId)).GetAwaiter().GetResult().Body;
                }
                else
                {
                    task = SecurityCenterClient.Tasks.GetResourceGroupLevelTaskWithHttpMessagesAsync(rg, AzureIdUtilities.GetResourceName(ResourceId)).GetAwaiter().GetResult().Body;
                }

                WriteObject(task.ConvertToPSType());
                break;

            default:
                throw new PSInvalidOperationException();
            }
        }
        public override void ExecuteCmdlet()
        {
            var name     = Name;
            var rg       = ResourceGroupName;
            var location = Location;

            switch (ParameterSetName)
            {
            case ParameterSetNames.ResourceGroupLevelResource:
                break;

            case ParameterSetNames.ResourceId:
                location = AzureIdUtilities.GetResourceLocation(ResourceId);;

                name = AzureIdUtilities.GetResourceName(ResourceId);
                rg   = AzureIdUtilities.GetResourceGroup(ResourceId);
                break;

            case ParameterSetNames.InputObject:
                name     = InputObject.Name;
                rg       = AzureIdUtilities.GetResourceGroup(InputObject.Id);
                location = AzureIdUtilities.GetResourceLocation(InputObject.Id);
                break;

            default:
                throw new PSInvalidOperationException();
            }

            if (ShouldProcess(name, VerbsCommon.Set))
            {
                SecurityCenterClient.AscLocation = location;
                SecurityCenterClient.JitNetworkAccessPolicies.DeleteWithHttpMessagesAsync(rg, name).GetAwaiter().GetResult();
            }

            if (PassThru.IsPresent)
            {
                WriteObject(true);
            }
        }
        public override void ExecuteCmdlet()
        {
            var name     = Name;
            var location = Location;
            var rgName   = ResourceGroupName;
            var vms      = VirtualMachine;

            switch (ParameterSetName)
            {
            case "ResourceGroupLevelResource":
                break;

            case "ResourceId":
                name     = AzureIdUtilities.GetResourceName(ResourceId);
                location = AzureIdUtilities.GetResourceLocation(ResourceId);
                rgName   = AzureIdUtilities.GetResourceGroup(ResourceId);
                break;

            case "InputObject":
                name     = InputObject.Name;
                location = InputObject.Location;
                rgName   = InputObject.ResourceGroupName;
                vms      = InputObject.VirtualMachine;
                break;

            default:
                throw new PSInvalidOperationException();
            }

            if (ShouldProcess(name, "Start"))
            {
                SecurityCenterClient.AscLocation = location;
                var aps = SecurityCenterClient.JitNetworkAccessPolicies.InitiateWithHttpMessagesAsync(rgName, name, vms.ConvertToCSType()).GetAwaiter().GetResult().Body;
                WriteObject(aps.ConvertToPSType(), enumerateCollection: false);
            }
        }
Ejemplo n.º 6
0
        public override void ExecuteCmdlet()
        {
            var rg         = ResourceGroupName;
            var name       = Name;
            var actionType = ActionType;
            var location   = Location;
            var status     = "";

            switch (ParameterSetName)
            {
            case ParameterSetNames.SubscriptionLevelResource:
            case ParameterSetNames.ResourceGroupLevelResource:
                break;

            case ParameterSetNames.ResourceId:
                location = AzureIdUtilities.GetResourceLocation(ResourceId);
                name     = AzureIdUtilities.GetResourceName(ResourceId);
                break;

            case ParameterSetNames.InputObject:
                status   = InputObject.State;
                name     = InputObject.Name;
                rg       = AzureIdUtilities.GetResourceGroup(InputObject.Id);
                location = AzureIdUtilities.GetResourceLocation(InputObject.Id);
                break;

            case ParameterSetNames.InputObjectV3:
                status   = InputObjectV3.Status;
                name     = InputObjectV3.Name;
                rg       = AzureIdUtilities.GetResourceGroup(InputObjectV3.Id);
                location = AzureIdUtilities.GetResourceLocation(InputObjectV3.Id);
                break;

            default:
                throw new PSInvalidOperationException();
            }

            if (!string.IsNullOrEmpty(status))
            {
                switch (status.ToLower())
                {
                case "dismissed":
                    actionType = "Dismiss";
                    break;

                case "active":
                    actionType = "Activate";
                    break;

                case "resolved":
                    actionType = "Resolve";
                    break;

                default:
                    break;
                }
            }

            SecurityCenterClient.AscLocation = location;

            if (string.IsNullOrEmpty(rg))
            {
                if (ShouldProcess(name, VerbsCommon.Set))
                {
                    if (actionType == "Dismiss")
                    {
                        SecurityCenterClient.Alerts.UpdateSubscriptionLevelStateToDismissWithHttpMessagesAsync(name).GetAwaiter().GetResult();
                    }
                    else if (actionType == "Activate")
                    {
                        SecurityCenterClient.Alerts.UpdateSubscriptionLevelStateToActivateWithHttpMessagesAsync(name).GetAwaiter().GetResult();
                    }
                    else if (actionType == "Resolve")
                    {
                        SecurityCenterClient.Alerts.UpdateSubscriptionLevelStateToResolveWithHttpMessagesAsync(name).GetAwaiter().GetResult();
                    }
                }
            }
            else
            {
                if (ShouldProcess(name, VerbsCommon.Set))
                {
                    if (actionType == "Dismiss")
                    {
                        SecurityCenterClient.Alerts.UpdateResourceGroupLevelStateToDismissWithHttpMessagesAsync(name, rg).GetAwaiter().GetResult();
                    }
                    else if (actionType == "Activate")
                    {
                        SecurityCenterClient.Alerts.UpdateResourceGroupLevelStateToActivateWithHttpMessagesAsync(name, rg).GetAwaiter().GetResult();
                    }
                    else if (actionType == "Resolve")
                    {
                        SecurityCenterClient.Alerts.UpdateResourceGroupLevelStateToResolveWithHttpMessagesAsync(name, rg).GetAwaiter().GetResult();
                    }
                }
            }

            if (PassThru.IsPresent)
            {
                WriteObject(true);
            }
        }
Ejemplo n.º 7
0
        public override void ExecuteCmdlet()
        {
            int    numberOfFetchedAlerts = 0;
            string nextLink = null;

            switch (ParameterSetName)
            {
            case ParameterSetNames.SubscriptionScope:
                var alerts       = SecurityCenterClient.Alerts.ListWithHttpMessagesAsync().GetAwaiter().GetResult().Body;
                var PSTypeAlerts = alerts.ConvertToPSType();
                WriteObject(PSTypeAlerts, enumerateCollection: true);
                numberOfFetchedAlerts += PSTypeAlerts.Count;
                nextLink = alerts?.NextPageLink;
                while (!string.IsNullOrWhiteSpace(nextLink) && numberOfFetchedAlerts < MaxAlertsToFetch)
                {
                    alerts       = SecurityCenterClient.Alerts.ListNextWithHttpMessagesAsync(alerts.NextPageLink).GetAwaiter().GetResult().Body;
                    PSTypeAlerts = alerts.ConvertToPSType();
                    WriteObject(PSTypeAlerts, enumerateCollection: true);
                    numberOfFetchedAlerts += PSTypeAlerts.Count;
                    nextLink = alerts?.NextPageLink;
                }
                break;

            case ParameterSetNames.ResourceGroupScope:
                alerts       = SecurityCenterClient.Alerts.ListByResourceGroupWithHttpMessagesAsync(ResourceGroupName).GetAwaiter().GetResult().Body;
                PSTypeAlerts = alerts.ConvertToPSType();
                WriteObject(PSTypeAlerts, enumerateCollection: true);
                numberOfFetchedAlerts += PSTypeAlerts.Count;
                nextLink = alerts?.NextPageLink;
                while (!string.IsNullOrWhiteSpace(nextLink) && numberOfFetchedAlerts < MaxAlertsToFetch)
                {
                    alerts       = SecurityCenterClient.Alerts.ListNextWithHttpMessagesAsync(alerts.NextPageLink).GetAwaiter().GetResult().Body;
                    PSTypeAlerts = alerts.ConvertToPSType();
                    WriteObject(PSTypeAlerts, enumerateCollection: true);
                    numberOfFetchedAlerts += PSTypeAlerts.Count;
                    nextLink = alerts?.NextPageLink;
                }
                break;

            case ParameterSetNames.SubscriptionLevelResource:
                SecurityCenterClient.AscLocation = Location;
                var alert = SecurityCenterClient.Alerts.GetSubscriptionLevelWithHttpMessagesAsync(Name).GetAwaiter().GetResult().Body;
                WriteObject(alert.ConvertToPSType(), enumerateCollection: false);
                break;

            case ParameterSetNames.ResourceGroupLevelResource:
                SecurityCenterClient.AscLocation = Location;
                alert = SecurityCenterClient.Alerts.GetResourceGroupLevelWithHttpMessagesAsync(Name, ResourceGroupName).GetAwaiter().GetResult().Body;
                WriteObject(alert.ConvertToPSType(), enumerateCollection: false);
                break;

            case ParameterSetNames.ResourceId:
                SecurityCenterClient.AscLocation = AzureIdUtilities.GetResourceLocation(ResourceId);

                var rg = AzureIdUtilities.GetResourceGroup(ResourceId);

                if (string.IsNullOrEmpty(rg))
                {
                    alert = SecurityCenterClient.Alerts.GetSubscriptionLevelWithHttpMessagesAsync(AzureIdUtilities.GetResourceName(ResourceId)).GetAwaiter().GetResult().Body;
                }
                else
                {
                    alert = SecurityCenterClient.Alerts.GetResourceGroupLevelWithHttpMessagesAsync(AzureIdUtilities.GetResourceName(ResourceId), rg).GetAwaiter().GetResult().Body;
                }

                WriteObject(alert.ConvertToPSType(), enumerateCollection: false);
                break;

            default:
                throw new PSInvalidOperationException();
            }
        }