Skip to content

Commit a27a426

Browse files
v2.0.0 Release (#28)
* 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 * Update Documents in Development branch (#25) * Markdown formatting edits and update doc for additional commands * Markdown formatting edits * 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. * Implement Error Handling on REST Headers This implements the fix suggested by @ecspresso (thanks!!) and closes #29. Co-Authored-By: Emile <[email protected]>
1 parent e5eb23c commit a27a426

30 files changed

+2169
-529
lines changed

CONTRIBUTING.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
1-
## How to contribute to this module
1+
# How to contribute to this module
22

3-
#### **Did you find a bug?**
3+
## **Did you find a bug?**
44

55
* **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/itglue/powershellwrapper/issues).
66

77
* If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/itglue/powershellwrapper/issues/new). Be sure to include a **title and clear description**, as much relevant information as possible, and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring.
88

9-
#### **Did you write a patch that fixes a bug?**
9+
## **Did you write a patch that fixes a bug?**
1010

11-
* Open a new GitHub pull request with the patch.
11+
* Open a new GitHub pull request (PR) with the patch.
1212

1313
* Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable.
1414

15-
#### **Do you intend to add a new feature or change an existing one?**
15+
## **Do you intend to add a new feature or change an existing one?**
1616

1717
* Suggest your change by creating a GitHub issue tagged with "Enhancement"
1818

1919
* Create a branch and start working on your new feature, following feedback from the community.
2020

2121
* Once the new feature is ready, submit a pull request. If the feature is accepted and has passed all CI testing, the pull request will be approved.
2222

23-
2423
Thanks! :heart:
2524

2625
---
2726

28-
> Based off of the Ruby on Rails project [contribution guide](https://github.com/rails/rails/blob/master/CONTRIBUTING.md).
27+
> Based off of the Ruby on Rails project [contribution guide](https://github.com/rails/rails/blob/master/CONTRIBUTING.md).

ITGlueAPI/ITGlueAPI.psd1

+27-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
RootModule = '.\ITGlueAPI.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '0.1.0'
15+
# Follows https://semver.org Semantic Versioning 2.0.0
16+
# Given a version number MAJOR.MINOR.PATCH, increment the:
17+
# -- MAJOR version when you make incompatible API changes,
18+
# -- MINOR version when you add functionality in a backwards-compatible manner, and
19+
# -- PATCH version when you make backwards-compatible bug fixes.
20+
ModuleVersion = '2.0.0'
1621

1722
# ID used to uniquely identify this module
1823
#GUID = ''
@@ -26,6 +31,9 @@ CompanyName = 'IT Glue'
2631
# Description of the functionality provided by this module
2732
Description = 'This module provides a PowerShell wrapper for the IT Glue API.'
2833

34+
# Copyright information of this module
35+
Copyright = 'https://github.com/itglue/powershellwrapper/blob/master/LICENSE'
36+
2937
# Minimum version of the Windows PowerShell engine required by this module
3038
PowerShellVersion = '3.0'
3139

@@ -70,17 +78,19 @@ NestedModules = 'Internal/BaseURI.ps1',
7078
'Resources/Contacts.ps1',
7179
'Resources/ContactTypes.ps1',
7280
'Resources/Countries.ps1',
73-
'Resources/FavoriteOrganizations.ps1',
7481
'Resources/FlexibleAssetFields.ps1',
7582
'Resources/FlexibleAssets.ps1',
7683
'Resources/FlexibleAssetTypes.ps1',
84+
'Resources/Groups.ps1',
7785
'Resources/Locations.ps1',
7886
'Resources/Manufacturers.ps1',
7987
'Resources/Models.ps1',
8088
'Resources/OperatingSystems.ps1',
8189
'Resources/Organizations.ps1',
8290
'Resources/OrganizationStatuses.ps1',
8391
'Resources/OrganizationTypes.ps1',
92+
'Resources/PasswordCategories.ps1',
93+
'Resources/Passwords.ps1',
8494
'Resources/Platforms.ps1',
8595
'Resources/Regions.ps1',
8696
'Resources/UserMetrics.ps1',
@@ -124,10 +134,6 @@ FunctionsToExport = 'Add-ITGlueAPIKey',
124134

125135
'Get-ITGlueCountries',
126136

127-
'New-ITGlueFavoriteOrganizations',
128-
'Get-ITGlueFavoriteOrganizations',
129-
'Remove-ITGlueFavoriteOrganizations',
130-
131137
'New-ITGlueFlexibleAssetFields',
132138
'Get-ITGlueFlexibleAssetFields',
133139
'Set-ITGlueFlexibleAssetFields',
@@ -140,10 +146,14 @@ FunctionsToExport = 'Add-ITGlueAPIKey',
140146
'New-ITGlueFlexibleAssets',
141147
'Get-ITGlueFlexibleAssets',
142148
'Set-ITGlueFlexibleAssets',
149+
'Remove-ITGlueFlexibleAssets',
150+
151+
'Get-ITGlueGroups',
143152

144153
'New-ITGlueLocations',
145154
'Get-ITGlueLocations',
146155
'Set-ITGlueLocations',
156+
'Remove-ITGlueLocations',
147157

148158
'New-ITGlueManufacturers',
149159
'Get-ITGlueManufacturers',
@@ -166,6 +176,16 @@ FunctionsToExport = 'Add-ITGlueAPIKey',
166176
'New-ITGlueOrganizations',
167177
'Get-ITGlueOrganizations',
168178
'Set-ITGlueOrganizations',
179+
'Remove-ITGlueOrganizations',
180+
181+
'New-ITGluePasswordCategories',
182+
'Get-ITGluePasswordCategories',
183+
'Set-ITGluePasswordCategories',
184+
185+
'New-ITGluePasswords',
186+
'Get-ITGluePasswords',
187+
'Set-ITGluePasswords',
188+
'Remove-ITGluePasswords',
169189

170190
'Get-ITGluePlatforms',
171191

@@ -198,7 +218,7 @@ AliasesToExport = '*'
198218
# PrivateData = ''
199219

200220
# HelpInfo URI of this module
201-
# HelpInfoURI = ''
221+
HelpInfoURI = 'https://github.com/itglue/powershellwrapper/wiki'
202222

203223
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
204224
# DefaultCommandPrefix = ''

ITGlueAPI/Internal/APIKey.ps1

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
function Add-ITGlueAPIKey {
22
[cmdletbinding()]
33
Param (
4-
[Parameter(Mandatory = $false)]
4+
[Parameter(Mandatory = $false, ValueFromPipeline = $true)]
55
[AllowEmptyString()]
66
[Alias('ApiKey')]
77
[string]$Api_Key
@@ -11,7 +11,7 @@ function Add-ITGlueAPIKey {
1111

1212
Set-Variable -Name "ITGlue_API_Key" -Value $x_api_key -Option ReadOnly -Scope global -Force
1313
}
14-
if (!$Api_Key) {
14+
else {
1515
Write-Host "Please enter your API key:"
1616
$x_api_key = Read-Host -AsSecureString
1717

@@ -24,9 +24,12 @@ function Remove-ITGlueAPIKey {
2424
}
2525

2626
function Get-ITGlueAPIKey {
27-
$ITGlue_API_Key
28-
29-
Write-Host "Use Get-ITGlueAPIKey -Force to retrieve the unencrypted copy." -ForegroundColor "Red"
27+
if($ITGlue_API_Key -eq $null) {
28+
Write-Error "No API key exists. Please run Add-ITGlueAPIKey to add one."
29+
}
30+
else {
31+
$ITGlue_API_Key
32+
}
3033
}
3134

3235
New-Alias -Name Set-ITGlueAPIKey -Value Add-ITGlueAPIKey

ITGlueAPI/Internal/BaseURI.ps1

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,24 @@ function Add-ITGlueBaseURI {
22
[cmdletbinding()]
33
Param (
44
[parameter(ValueFromPipeline)]
5-
[string]$base_uri = "http://api.itglue.com"
5+
[string]$base_uri = 'https://api.itglue.com',
6+
7+
[Alias('locale','dc')]
8+
[ValidateSet( 'US', 'EU')]
9+
[String]$data_center = ''
610
)
711

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

17+
switch ($data_center) {
18+
'US' {$base_uri = 'https://api.itglue.com'}
19+
'EU' {$base_uri = 'https://api.eu.itglue.com'}
20+
Default {}
21+
}
22+
1323

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

ITGlueAPI/Resources/ConfigurationInterfaces.ps1

+68-17
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,21 @@ function New-ITGlueConfigurationInterfaces {
1212
$resource_uri = ('/configurations/{0}/relationships/configuration_interfaces' -f $conf_id)
1313
}
1414

15-
$body = ConvertTo-Json -InputObject $data -Depth $ITGlue_JSON_Conversion_Depth
15+
$body = @{}
1616

17-
$ITGlue_Headers.Add('x-api-key', (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password)
18-
$rest_output = Invoke-RestMethod -method 'POST' -uri ($ITGlue_Base_URI + $resource_uri) -headers $ITGlue_Headers `
19-
-body $body -ErrorAction Stop -ErrorVariable $web_error
20-
$ITGlue_Headers.Remove('x-api-key') >$null # Quietly clean up scope so the API key doesn't persist
17+
$body += @{'data' = $data}
18+
19+
$body = ConvertTo-Json -InputObject $body -Depth $ITGlue_JSON_Conversion_Depth
20+
21+
try {
22+
$ITGlue_Headers.Add('x-api-key', (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password)
23+
$rest_output = Invoke-RestMethod -method 'POST' -uri ($ITGlue_Base_URI + $resource_uri) -headers $ITGlue_Headers `
24+
-body $body -ErrorAction Stop -ErrorVariable $web_error
25+
} catch {
26+
Write-Error $_
27+
} finally {
28+
$ITGlue_Headers.Remove('x-api-key') >$null # Quietly clean up scope so the API key doesn't persist
29+
}
2130

2231
$data = @{}
2332
$data = $rest_output
@@ -31,6 +40,14 @@ function Get-ITGlueConfigurationInterfaces {
3140
[Parameter(ParameterSetName = 'show')]
3241
[Nullable[Int64]]$conf_id = $null,
3342

43+
[Parameter(ParameterSetName = 'index')]
44+
[Nullable[Int64]]$filter_id = $null,
45+
46+
[Parameter(ParameterSetName = 'index')]
47+
[ValidateSet('created_at', 'updated-at', `
48+
'-created_at', '-updated-at')]
49+
[String]$sort = '',
50+
3451
[Parameter(ParameterSetName = 'index')]
3552
[Nullable[Int64]]$page_number = $null,
3653

@@ -46,8 +63,15 @@ function Get-ITGlueConfigurationInterfaces {
4663
$resource_uri = ('/configuration_interfaces/{0}' -f $id)
4764
}
4865

66+
$body = @{}
67+
4968
if ($PSCmdlet.ParameterSetName -eq 'index') {
50-
$body = @{}
69+
if ($filter_id) {
70+
$body += @{'filter[id]' = $filter_id}
71+
}
72+
if ($sort) {
73+
$body += @{'sort' = $sort}
74+
}
5175
if ($page_number) {
5276
$body += @{'page[number]' = $page_number}
5377
}
@@ -56,23 +80,35 @@ function Get-ITGlueConfigurationInterfaces {
5680
}
5781
}
5882

59-
60-
$ITGlue_Headers.Add('x-api-key', (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password)
61-
$rest_output = Invoke-RestMethod -method 'GET' -uri ($ITGlue_Base_URI + $resource_uri) -headers $ITGlue_Headers `
62-
-body $body -ErrorAction Stop -ErrorVariable $web_error
63-
$ITGlue_Headers.Remove('x-api-key') >$null # Quietly clean up scope so the API key doesn't persist
83+
try {
84+
$ITGlue_Headers.Add('x-api-key', (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password)
85+
$rest_output = Invoke-RestMethod -method 'GET' -uri ($ITGlue_Base_URI + $resource_uri) -headers $ITGlue_Headers `
86+
-body $body -ErrorAction Stop -ErrorVariable $web_error
87+
} catch {
88+
Write-Error $_
89+
} finally {
90+
$ITGlue_Headers.Remove('x-api-key') >$null # Quietly clean up scope so the API key doesn't persist
91+
}
6492

6593
$data = @{}
6694
$data = $rest_output
6795
return $data
6896
}
6997

7098
function Set-ITGlueConfigurationInterfaces {
99+
[CmdletBinding(DefaultParametersetName = 'update')]
71100
Param (
101+
[Parameter(ParameterSetName = 'update')]
72102
[Nullable[Int64]]$id,
73103

104+
[Parameter(ParameterSetName = 'update')]
74105
[Nullable[Int64]]$conf_id = $null,
75106

107+
[Parameter(ParameterSetName = 'bulk_update')]
108+
[Nullable[Int64]]$filter_id = $null,
109+
110+
[Parameter(ParameterSetName = 'update')]
111+
[Parameter(ParameterSetName = 'bulk_update')]
76112
[Parameter(Mandatory = $true)]
77113
$data
78114
)
@@ -83,14 +119,29 @@ function Set-ITGlueConfigurationInterfaces {
83119
$resource_uri = ('/configurations/{0}/relationships/configuration_interfaces/{1}' -f $conf_id, $id)
84120
}
85121

86-
$body = ConvertTo-Json -InputObject $data -Depth $ITGlue_JSON_Conversion_Depth
122+
$body = @{}
123+
124+
if ($PSCmdlet.ParameterSetName -eq 'bulk_delete') {
125+
if ($filter_id) {
126+
$body += @{'filter[id]' = $filter_id}
127+
}
128+
}
129+
130+
$body += @{'data' = $data}
87131

88-
$ITGlue_Headers.Add('x-api-key', (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password)
89-
$rest_output = Invoke-RestMethod -method 'PATCH' -uri ($ITGlue_Base_URI + $resource_uri) -headers $ITGlue_Headers `
90-
-body $body -ErrorAction Stop -ErrorVariable $web_error
91-
$ITGlue_Headers.Remove('x-api-key') >$null # Quietly clean up scope so the API key doesn't persist
132+
$body = ConvertTo-Json -InputObject $body -Depth $ITGlue_JSON_Conversion_Depth
133+
134+
try {
135+
$ITGlue_Headers.Add('x-api-key', (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password)
136+
$rest_output = Invoke-RestMethod -method 'PATCH' -uri ($ITGlue_Base_URI + $resource_uri) -headers $ITGlue_Headers `
137+
-body $body -ErrorAction Stop -ErrorVariable $web_error
138+
} catch {
139+
Write-Error $_
140+
} finally {
141+
$ITGlue_Headers.Remove('x-api-key') >$null # Quietly clean up scope so the API key doesn't persist
142+
}
92143

93144
$data = @{}
94-
$data = $rest_output
145+
$data = $rest_output
95146
return $data
96147
}

ITGlueAPI/Resources/ConfigurationStatuses.ps1

+19-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ function New-ITGlueConfigurationStatuses {
66

77
$resource_uri = '/configuration_statuses/'
88

9-
$body = ConvertTo-Json -InputObject $data -Depth $ITGlue_JSON_Conversion_Depth
9+
$body = @{}
10+
11+
$body += @{'data' = $data}
12+
13+
$body = ConvertTo-Json -InputObject $body -Depth $ITGlue_JSON_Conversion_Depth
1014

1115
$ITGlue_Headers.Add('x-api-key', (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password)
1216
$rest_output = Invoke-RestMethod -method 'POST' -uri ($ITGlue_Base_URI + $resource_uri) -headers $ITGlue_Headers `
@@ -25,8 +29,8 @@ function Get-ITGlueConfigurationStatuses {
2529
[String]$filter_name = '',
2630

2731
[Parameter(ParameterSetName = 'index')]
28-
[ValidateSet( 'name', 'id', `
29-
'-name', '-id')]
32+
[ValidateSet( 'name', 'id', 'created_at', 'updated_at', `
33+
'-name', '-id', '-created_at', '-updated_at')]
3034
[String]$sort = '',
3135

3236
[Parameter(ParameterSetName = 'index')]
@@ -41,11 +45,15 @@ function Get-ITGlueConfigurationStatuses {
4145

4246
$resource_uri = ('/configuration_statuses/{0}' -f $id)
4347

48+
$body = @{}
49+
4450
if ($PSCmdlet.ParameterSetName -eq 'index') {
45-
$body = @{
46-
'filter[name]' = $filter_name
47-
'sort' = $sort
51+
if ($filter_name) {
52+
$body += @{'filter[name]' = $filter_name}
4853
}
54+
if ($sort) {
55+
$body += @{'sort' = $sort}
56+
}
4957
if ($page_number) {
5058
$body += @{'page[number]' = $page_number}
5159
}
@@ -54,7 +62,6 @@ function Get-ITGlueConfigurationStatuses {
5462
}
5563
}
5664

57-
5865
$ITGlue_Headers.Add('x-api-key', (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password)
5966
$rest_output = Invoke-RestMethod -method 'GET' -uri ($ITGlue_Base_URI + $resource_uri) -headers $ITGlue_Headers `
6067
-body $body -ErrorAction Stop -ErrorVariable $web_error
@@ -76,7 +83,11 @@ function Set-ITGlueConfigurationStatuses {
7683

7784
$resource_uri = ('/configuration_statuses/{0}' -f $id)
7885

79-
$body = ConvertTo-Json -InputObject $data -Depth $ITGlue_JSON_Conversion_Depth
86+
$body = @{}
87+
88+
$body += @{'data' = $data}
89+
90+
$body = ConvertTo-Json -InputObject $body -Depth $ITGlue_JSON_Conversion_Depth
8091

8192
$ITGlue_Headers.Add('x-api-key', (New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList 'N/A', $ITGlue_API_Key).GetNetworkCredential().Password)
8293
$rest_output = Invoke-RestMethod -method 'PATCH' -uri ($ITGlue_Base_URI + $resource_uri) -headers $ITGlue_Headers `

0 commit comments

Comments
 (0)