Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Get-ITGlueLogs & Added support for the Australian datacenter #139

Merged
merged 18 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion ITGlueAPI/ITGlueAPI.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
'Resources/FlexibleAssetTypes.ps1',
'Resources/Groups.ps1',
'Resources/Locations.ps1',
'Resources/Logs.ps1',
'Resources/Manufacturers.ps1',
'Resources/Models.ps1',
'Resources/OperatingSystems.ps1',
Expand Down Expand Up @@ -149,7 +150,7 @@
'Set-ITGlueDocuments',

'Get-ITGlueDomains',

'Get-ITGlueExpirations',

'New-ITGlueFlexibleAssetFields',
Expand All @@ -173,6 +174,8 @@
'Set-ITGlueLocations',
'Remove-ITGlueLocations',

'Get-ITGlueLogs',

'New-ITGlueManufacturers',
'Get-ITGlueManufacturers',
'Set-ITGlueManufacturers',
Expand Down
4 changes: 2 additions & 2 deletions ITGlueAPI/ITGlueAPI.psm1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$ITGlue_Headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$ITGlue_Headers.Add("Content-Type", 'application/vnd.api+json')
$ITGlue_Headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$ITGlue_Headers.Add("Content-Type", 'application/vnd.api+json')

Set-Variable -Name "ITGlue_Headers" -Value $ITGlue_Headers -Scope global

Expand Down
7 changes: 4 additions & 3 deletions ITGlueAPI/Internal/BaseURI.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,27 @@ function Add-ITGlueBaseURI {
[string]$base_uri = 'https://api.itglue.com',

[Alias('locale','dc')]
[ValidateSet( 'US', 'EU')]
[ValidateSet( 'US', 'EU', 'AU')]
[String]$data_center = ''
)

# Trim superflous forward slash from address (if applicable)
# Trim superfluous forward slash from address (if applicable)
if($base_uri[$base_uri.Length-1] -eq "/") {
$base_uri = $base_uri.Substring(0,$base_uri.Length-1)
}

switch ($data_center) {
'US' {$base_uri = 'https://api.itglue.com'}
'EU' {$base_uri = 'https://api.eu.itglue.com'}
'AU' {$base_uri = 'https://api.au.itglue.com'}
Default {}
}

Set-Variable -Name "ITGlue_Base_URI" -Value $base_uri -Option ReadOnly -Scope global -Force
}

function Remove-ITGlueBaseURI {
Remove-Variable -Name "ITGlue_Base_URI" -Scope global -Force
Remove-Variable -Name "ITGlue_Base_URI" -Scope global -Force
}

function Get-ITGlueBaseURI {
Expand Down
10 changes: 5 additions & 5 deletions ITGlueAPI/Internal/ModuleSettings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function Import-ITGlueModuleSettings {
if(test-path ($ITGlueAPIConfPath+"\"+$ITGlueAPIConfFile) ) {
$tmp_config = Import-LocalizedData -BaseDirectory $ITGlueAPIConfPath -FileName $ITGlueAPIConfFile

# Send to function to strip potentially superflous slash (/)
# Send to function to strip potentially superfluous slash (/)
Add-ITGlueBaseURI $tmp_config.ITGlue_Base_URI

$tmp_config.ITGlue_API_key = ConvertTo-SecureString $tmp_config.ITGlue_API_key
Expand All @@ -36,7 +36,7 @@ function Import-ITGlueModuleSettings {
-Option ReadOnly -Scope global -Force

Set-Variable -Name "ITGlue_JSON_Conversion_Depth" -Value $tmp_config.ITGlue_JSON_Conversion_Depth `
-Scope global -Force
-Scope global -Force

Write-Host "ITGlueAPI Module configuration loaded successfully from $ITGlueAPIConfPath\$ITGlueAPIConfFile!" -ForegroundColor Green

Expand All @@ -45,12 +45,12 @@ function Import-ITGlueModuleSettings {
}
else {
Write-Host "No configuration file was found at $ITGlueAPIConfPath\$ITGlueAPIConfFile." -ForegroundColor Red

Set-Variable -Name "ITGlue_Base_URI" -Value "https://api.itglue.com" -Option ReadOnly -Scope global -Force

Write-Host "Using https://api.itglue.com as Base URI. Run Add-ITGlueBaseURI to modify."
Write-Host "Please run Add-ITGlueAPIKey to get started." -ForegroundColor Red

Set-Variable -Name "ITGlue_JSON_Conversion_Depth" -Value 100 -Scope global -Force
}
}
12 changes: 6 additions & 6 deletions ITGlueAPI/Resources/Attachments.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function New-ITGlueAttachments {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true)]
[Parameter(Mandatory = $true)]
[ValidateSet( 'checklists', 'checklist_templates', 'configurations', 'contacts', 'documents', `
'domains', 'locations', 'passwords', 'ssl_certificates', 'flexible_assets', 'tickets')]
[string]$resource_type,
Expand Down Expand Up @@ -32,14 +32,14 @@ function New-ITGlueAttachments {
}

$data = @{}
$data = $rest_output
$data = $rest_output
return $data
}

function Set-ITGlueAttachments {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true)]
[Parameter(Mandatory = $true)]
[ValidateSet( 'checklists', 'checklist_templates', 'configurations', 'contacts', 'documents', `
'domains', 'locations', 'passwords', 'ssl_certificates', 'flexible_assets', 'tickets')]
[string]$resource_type,
Expand Down Expand Up @@ -74,14 +74,14 @@ function Set-ITGlueAttachments {
}

$data = @{}
$data = $rest_output
$data = $rest_output
return $data
}

function Remove-ITGlueAttachments {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true)]
[Parameter(Mandatory = $true)]
[ValidateSet( 'checklists', 'checklist_templates', 'configurations', 'contacts', 'documents', `
'domains', 'locations', 'passwords', 'ssl_certificates', 'flexible_assets', 'tickets')]
[string]$resource_type,
Expand Down Expand Up @@ -112,6 +112,6 @@ function Remove-ITGlueAttachments {
}

$data = @{}
$data = $rest_output
$data = $rest_output
return $data
}
2 changes: 1 addition & 1 deletion ITGlueAPI/Resources/Documents.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ function Set-ITGlueDocuments {
}

$data = @{}
$data = $rest_output
$data = $rest_output
return $data
}
2 changes: 1 addition & 1 deletion ITGlueAPI/Resources/Expirations.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function Get-ITGlueExpirations {

[Parameter(ParameterSetName = 'index')]
[String]$filter_expiration_date = '',

[Parameter(ParameterSetName = 'index')]
[Int64]$filter_organization_id = '',

Expand Down
106 changes: 106 additions & 0 deletions ITGlueAPI/Resources/Logs.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
function Get-ITGlueLogs {
<#
.SYNOPSIS
Get all activity logs of the account for the most recent 30 days.
.DESCRIPTION
The Get-ITGlueLogs cmdlet gets all activity logs of the account for the most recent 30 days.
This endpoint is limited to 5 pages of results. If more results are desired,
setting a larger page [size] will increase the number of results per page.
To iterate over even more results, use filter [created_at] (with created_at sort)
to fetch a subset of results based on timestamp, then use the last timestamp
in the last page the start date in the filter for the next request.
.PARAMETER sort
Sort the order of the returned data
Allowed values:
'created_at','-created_at'
.PARAMETER page_number
The page number to return data from
This endpoint is limited to 5 pages of results.
.PARAMETER page_size
The number of results to return with each page
By default ITGlues API returned the first 50 items.
Allowed values:
1 - 1000
.EXAMPLE
Get-ITGlueLogs
Pulls the first 50 activity logs from the last 30 days with data
being sorted newest to oldest.
.EXAMPLE
Get-ITGlueLogs -sort -created_at
Pulls the first 50 activity logs from the last 30 days with data
being sorted oldest to newest.
.EXAMPLE
Get-ITGlueLogs -page_number 2
Pulls the first 50 activity logs starting from page 2 from the last 30 days
with data being sorted newest to oldest.
.NOTES
As of 2022-11
Need to add in the "filter[created_at]" parameter
.LINK
https://api.itglue.com/developer/#logs
.LINK
https://github.com/itglue/powershellwrapper
#>

[CmdletBinding(DefaultParameterSetName = 'index')]
Param (
[Parameter(ParameterSetName = 'index')]
[ValidateSet( 'created_at','-created_at' )]
[String]$sort = '',

[Parameter(ParameterSetName = 'index')]
[Nullable[Int64]]$page_number = $null,

[Parameter(ParameterSetName = 'index')]
[ValidateRange ( 1, 1000 )]
[Nullable[int]]$page_size = $null
)

$resource_uri = '/logs'

if ($PSCmdlet.ParameterSetName -eq 'index') {
if ($sort) {
$body += @{'sort' = $sort}
}
if ($page_number) {
$body += @{'page[number]' = $page_number}
}
if ($page_size) {
$body += @{'page[size]' = $page_size}
}
}

try {
$ITGlue_Headers.Add('x-api-key', (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password)
$rest_output = Invoke-RestMethod -method 'GET' -uri ($ITGlue_Base_URI + $resource_uri) -headers $ITGlue_Headers `
-body $body -ErrorAction Stop -ErrorVariable web_error
} catch {
Write-Error $_
} finally {
[void] ($ITGlue_Headers.Remove('x-api-key')) # Quietly clean up scope so the API key doesn't persist
}

$data = @{}
$data = $rest_output
return $data
}
2 changes: 1 addition & 1 deletion ITGlueAPI/Resources/Organizations.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ function Get-ITGlueOrganizations {

[Parameter(ParameterSetName = 'index')]
[Nullable[Int64]]$filter_my_glue_account_id = $null,

[Parameter(ParameterSetName = 'index')]
[Nullable[Int64]]$filter_group_id = $null,

Expand Down
12 changes: 6 additions & 6 deletions ITGlueAPI/Resources/RelatedItems.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function New-ITGlueRelatedItems {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true)]
[Parameter(Mandatory = $true)]
[ValidateSet( 'checklists', 'checklist_templates', 'configurations', 'contacts', 'documents', `
'domains', 'locations', 'passwords', 'ssl_certificates', 'flexible_assets', 'tickets')]
[string]$resource_type,
Expand Down Expand Up @@ -32,14 +32,14 @@ function New-ITGlueRelatedItems {
}

$data = @{}
$data = $rest_output
$data = $rest_output
return $data
}

function Set-ITGlueRelatedItems {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true)]
[Parameter(Mandatory = $true)]
[ValidateSet( 'checklists', 'checklist_templates', 'configurations', 'contacts', 'documents', `
'domains', 'locations', 'passwords', 'ssl_certificates', 'flexible_assets', 'tickets')]
[string]$resource_type,
Expand Down Expand Up @@ -74,14 +74,14 @@ function Set-ITGlueRelatedItems {
}

$data = @{}
$data = $rest_output
$data = $rest_output
return $data
}

function Remove-ITGlueRelatedItems {
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true)]
[Parameter(Mandatory = $true)]
[ValidateSet( 'checklists', 'checklist_templates', 'configurations', 'contacts', 'documents', `
'domains', 'locations', 'passwords', 'ssl_certificates', 'flexible_assets', 'tickets')]
[string]$resource_type,
Expand Down Expand Up @@ -112,6 +112,6 @@ function Remove-ITGlueRelatedItems {
}

$data = @{}
$data = $rest_output
$data = $rest_output
return $data
}
11 changes: 8 additions & 3 deletions ITGlueAPI/Tests/BaseURI.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,26 @@ $ThisFileName = $ThisFile | Split-Path -Leaf

Describe "Tests" {
Context "Test $ThisFileName Functions" {
It "Add-ITGlueBaseURI without parameter should reutrn a valid URI" {
It "Add-ITGlueBaseURI without parameter should return a valid URI" {
Add-ITGlueBaseURI
$BaseURI = Get-ITGlueBaseURI
$BaseURI | Should -Be 'https://api.itglue.com'
}
It "Add-ITGlueBaseURI parameter US should reutrn a valid URI" {
It "Add-ITGlueBaseURI parameter US should return a valid URI" {
Add-ITGlueBaseURI -data_center 'US'
$BaseURI = Get-ITGlueBaseURI
$BaseURI | Should -Be 'https://api.itglue.com'
}
It "Add-ITGlueBaseURI parameter EU should reutrn a valid URI" {
It "Add-ITGlueBaseURI parameter EU should return a valid URI" {
Add-ITGlueBaseURI -data_center 'EU'
$BaseURI = Get-ITGlueBaseURI
$BaseURI | Should -Be 'https://api.eu.itglue.com'
}
It "Add-ITGlueBaseURI parameter AU should return a valid URI" {
Add-ITGlueBaseURI -data_center 'AU'
$BaseURI = Get-ITGlueBaseURI
$BaseURI | Should -Be 'https://api.au.itglue.com'
}
It "Remove-ITGlueBaseURI should remove the variable" {
Remove-ITGlueBaseURI
$BaseURI = Get-ITGlueBaseURI
Expand Down
5 changes: 3 additions & 2 deletions ITGlueAPI/Tests/ITGlueAPI.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ $ResourceDirectoryFiles = (
'FlexibleAssetTypes.ps1',
'Groups.ps1',
'Locations.ps1',
'Logs.ps1',
'Manufacturers.ps1',
'Models.ps1',
'OperatingSystems.ps1',
Expand Down Expand Up @@ -137,10 +138,10 @@ Describe "Module Tests" {
}
# TODO - add tests to check for tests files
}

Context "PowerShell $ThisModuleName Import Test" {
# Credit - borrowed with care from https://github.com/TheMattCollins0/MattTools/blob/master/Tests/ModuleImport.Tests.ps1 and modified as needed
It "Should import PowerShell $ThisModuleName succesfully" {
It "Should import PowerShell $ThisModuleName successfully" {
Import-Module -Name $ThisModulePath -ErrorVariable ImportError
$ImportError | Should Be $null
}
Expand Down