Skip to content

Commit

Permalink
Begin work on ShouldProcess
Browse files Browse the repository at this point in the history
  • Loading branch information
TehMuffinMoo committed Jul 17, 2024
1 parent 3851fe4 commit 20dbb37
Show file tree
Hide file tree
Showing 29 changed files with 546 additions and 232 deletions.
23 changes: 15 additions & 8 deletions Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1APIKey.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
.PARAMETER id
The id of the API Key to filter by
.PARAMETER Force
Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Low.
.EXAMPLE
PS> Get-B1APIKey -User "user@domain.corp" -Name "somename" -Type "interactive" -State Enabled
Expand All @@ -53,6 +56,10 @@
.FUNCTIONALITY
Authentication
#>
[CmdletBinding(
SupportsShouldProcess,
ConfirmImpact = 'Low'
)]
param(
[String]$User,
[string]$CreatedBy,
Expand All @@ -67,9 +74,10 @@
[String[]]$Fields,
[String]$OrderBy,
$CustomFilters,
[String]$id
[String]$id,
[Switch]$Force
)

$ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters
[System.Collections.ArrayList]$Filters = @()
[System.Collections.ArrayList]$QueryFilters = @()
$MatchType = Match-Type $Strict
Expand Down Expand Up @@ -116,11 +124,10 @@
}

Write-DebugMsg -Filters $QueryFilters

$Results = Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/api_keys$QueryString" | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue -WarningAction SilentlyContinue

if ($Results) {
return $Results
if($PSCmdlet.ShouldProcess('List API Keys','List API Keys',$MyInvocation.MyCommand)){
$Results = Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/api_keys$QueryString" | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
if ($Results) {
return $Results
}
}

}
26 changes: 18 additions & 8 deletions Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1AuditLog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
Accepts either an Object, ArrayList or String containing one or more custom filters.
See here for usage: https://ibps.readthedocs.io/en/latest/#-customfilters
.PARAMETER Force
Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Low.
.EXAMPLE
PS> Get-B1AuditLog -Limit "25" -Offset "0" -Username "my.email@domain.com" -Method "POST" -Action "Create" -ClientIP "1.2.3.4" -ResponseCode "200"
Expand All @@ -58,6 +61,10 @@
.FUNCTIONALITY
Logs
#>
[CmdletBinding(
SupportsShouldProcess,
ConfirmImpact = 'Low'
)]
param(
[string]$Username,
[string]$ResourceType,
Expand All @@ -73,9 +80,10 @@
[String]$OrderBy,
[String[]]$Fields,
$CustomFilters,
[switch]$Strict
[switch]$Strict,
[Switch]$Force
)

$ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters
$Start = $Start.ToUniversalTime()
$End = $End.ToUniversalTime()

Expand Down Expand Up @@ -135,11 +143,13 @@
Write-DebugMsg -Filters $QueryFilters

if ($QueryString) {
$Results = Invoke-CSP -Uri "$(Get-B1CSPUrl)/api/auditlog/v1/logs$QueryString" -Method GET | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue
}
if ($Results) {
return $Results
} else {
return $null
if($PSCmdlet.ShouldProcess('Retrive Audit Log','Retrive Audit Log',$MyInvocation.MyCommand)){
$Results = Invoke-CSP -Uri "$(Get-B1CSPUrl)/api/auditlog/v1/logs$QueryString" -Method GET | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue
if ($Results) {
return $Results
} else {
return $null
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
.PARAMETER Fields
Specify a list of fields to return. The default is to return all fields.
.PARAMETER Force
Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Low.
.EXAMPLE
PS> Get-B1BulkOperation -Name "Backup of all CSP data"
Expand All @@ -27,12 +30,17 @@
.FUNCTIONALITY
Tasks
#>
[CmdletBinding(
SupportsShouldProcess,
ConfirmImpact = 'Low'
)]
param(
[string]$id,
[string]$Name,
[switch]$Strict = $false
[Switch]$Strict,
[Switch]$Force
)

$ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters
$MatchType = Match-Type $Strict
[System.Collections.ArrayList]$Filters = @()
[System.Collections.ArrayList]$QueryFilters = @()
Expand All @@ -52,9 +60,11 @@

Write-DebugMsg -Filters $QueryFilters

if ($QueryString) {
Invoke-CSP -Method "GET" -Uri "$(Get-B1CSPUrl)/bulk/v1/operation$QueryString" | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
} else {
Invoke-CSP -Method "GET" -Uri "$(Get-B1CSPUrl)/bulk/v1/operation" | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
if($PSCmdlet.ShouldProcess('Query Bulk Operations','Query Bulk Operations',$MyInvocation.MyCommand)){
if ($QueryString) {
Invoke-CSP -Method "GET" -Uri "$(Get-B1CSPUrl)/bulk/v1/operation$QueryString" | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
} else {
Invoke-CSP -Method "GET" -Uri "$(Get-B1CSPUrl)/bulk/v1/operation" | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
.PARAMETER Account
Using the -Account switch will return the account data associated with the current user
.PARAMETER Force
Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Low.
.EXAMPLE
PS> Get-B1CSPCurrentUser
Expand All @@ -24,22 +27,36 @@
.FUNCTIONALITY
Authentication
#>
[CmdletBinding(DefaultParameterSetName = 'None')]
[CmdletBinding(
DefaultParameterSetName = 'None',
SupportsShouldProcess,
ConfirmImpact = 'Low'
)]
param(
[Parameter(ParameterSetName="Groups")]
[Switch]$Groups,
[Parameter(ParameterSetName="Account")]
[Switch]$Account,
[Parameter(ParameterSetName="Compartments")]
[Switch]$Compartments
[Switch]$Compartments,
[Switch]$Force
)
$ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters
if ($Groups) {
Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/current_user/groups" | Select-Object -ExpandProperty results
if($PSCmdlet.ShouldProcess("List The Current CSP User`'s Groups","List Current CSP User`'s Groups",$MyInvocation.MyCommand)){
Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/current_user/groups" | Select-Object -ExpandProperty results
}
} elseif ($Account) {
Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/current_user/accounts" | Select-Object -ExpandProperty results
if($PSCmdlet.ShouldProcess("List The Current CSP User`'s Accounts","List Current CSP User`'s Accounts",$MyInvocation.MyCommand)){
Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/current_user/accounts" | Select-Object -ExpandProperty results
}
} elseif ($Compartments) {
Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/current_user/compartments" | Select-Object -ExpandProperty results
if($PSCmdlet.ShouldProcess("List The Current CSP User`'s Compartments","List Current CSP User`'s Compartments",$MyInvocation.MyCommand)){
Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/current_user/compartments" | Select-Object -ExpandProperty results
}
} else {
Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/current_user" | Select-Object -ExpandProperty result
if($PSCmdlet.ShouldProcess("List The Current CSP User`'s Details","List Current CSP User`'s Details",$MyInvocation.MyCommand)){
Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/current_user" | Select-Object -ExpandProperty result
}
}
}
20 changes: 15 additions & 5 deletions Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1Compartment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
.PARAMETER id
The id of the API Key to filter by
.PARAMETER Force
Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Low.
.EXAMPLE
PS> Get-B1APIKey -User "user@domain.corp" -Name "somename" -Type "interactive" -State Enabled
Expand All @@ -40,6 +43,10 @@
.FUNCTIONALITY
Authentication
#>
[CmdletBinding(
SupportsShouldProcess,
ConfirmImpact = 'Low'
)]
param(
[String]$Name,
[Int]$Limit,
Expand All @@ -48,9 +55,10 @@
[String[]]$Fields,
[String]$OrderBy,
$CustomFilters,
[String]$id
[String]$id,
[Switch]$Force
)

$ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters
[System.Collections.ArrayList]$Filters = @()
[System.Collections.ArrayList]$QueryFilters = @()
$MatchType = Match-Type $Strict
Expand Down Expand Up @@ -84,8 +92,10 @@
$QueryString = ConvertTo-QueryString $QueryFilters
}
Write-DebugMsg -Filters $QueryFilters
$Results = Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/compartments$QueryString" | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
if ($Results) {
return $Results
if($PSCmdlet.ShouldProcess('List Compartments','List Compartments',$MyInvocation.MyCommand)){
$Results = Invoke-CSP -Method GET -Uri "$(Get-B1CSPUrl)/v2/compartments$QueryString" | Select-Object -ExpandProperty results -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
if ($Results) {
return $Results
}
}
}
24 changes: 17 additions & 7 deletions Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1DFPLog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
.PARAMETER Offset
Use this parameter to offset the results by the value entered for the purpose of pagination
.PARAMETER Force
Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Low.
.EXAMPLE
PS> Get-B1DFPLog -IP "10.10.132.10" -Query "google.com" -Type "A" -Response "216.58.201.110" -Start (Get-Date).AddHours(-6) -End (Get-Date) -Limit 1000 -Offset 0
Expand All @@ -51,6 +54,10 @@
.FUNCTIONALITY
Logs
#>
[CmdletBinding(
SupportsShouldProcess,
ConfirmImpact = 'Low'
)]
param(
[string]$Query,
[string]$IP,
Expand All @@ -63,9 +70,10 @@
[ValidateSet('asc','desc')]
[String]$Order = 'asc',
[int]$Limit = 100,
[int]$Offset = 0
[int]$Offset = 0,
[Switch]$Force
)

$ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters
$Cube = 'PortunusDnsLogs'

$Dimensions = @(
Expand Down Expand Up @@ -158,10 +166,12 @@
}
}

$Result = Invoke-B1CubeJS -Cube $($Cube) -Dimensions $Dimensions -TimeDimension timestamp -Start $Start -End $End -Limit $Limit -Offset $Offset -Filters $Filters -OrderBy $OrderBy -Order $Order
if ($Result) {
return $Result
} else {
Write-Host "Error: No DNS logs returned." -ForegroundColor Red
if($PSCmdlet.ShouldProcess("Query the DNS Activity Logs","Query the DNS Activity Logs",$MyInvocation.MyCommand)){
$Result = Invoke-B1CubeJS -Cube $($Cube) -Dimensions $Dimensions -TimeDimension timestamp -Start $Start -End $End -Limit $Limit -Offset $Offset -Filters $Filters -OrderBy $OrderBy -Order $Order
if ($Result) {
return $Result
} else {
Write-Host "Error: No DNS logs returned." -ForegroundColor Red
}
}
}
26 changes: 18 additions & 8 deletions Modules/ibPS/Functions/BloxOne/BloxOneCloud/Get-B1DHCPLog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
.PARAMETER Offset
Use this parameter to offset the results by the value entered for the purpose of pagination
.PARAMETER Force
Perform the operation without prompting for confirmation. By default, this function will not prompt for confirmation unless $ConfirmPreference is set to Low.
.EXAMPLE
PS> Get-B1DHCPLog -Hostname "dhcpclient.mydomain.corp" -State "Assignments" -IP "10.10.10.100" -Protocol "IPv4 Address" -DHCPServer "bloxoneddihost1.mydomain.corp" -Start (Get-Date).AddHours(-24) -End (Get-Date) -Limit 100 -Offset 0
Expand All @@ -54,6 +57,10 @@
.FUNCTIONALITY
DHCP
#>
[CmdletBinding(
SupportsShouldProcess,
ConfirmImpact = 'Low'
)]
param(
[string]$Hostname,
[string]$State,
Expand All @@ -67,12 +74,13 @@
[ValidateSet('asc','desc')]
[String]$Order = 'asc',
[int]$Limit = 100,
[int]$Offset = 0
[int]$Offset = 0,
[Switch]$Force
)

$ConfirmPreference = Confirm-ShouldProcess $PSBoundParameters
$Cube = 'NstarLeaseActivity'

## Replace with CubeJS Query
## Replace with CubeJS Query?
$DHCPHostQuery = Get-B1DHCPHost -Limit 2500 -Fields id,name
$DHCPHosts += $DHCPHostQuery
if ($DHCPHostQuery.count -eq 2500) {
Expand Down Expand Up @@ -177,10 +185,12 @@
}
}

$Result = Invoke-B1CubeJS -Cube $($Cube) -Dimensions $Dimensions -TimeDimension timestamp -Start $Start -End $End -Limit $Limit -Offset $Offset -Filters $Filters -OrderBy $OrderBy -Order $Order
if ($Result) {
return $Result | Select-Object @{name="dhcp_server";Expression={Match-DHCPHost -id $_.'host_id'}},*
} else {
Write-Host "Error: No DHCP logs returned." -ForegroundColor Red
if($PSCmdlet.ShouldProcess("Query the DHCP Logs","Query the DHCP Logs",$MyInvocation.MyCommand)){
$Result = Invoke-B1CubeJS -Cube $($Cube) -Dimensions $Dimensions -TimeDimension timestamp -Start $Start -End $End -Limit $Limit -Offset $Offset -Filters $Filters -OrderBy $OrderBy -Order $Order
if ($Result) {
return $Result | Select-Object @{name="dhcp_server";Expression={Match-DHCPHost -id $_.'host_id'}},*
} else {
Write-Host "Error: No DHCP logs returned." -ForegroundColor Red
}
}
}
Loading

0 comments on commit 20dbb37

Please sign in to comment.