Skip to content

Commit c4341a0

Browse files
author
Adrian Wells
committed
Improve testing, add variables, and minor code formatting
1 parent cd7914b commit c4341a0

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-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
}

0 commit comments

Comments
 (0)