Skip to content

Commit b505592

Browse files
adrianwellsCalebAlbers
adrianwells
authored andcommitted
Export itgluemodulesettings (#41) + Add Pester Tests
* Add Support for Passwords API With the release of API v1.8.0, a new Passwords endpoint was added. This update uncovers that endpoint in the PowerShell module with the addition of the following functions: - `New-ITGluePasswords` - `Get-ITGluePasswords` - `Set-ITGluePasswords` Release notes for the Passwords api are available [here](https://kb.itglue.com/hc/en-us/articles/360001797531-Release-Note s-1-8-0-API). —————— The Module Version was also updated to reflect the API version it supports. * Add support for EU API endpoints API endpoints have been added for deployments in the EU datacenter. This update uncovers the ability to use the EU API links by use of a `-data_center` (or `-dc`) option on the `Add-ITGlueBaseURI` function. This optional argument takes `EU` and `US` as options, however the US datacenter is still kept as the default even if no arguments are given. — HTTPS is also set by default for both the US and EU data centers. * Added enhanced filtering capability Most endpoints (especially Index/Show, and Update) now allow for expanded filtering capabilities. This updated exposes those new capabilities as command parameters. * Fixed Configurations Return Data Fixed a bug that was pointed out that caused incorrect data to be returned from the `Get-ITGlueConfigurations’ function. * Compatability Update All resources now match the current API spec given at https://api.itglue.com/developer. This includes enhanced bulk update, bulk destroy, and filtering capabilities. Thanks to @TheMattCollins0 for changes to make adding an API key via command line easier. * Added file to resolve Import-Module HRESULT: 0x8013104 * Update development branch with current proposed updates (#22) * Add Support for Passwords API With the release of API v1.8.0, a new Passwords endpoint was added. This update uncovers that endpoint in the PowerShell module with the addition of the following functions: - `New-ITGluePasswords` - `Get-ITGluePasswords` - `Set-ITGluePasswords` Release notes for the Passwords api are available [here](https://kb.itglue.com/hc/en-us/articles/360001797531-Release-Note s-1-8-0-API). —————— The Module Version was also updated to reflect the API version it supports. * Add support for EU API endpoints API endpoints have been added for deployments in the EU datacenter. This update uncovers the ability to use the EU API links by use of a `-data_center` (or `-dc`) option on the `Add-ITGlueBaseURI` function. This optional argument takes `EU` and `US` as options, however the US datacenter is still kept as the default even if no arguments are given. — HTTPS is also set by default for both the US and EU data centers. * Added enhanced filtering capability Most endpoints (especially Index/Show, and Update) now allow for expanded filtering capabilities. This updated exposes those new capabilities as command parameters. * Fixed Configurations Return Data Fixed a bug that was pointed out that caused incorrect data to be returned from the `Get-ITGlueConfigurations’ function. * Compatability Update All resources now match the current API spec given at https://api.itglue.com/developer. This includes enhanced bulk update, bulk destroy, and filtering capabilities. Thanks to @TheMattCollins0 for changes to make adding an API key via command line easier. * Added file to resolve Import-Module HRESULT: 0x8013104 * Support Nested Relationships Route for Show * Markdown formatting edits and update doc for additional commands * Markdown formatting edits * Intial check in of basic tests for the module * Expanded testing * Minor edits * Update Documents in Development branch (#25) * Markdown formatting edits and update doc for additional commands * Markdown formatting edits * Revert "Expanded testing" This reverts commit 6c8f31e. * Revert "Intial check in of basic tests for the module" This reverts commit ead9f25. * Corrected test for test files * Update to Current API Standards This update overhauls all endpoints to bring them current with the IT Glue API. Any and all filtering, options, and endpoints are covered. :warning: This is a **breaking** update. In order to better match the API docs that IT Glue presents at https://api.itglue.com/development, the `$data` input taken for module functions will *only* consist of the information present in the `data` array, rather than requiring what was effectively a `$body` request with a data array nested as a value. Some other styalistic choices were propogated throughout the code as well. For example, the `-important` parameter that some functions support now is a boolean. You no longer have to pass `0` or `1`, but can also pass `$true`, `$false`, or any other PowerShell boolean equivalent. * Minor ITGlueAPI.psd1 file edits (#27) * Markdown formatting edits and update doc for additional commands * Markdown formatting edits * Intial check in of basic tests for the module * Expanded testing * Minor edits * Revert "Expanded testing" This reverts commit 6c8f31e. * Revert "Intial check in of basic tests for the module" This reverts commit ead9f25. * Update to 2.0.0 The module version has been updated to `2.0.0`. From now on, Semantic Versioning (https://semver.org) should be followed on the module. Given a version number MAJOR.MINOR.PATCH, increment the: MAJOR version when you make incompatible API changes, MINOR version when you add functionality in a backwards-compatible manner, and PATCH version when you make backwards-compatible bug fixes. * Updated to test to remove a check due to changes in module * Minor to cleanup error caused by debug details * Implement Error Handling on REST Headers This implements the fix suggested by @ecspresso (thanks!!) and closes #29. Co-Authored-By: Emile <[email protected]> * Sync'ing master with 2.0.0 release * Minor edit * Inital Commit * Fix to remove variable correclty and minor spacing edits * Added Semantic Versioning guidance * Initial Commit * Fix Remove-ITGlueAPIKey and minor edits * Increment version for recent patch in APIKey.ps1 * Improve testing, add variables, and minor code formatting
1 parent 5c8bff6 commit b505592

File tree

6 files changed

+220
-19
lines changed

6 files changed

+220
-19
lines changed

ITGlueAPI/ITGlueAPI.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ RootModule = '.\ITGlueAPI.psm1'
1717
# -- MAJOR version when you make incompatible API changes,
1818
# -- MINOR version when you add functionality in a backwards-compatible manner, and
1919
# -- PATCH version when you make backwards-compatible bug fixes.
20-
ModuleVersion = '2.0.1'
20+
ModuleVersion = '2.0.2'
2121

2222
# ID used to uniquely identify this module
2323
#GUID = ''

ITGlueAPI/ITGlueAPI.psm1

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@ $ITGlue_Headers.Add("Content-Type", 'application/vnd.api+json')
33

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

6-
76
Import-ITGlueModuleSettings

ITGlueAPI/Internal/ModuleSettings.ps1

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
1-
function Export-ITGlueModuleSettings {
1+
# Locations of settings path and file
2+
$ITGlueAPIConfPath = "$($env:USERPROFILE)\ITGlueAPI"
3+
$ITGlueAPIConfFile = "config.psd1"
24

3-
$secureString = $ITGlue_API_KEY | ConvertFrom-SecureString
4-
$outputPath = "$($env:USERPROFILE)\ITGlueAPI"
5-
New-Item -ItemType Directory -Force -Path $outputPath | %{$_.Attributes = "hidden"}
5+
function Export-ITGlueModuleSettings {
6+
# Confirm variables exist and are not null before exporting
7+
if ($ITGlue_Base_URI -and $ITGlue_API_Key -and $ITGlue_JSON_Conversion_Depth) {
8+
$secureString = $ITGlue_API_KEY | ConvertFrom-SecureString
9+
New-Item -ItemType Directory -Force -Path $ITGlueAPIConfPath | ForEach-Object{$_.Attributes = "hidden"}
610
@"
711
@{
812
ITGlue_Base_URI = '$ITGlue_Base_URI'
913
ITGlue_API_Key = '$secureString'
1014
ITGlue_JSON_Conversion_Depth = '$ITGlue_JSON_Conversion_Depth'
1115
}
12-
"@ | Out-File -FilePath ($outputPath+"\config.psd1") -Force
13-
14-
16+
"@ | Out-File -FilePath ($ITGlueAPIConfPath+"\"+$ITGlueAPIConfFile) -Force
17+
}
18+
else {
19+
Write-Host "Failed export ITGlue Module settings to $ITGlueAPIConfPath\$ITGlueAPIConfFile"
20+
}
1521
}
1622

17-
18-
1923
function Import-ITGlueModuleSettings {
2024

21-
# PLEASE ADD ERROR CHECKING
25+
# PLEASE ADD ERROR CHECKING SUCH AS TESTING FOR VALID VARIABLES?
2226

23-
if(test-path "$($env:USERPROFILE)\ITGlueAPI") {
24-
$tmp_config = Import-LocalizedData -BaseDirectory "$($env:USERPROFILE)\ITGlueAPI" -FileName "config.psd1"
27+
if(test-path ($ITGlueAPIConfPath+"\"+$ITGlueAPIConfFile) ) {
28+
$tmp_config = Import-LocalizedData -BaseDirectory $ITGlueAPIConfPath -FileName $ITGlueAPIConfFile
2529

2630
# Send to function to strip potentially superflous slash (/)
2731
Add-ITGlueBaseURI $tmp_config.ITGlue_Base_URI
@@ -34,19 +38,19 @@ function Import-ITGlueModuleSettings {
3438
Set-Variable -Name "ITGlue_JSON_Conversion_Depth" -Value $tmp_config.ITGlue_JSON_Conversion_Depth `
3539
-Scope global -Force
3640

41+
Write-Host "ITGlueAPI Module configuration loaded successfully from $ITGlueAPIConfPath\$ITGlueAPIConfFile!" -ForegroundColor Green
42+
3743
# Clean things up
3844
Remove-Variable "tmp_config"
39-
40-
Write-Host "Module configuration loaded successfully!" -ForegroundColor Green
4145
}
4246
else {
43-
Write-Host "No configuration file was found." -ForegroundColor Red
47+
Write-Host "No configuration file was found at $ITGlueAPIConfPath\$ITGlueAPIConfFile." -ForegroundColor Red
4448

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

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

50-
Set-Variable -Name "ITGlue_JSON_Conversion_Depth" -Value 100 -Scope global -Force
54+
Set-Variable -Name "ITGlue_JSON_Conversion_Depth" -Value 100 -Scope global -Force
5155
}
5256
}

ITGlueAPI/Tests/APIKey.Tests.ps1

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#Requires -Modules Pester
2+
3+
# Obtain name of this file
4+
$ThisFile = $PSCommandPath -replace '\.Tests\.ps1$'
5+
$ThisFileName = $ThisFile | Split-Path -Leaf
6+
7+
Describe "Tests" {
8+
Context "Test $ThisFileName Functions" {
9+
It "ITGlue_API_Key should intially be empty or null" {
10+
$ITGlue_API_Key | Should -BeNullOrEmpty
11+
}
12+
It "Add-ITGlueAPIKey called with parameter ITGlue_API_Key should not be empty" {
13+
Add-ITGlueAPIKey -Api_Key "ITGAPIKEY"
14+
Get-ITGlueAPIKey | Should -Not -BeNullOrEmpty
15+
}
16+
It "Get-ITGlueAPIKey should return a value" {
17+
Get-ITGlueAPIKey | Should -Not -BeNullOrEmpty
18+
}
19+
It "Remove-ITGlueAPIKey should remove the ITGlue_API_Key variable" {
20+
Remove-ITGlueAPIKey
21+
Get-ITGlueAPIKey | Should -BeNullOrEmpty
22+
}
23+
}
24+
}

ITGlueAPI/Tests/BaseURI.Tests.ps1

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#Requires -Modules Pester
2+
3+
# Obtain name of this file
4+
$ThisFile = $PSCommandPath -replace '\.Tests\.ps1$'
5+
$ThisFileName = $ThisFile | Split-Path -Leaf
6+
7+
Describe "Tests" {
8+
Context "Test $ThisFileName Functions" {
9+
It "Add-ITGlueBaseURI without parameter should reutrn a valid URI" {
10+
Add-ITGlueBaseURI
11+
$BaseURI = Get-ITGlueBaseURI
12+
$BaseURI | Should -Be 'https://api.itglue.com'
13+
}
14+
It "Add-ITGlueBaseURI parameter US should reutrn a valid URI" {
15+
Add-ITGlueBaseURI -data_center 'US'
16+
$BaseURI = Get-ITGlueBaseURI
17+
$BaseURI | Should -Be 'https://api.itglue.com'
18+
}
19+
It "Add-ITGlueBaseURI parameter EU should reutrn a valid URI" {
20+
Add-ITGlueBaseURI -data_center 'EU'
21+
$BaseURI = Get-ITGlueBaseURI
22+
$BaseURI | Should -Be 'https://api.eu.itglue.com'
23+
}
24+
It "Remove-ITGlueBaseURI should remove the variable" {
25+
Remove-ITGlueBaseURI
26+
$BaseURI = Get-ITGlueBaseURI
27+
$BaseURI | Should -BeNullOrEmpty
28+
}
29+
}
30+
}

ITGlueAPI/Tests/ITGlueAPI.Tests.ps1

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
#Requires -Modules Pester
2+
3+
# Obtain name of this module by parsing name of test file (ITGlueAPI\Tests\ITGlueAPI.Tests.ps1)
4+
$ThisModule = $PSCommandPath -replace '\.Tests\.ps1$'
5+
$ThisModuleName = $ThisModule | Split-Path -Leaf
6+
7+
# Obtain path of the module based on location of test file (ITGlueAPI\Tests\ITGlueAPI.Tests.ps1)
8+
$ThisModulePath = Split-Path (Split-Path -Parent $PSCommandPath) -Parent
9+
10+
# Make sure one or multiple versions of the module are not loaded
11+
Get-Module -Name $ThisModuleName | Remove-Module
12+
13+
# Credit - borrowed with care from http://www.lazywinadmin.com/2016/05/using-pester-to-test-your-manifest-file.html and modified as needed
14+
# Manifest file path
15+
$ManifestFile = "$ThisModulePath\$ThisModuleName.psd1"
16+
17+
# Import the module and store the information about the module
18+
$ModuleInformation = Import-module -Name $ManifestFile -PassThru
19+
20+
# Internal Files
21+
$InternalDirectoryFiles = (
22+
'APIKey.ps1',
23+
'BaseURI.ps1',
24+
'ModuleSettings.ps1'
25+
)
26+
27+
# Resource Files
28+
$ResourceDirectoryFiles = (
29+
'ConfigurationInterfaces.ps1',
30+
'Configurations.ps1',
31+
'ConfigurationStatuses.ps1',
32+
'ConfigurationTypes.ps1',
33+
'Contacts.ps1',
34+
'ContactTypes.ps1',
35+
'Countries.ps1',
36+
'FlexibleAssetFields.ps1',
37+
'FlexibleAssets.ps1',
38+
'FlexibleAssetTypes.ps1',
39+
'Groups.ps1',
40+
'Locations.ps1',
41+
'Manufacturers.ps1',
42+
'Models.ps1',
43+
'OperatingSystems.ps1',
44+
'Organizations.ps1',
45+
'OrganizationStatuses.ps1',
46+
'OrganizationTypes.ps1',
47+
'PasswordCategories.ps1',
48+
'Passwords.ps1',
49+
'Platforms.ps1',
50+
'Regions.ps1',
51+
'UserMetrics.ps1',
52+
'Users.ps1'
53+
)
54+
55+
# Manifest Elements
56+
$ManifestFileElements = (
57+
'RootModule',
58+
'Author',
59+
'CompanyName',
60+
'Description',
61+
'Copyright',
62+
'PowerShellVersion',
63+
'NestedModules',
64+
'HelpInfoURI'
65+
)
66+
67+
Describe "Module Tests" {
68+
Context "Test $ThisModuleName Module" {
69+
It "has the root module $ThisModuleName.psm1" {
70+
"$ThisModulePath\$ThisModuleName.psm1" | Should Exist
71+
}
72+
73+
Context "Test Manifest File (.psd1)"{
74+
It "Should pass Test-ModuleManifest" {
75+
$errors = $null
76+
$errors = Test-ModuleManifest -Path $ThisModulePath\$ThisModuleName.psd1 -ErrorAction Stop
77+
$errors.Count | Should Be 1
78+
}
79+
80+
# Credit - borrowed with care from http://www.lazywinadmin.com/2016/05/using-pester-to-test-your-manifest-file.html and modified as needed
81+
ForEach ($ManifestFileElement in $ManifestFileElements) {
82+
It "Should contains $ManifestFileElement"{
83+
$ModuleInformation.$ManifestFileElement | Should not BeNullOrEmpty
84+
}
85+
}
86+
}
87+
88+
It "$ThisModuleName\Resources directory has functions" {
89+
"$ThisModulePath\Resources\*.ps1" | Should Exist
90+
}
91+
92+
# TODO - Only checking one file currently
93+
It "$ThisModuleName is valid PowerShell code" {
94+
$psFile = Get-Content -Path "$ThisModulePath\$ThisModuleName.psm1" -ErrorAction Stop
95+
$errors = $null
96+
$null = [System.Management.Automation.PSParser]::Tokenize($psfile, [ref]$errors)
97+
$errors.Count | Should Be 0
98+
}
99+
}
100+
101+
# Check that Internal files exist
102+
ForEach ($InternalFile in $InternalDirectoryFiles) {
103+
Context "Test $InternalFile Internal File in .\Internal directory" {
104+
It "$InternalFile should exist" {
105+
"$ThisModulePath\Internal\$InternalFile" | Should Exist
106+
}
107+
It "$InternalFile is valid PowerShell code" {
108+
$psFile = Get-Content -Path "$ThisModulePath\Internal\$InternalFile" -ErrorAction Stop
109+
$errors = $null
110+
$null = [System.Management.Automation.PSParser]::Tokenize($psfile, [ref]$errors)
111+
$errors.Count | Should Be 0
112+
}
113+
# Test for test files
114+
$InternalFileTest = $InternalFile -replace '\.ps1$'
115+
It "$InternalFileTest.Tests.ps1 should exist" {
116+
"$InternalFileTest.Tests.ps1" | Should Exist
117+
}
118+
}
119+
}
120+
121+
# Check that Resource files exist
122+
ForEach ($ResourceFile in $ResourceDirectoryFiles) {
123+
Context "Test $ResourceFile Resource File in .\Resources directory" {
124+
It "$ResourceFile should exist" {
125+
"$ThisModulePath\Resources\$ResourceFile" | Should Exist
126+
}
127+
It "$ResourceFile is valid PowerShell code" {
128+
$psFile = Get-Content -Path "$ThisModulePath\Resources\$ResourceFile" -ErrorAction Stop
129+
$errors = $null
130+
$null = [System.Management.Automation.PSParser]::Tokenize($psfile, [ref]$errors)
131+
$errors.Count | Should Be 0
132+
}
133+
}
134+
# TODO - add tests to check for tests files
135+
}
136+
137+
Context "PowerShell $ThisModuleName Import Test" {
138+
# Credit - borrowed with care from https://github.com/TheMattCollins0/MattTools/blob/master/Tests/ModuleImport.Tests.ps1 and modified as needed
139+
It "Should import PowerShell $ThisModuleName succesfully" {
140+
Import-Module -Name $ThisModulePath -ErrorVariable ImportError
141+
$ImportError | Should Be $null
142+
}
143+
}
144+
}

0 commit comments

Comments
 (0)