From adb11a8bb3bc6c657badfa344069298a905c14ce Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sat, 30 Dec 2017 12:09:17 +0000 Subject: [PATCH 01/20] Update .gitlab-ci.yml --- .gitlab-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bc7a59d..ec7ded7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,7 @@ variables: GIT_SSL_NO_VERIFY: "true" - + ErrorActionPreference: STOP + before_script: - Get-PackageProvider -Name NuGet -ForceBootstrap | Out-Null - Install-Module InvokeBuild, BuildHelpers, PSScriptAnalyzer -force -Scope CurrentUser From 018f5943ae5a462b2a1d6eec6f36f394bebb09a4 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sun, 31 Dec 2017 19:22:39 +0000 Subject: [PATCH 02/20] Update .gitlab-ci.yml --- .gitlab-ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ec7ded7..ca6c7be 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,9 +4,9 @@ variables: before_script: - Get-PackageProvider -Name NuGet -ForceBootstrap | Out-Null - - Install-Module InvokeBuild, BuildHelpers, PSScriptAnalyzer -force -Scope CurrentUser - - Install-Module Pester -Force -SkipPublisherCheck -Scope CurrentUser - - Import-Module PSScriptAnalyzer -Scope CurrentUser + - Install-Module InvokeBuild, BuildHelpers, PSScriptAnalyzer -force + - Install-Module Pester -Force -SkipPublisherCheck + - Import-Module PSScriptAnalyzer stages: - test From 333e65361902fe6bebe6c8a64186988944c2f700 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sun, 31 Dec 2017 19:25:46 +0000 Subject: [PATCH 03/20] Update .gitlab-ci.yml --- .gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ca6c7be..52b73cb 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ variables: before_script: - Get-PackageProvider -Name NuGet -ForceBootstrap | Out-Null - - Install-Module InvokeBuild, BuildHelpers, PSScriptAnalyzer -force + - Install-Module InvokeBuild, BuildHelpers, PSScriptAnalyzer -force -AllowClobber - Install-Module Pester -Force -SkipPublisherCheck - Import-Module PSScriptAnalyzer From 7606d2d7a9ba4a394c9fec3ec4e91ec06a77766b Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sun, 31 Dec 2017 19:36:51 +0000 Subject: [PATCH 04/20] Change Gitlab CI build --- .gitlab-ci.yml | 32 ++++++---------- SnipeitPS/Public/Get-Supplier.ps1 | 39 +++++++++++++++++++ SnipeitPS/SnipeItPS.psd1 | Bin 8482 -> 8524 bytes build.ps1 | 61 ++++++++++++++++++++++++++++++ 4 files changed, 112 insertions(+), 20 deletions(-) create mode 100644 SnipeitPS/Public/Get-Supplier.ps1 create mode 100644 build.ps1 diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bc7a59d..0a5aaf4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,29 +1,21 @@ -variables: - GIT_SSL_NO_VERIFY: "true" - -before_script: - - Get-PackageProvider -Name NuGet -ForceBootstrap | Out-Null - - Install-Module InvokeBuild, BuildHelpers, PSScriptAnalyzer -force -Scope CurrentUser - - Install-Module Pester -Force -SkipPublisherCheck -Scope CurrentUser - - Import-Module PSScriptAnalyzer -Scope CurrentUser - stages: - test # - release -ps_scriptanalyzer: - stage: test - script: - - $res = (Invoke-ScriptAnalyzer -Path . -Severity Error).count - - if ($res -gt 0) { throw "$($res) Analytics failed."} - tags: - - powershell +variables: + GIT_SSL_NO_VERIFY: "true" + ErrorActionPreference: STOP + +Test: + stage: test + script: + - .\build.ps1 -Tasks 'analyze','test' + except: + - master -# except: -# - master #Release: # stage: release -# script: +# script: # - .\build.ps1 -Tasks 'analyze','test','release' # only: -# - master \ No newline at end of file +# - master diff --git a/SnipeitPS/Public/Get-Supplier.ps1 b/SnipeitPS/Public/Get-Supplier.ps1 new file mode 100644 index 0000000..8c8a0c4 --- /dev/null +++ b/SnipeitPS/Public/Get-Supplier.ps1 @@ -0,0 +1,39 @@ +<# +.SYNOPSIS +# Gets a list of Snipe-it Suppliers + +.PARAMETER url +URL of Snipeit system, can be set using Set-Info command + +.PARAMETER apiKey +Users API Key for Snipeit, can be set using Set-Info command + +.EXAMPLE +Get-Supplier -url "https://assets.example.com" -token "token..." + +.EXAMPLE +Get-Supplier -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "MySupplier" } + +#> + +function Get-Supplier() +{ + Param( + [parameter(mandatory=$true)] + [string]$url, + + [parameter(mandatory=$true)] + [string]$apiKey + ) + + $Parameters = @{ + Uri = "$url/api/v1/suppliers" + Method = 'Get' + Token = $apiKey + } + + $result = Invoke-SnipeitMethod @Parameters + + $result +} + diff --git a/SnipeitPS/SnipeItPS.psd1 b/SnipeitPS/SnipeItPS.psd1 index 76d510ddf8c2c61d91dd66af56b8bc3b92fbf3ae..3b16a4eb52d4db127170a5560f145a1963689ac3 100644 GIT binary patch delta 28 icmZ4FbjE4J9+AmEge16w8A=%nfG~$4bMsb_Tpj?N!3m`R delta 12 TcmX@(w8&}09+Az@MACQwC|?DV diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..89afefb --- /dev/null +++ b/build.ps1 @@ -0,0 +1,61 @@ +param( + [string[]]$Tasks +) + +function Install-Dependency([string] $Name) +{ + $policy = Get-PSRepository -Name "PSGallery" | Select-Object -ExpandProperty "InstallationPolicy" + if($policy -ne "Trusted") { + Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted + } + + if (!(Get-Module -Name $Name -ListAvailable)) { + Install-Module -Name $Name -Scope CurrentUser + } +} + +function Analyze-Scripts +{ + param( + [string]$Path = "$PSScriptRoot\SnipeitPS\" + ) + $result = Invoke-ScriptAnalyzer -Path $Path -Severity @('Error', 'Warning') -Recurse + if ($result) { + $result | Format-Table + Write-Error -Message "$($result.SuggestedCorrections.Count) linting errors or warnings were found. The build cannot continue." + EXIT 1 + } +} + +function Run-Tests +{ + param( + [string]$Path = "$PSScriptRoot\SnipeitPS" + ) + + $results = Invoke-Pester -Path $Path -PassThru + if($results.FailedCount -gt 0) { + Write-Output " > $($results.FailedCount) tests failed. The build cannot continue." + foreach($result in $($results.TestResult | Where {$_.Passed -eq $false} | Select-Object -Property Describe,Context,Name,Passed,Time)){ + Write-Output " > $result" + } + + EXIT 1 + } +} + +foreach($task in $Tasks){ + switch($task) + { + "analyze" { + Install-Dependency -Name "PSScriptAnalyzer" + Write-Output "Analyzing Scripts..." + Analyze-Scripts + } + "test" { + Install-Dependency -Name "Pester" + Write-Output "Running Pester Tests..." + Run-Tests + } + } +} From 420c59722bccae8b004fec69b2d2b23cb56a62b7 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sun, 31 Dec 2017 19:42:27 +0000 Subject: [PATCH 05/20] More test changes --- .gitlab-ci.yml | 2 +- build.ps1 | 21 ++------------------- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0a5aaf4..9ccc302 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,7 +9,7 @@ variables: Test: stage: test script: - - .\build.ps1 -Tasks 'analyze','test' + - .\build.ps1 -Tasks 'test' except: - master diff --git a/build.ps1 b/build.ps1 index 89afefb..3ebf83a 100644 --- a/build.ps1 +++ b/build.ps1 @@ -14,26 +14,13 @@ function Install-Dependency([string] $Name) } } -function Analyze-Scripts -{ - param( - [string]$Path = "$PSScriptRoot\SnipeitPS\" - ) - $result = Invoke-ScriptAnalyzer -Path $Path -Severity @('Error', 'Warning') -Recurse - if ($result) { - $result | Format-Table - Write-Error -Message "$($result.SuggestedCorrections.Count) linting errors or warnings were found. The build cannot continue." - EXIT 1 - } -} - function Run-Tests { param( [string]$Path = "$PSScriptRoot\SnipeitPS" ) - $results = Invoke-Pester -Path $Path -PassThru + $results = Invoke-Pester -PassThru if($results.FailedCount -gt 0) { Write-Output " > $($results.FailedCount) tests failed. The build cannot continue." foreach($result in $($results.TestResult | Where {$_.Passed -eq $false} | Select-Object -Property Describe,Context,Name,Passed,Time)){ @@ -47,12 +34,8 @@ function Run-Tests foreach($task in $Tasks){ switch($task) { - "analyze" { - Install-Dependency -Name "PSScriptAnalyzer" - Write-Output "Analyzing Scripts..." - Analyze-Scripts - } "test" { + Install-Dependency -Name "PSScriptAnalyzer" Install-Dependency -Name "Pester" Write-Output "Running Pester Tests..." Run-Tests From e73e0be549bc1078f1fb69897160889fbaf0ab1b Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sun, 31 Dec 2017 20:07:11 +0000 Subject: [PATCH 06/20] Release to internal Nuget test --- .gitlab-ci.yml | 14 +++++++------- build.ps1 | 12 ++++++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9ccc302..056c15c 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,6 @@ stages: - test -# - release + - release variables: GIT_SSL_NO_VERIFY: "true" @@ -13,9 +13,9 @@ Test: except: - master -#Release: -# stage: release -# script: -# - .\build.ps1 -Tasks 'analyze','test','release' -# only: -# - master +Release: + stage: release + script: + - .\build.ps1 -Tasks 'test','release' + only: + - master diff --git a/build.ps1 b/build.ps1 index 3ebf83a..47ea638 100644 --- a/build.ps1 +++ b/build.ps1 @@ -40,5 +40,17 @@ foreach($task in $Tasks){ Write-Output "Running Pester Tests..." Run-Tests } + "release" { + Register-PSRepository -Name InternalPowerShellModules ` + -SourceLocation http://192.168.1.155:81/nuget/DIPowerShell ` + -PackageManagementProvider NuGet ` + -PublishLocation http://192.168.1.155:81/nuget/DIPowerShell ` + -InstallationPolicy Trusted + + Write-Output "Registerting Module" + + Import-Module $env:CI_PROJECT_PATH\SnipeitPS\SnipeitPS.psd1 -ErrorAction Stop + Publish-Module -Name SnipeitPS -Repository InternalPowerShellModules -NuGetApiKey 123456789 + } } } From aa4fea0a5b0659287b9af2289ece11c084177f5c Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sun, 31 Dec 2017 20:13:32 +0000 Subject: [PATCH 07/20] Release to internal Nuget test --- .gitlab-ci.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 056c15c..ee7d76a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -19,3 +19,4 @@ Release: - .\build.ps1 -Tasks 'test','release' only: - master + From bde2802e9f7f8c187d1db949178d8675d588eda9 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sun, 31 Dec 2017 20:19:00 +0000 Subject: [PATCH 08/20] Update .gitlab-ci.yml --- .gitlab-ci.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ee7d76a..e5e8165 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,7 +16,6 @@ Test: Release: stage: release script: - - .\build.ps1 -Tasks 'test','release' + - .\build.ps1 -Tasks 'test', 'release' only: - - master - + - master \ No newline at end of file From 98f52f4b39ec4ccec87e3ecc4d4a912583cb417c Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sun, 31 Dec 2017 20:19:53 +0000 Subject: [PATCH 09/20] Update .gitlab-ci.yml --- .gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e5e8165..7f5c3ef 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -17,5 +17,5 @@ Release: stage: release script: - .\build.ps1 -Tasks 'test', 'release' - only: - - master \ No newline at end of file + only: + - master \ No newline at end of file From bf478494caa2dc8fc7bf21894d1695841f8c48c2 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sun, 31 Dec 2017 20:20:34 +0000 Subject: [PATCH 10/20] Update .gitlab-ci.yml --- .gitlab-ci.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 7f5c3ef..9ccc302 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,6 @@ stages: - test - - release +# - release variables: GIT_SSL_NO_VERIFY: "true" @@ -13,9 +13,9 @@ Test: except: - master -Release: - stage: release - script: - - .\build.ps1 -Tasks 'test', 'release' - only: - - master \ No newline at end of file +#Release: +# stage: release +# script: +# - .\build.ps1 -Tasks 'analyze','test','release' +# only: +# - master From ff7d1abb402c3bbf2fdda9f99a5b75af60f2f5d6 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sun, 31 Dec 2017 20:21:24 +0000 Subject: [PATCH 11/20] Update .gitlab-ci.yml --- .gitlab-ci.yml | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9ccc302..ea940ef 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,21 +1,18 @@ stages: - test -# - release - + - release variables: GIT_SSL_NO_VERIFY: "true" ErrorActionPreference: STOP - Test: stage: test script: - .\build.ps1 -Tasks 'test' except: - master - -#Release: -# stage: release -# script: -# - .\build.ps1 -Tasks 'analyze','test','release' -# only: -# - master +Release: + stage: release + script: + - .\build.ps1 -Tasks 'test','release' + only: + - master \ No newline at end of file From d06f20a5ebf893fa1d90ddff2fc941e8c6e127e9 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sun, 31 Dec 2017 20:22:57 +0000 Subject: [PATCH 12/20] Change env variable --- build.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.ps1 b/build.ps1 index 47ea638..dafe390 100644 --- a/build.ps1 +++ b/build.ps1 @@ -49,7 +49,7 @@ foreach($task in $Tasks){ Write-Output "Registerting Module" - Import-Module $env:CI_PROJECT_PATH\SnipeitPS\SnipeitPS.psd1 -ErrorAction Stop + Import-Module $env:CI_PROJECT_DIR\SnipeitPS\SnipeitPS.psd1 -ErrorAction Stop Publish-Module -Name SnipeitPS -Repository InternalPowerShellModules -NuGetApiKey 123456789 } } From 783c6b0a6a8efbe025316b56d6c509c7e8030c85 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sun, 31 Dec 2017 20:25:40 +0000 Subject: [PATCH 13/20] Fix yaml --- .gitlab-ci.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ee7d76a..d0619a2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,22 +1,18 @@ stages: - test - release - variables: GIT_SSL_NO_VERIFY: "true" ErrorActionPreference: STOP - Test: stage: test script: - .\build.ps1 -Tasks 'test' except: - master - Release: stage: release - script: + script: - .\build.ps1 -Tasks 'test','release' only: - master - From d4210401921687f8f2801d6421ef55fb5433b0e5 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sun, 31 Dec 2017 21:16:55 +0000 Subject: [PATCH 14/20] Add more to build script for gitlabci --- build.ps1 | 65 ++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 10 deletions(-) diff --git a/build.ps1 b/build.ps1 index dafe390..fc4dac7 100644 --- a/build.ps1 +++ b/build.ps1 @@ -2,6 +2,8 @@ param( [string[]]$Tasks ) + + function Install-Dependency([string] $Name) { $policy = Get-PSRepository -Name "PSGallery" | Select-Object -ExpandProperty "InstallationPolicy" @@ -31,6 +33,57 @@ function Run-Tests } } +function Release +{ + Write-Output "Setting Variables" + $BuildRoot = $env:CI_PROJECT_DIR + $releasePath = "$BuildRoot\Release" + + Write-Output "Build Root : $BuildRoot" + Write-Output "Release Root : $releasePath" + + if (-not (Test-Path "$releasePath\SnipeitPS")) { + $null = New-Item -Path "$releasePath\SnipeitPS" -ItemType Directory + } + + # Copy module + Copy-Item -Path "$BuildRoot\SnipeitPS\*" -Destination "$releasePath\SnipeitPS" -Recurse -Force + # Copy additional files + $additionalFiles = @( + "$BuildRoot\CHANGELOG.md" + "$BuildRoot\LICENSE" + "$BuildRoot\README.md" + ) + Copy-Item -Path $additionalFiles -Destination "$releasePath\SnipeitPS" -Force + + + $manifestContent = Get-Content -Path "$releasePath\SnipeitPS\SnipeitPS.psd1" -Raw + if ($manifestContent -notmatch '(?<=ModuleVersion\s+=\s+'')(?.*)(?='')') { + throw "Module version was not found in manifest file," + } + + $currentVersion = [Version] $Matches.ModuleVersion + if ($env:CI_JOB_ID) { + $newRevision = $env:CI_JOB_ID + } + else { + $newRevision = 0 + } + $version = New-Object -TypeName System.Version -ArgumentList $currentVersion.Major, + $currentVersion.Minor, + $newRevision + + Write-Output "New version : $version" + + Update-Metadata -Path "$releasePath\SnipeitPS\SnipeitPS.psd1" -PropertyName ModuleVersion -Value $version + $functionsToExport = Get-ChildItem "$BuildRoot\SnipeitPS\SnipeitPS\Public" | ForEach-Object {$_.BaseName} + Set-ModuleFunctions -Name "$releasePath\SnipeitPS\SnipeitPS.psd1" -FunctionsToExport $functionsToExport + + Remove-Module SnipeitPS + Import-Module $env:CI_PROJECT_DIR\SnipeitPS\SnipeitPS.psd1 -ErrorAction Stop + Publish-Module -Name SnipeitPS -Repository InternalPowerShellModules -NuGetApiKey 123456789 +} + foreach($task in $Tasks){ switch($task) { @@ -41,16 +94,8 @@ foreach($task in $Tasks){ Run-Tests } "release" { - Register-PSRepository -Name InternalPowerShellModules ` - -SourceLocation http://192.168.1.155:81/nuget/DIPowerShell ` - -PackageManagementProvider NuGet ` - -PublishLocation http://192.168.1.155:81/nuget/DIPowerShell ` - -InstallationPolicy Trusted - - Write-Output "Registerting Module" - - Import-Module $env:CI_PROJECT_DIR\SnipeitPS\SnipeitPS.psd1 -ErrorAction Stop - Publish-Module -Name SnipeitPS -Repository InternalPowerShellModules -NuGetApiKey 123456789 + Write-Output "Releasing..." + Release } } } From af60ed8b26c752db31c2145c7b0e29d2541a8a0e Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sun, 31 Dec 2017 21:21:21 +0000 Subject: [PATCH 15/20] Fix path issue :( --- build.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.ps1 b/build.ps1 index fc4dac7..402f83f 100644 --- a/build.ps1 +++ b/build.ps1 @@ -76,7 +76,7 @@ function Release Write-Output "New version : $version" Update-Metadata -Path "$releasePath\SnipeitPS\SnipeitPS.psd1" -PropertyName ModuleVersion -Value $version - $functionsToExport = Get-ChildItem "$BuildRoot\SnipeitPS\SnipeitPS\Public" | ForEach-Object {$_.BaseName} + $functionsToExport = Get-ChildItem "$BuildRoot\SnipeitPS\Public" | ForEach-Object {$_.BaseName} Set-ModuleFunctions -Name "$releasePath\SnipeitPS\SnipeitPS.psd1" -FunctionsToExport $functionsToExport Remove-Module SnipeitPS From 8bdfb157fc0b41df6e1a446da0b4c9290f338fa4 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sun, 31 Dec 2017 21:23:55 +0000 Subject: [PATCH 16/20] dont need to remove the module... --- build.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.ps1 b/build.ps1 index 402f83f..662bd48 100644 --- a/build.ps1 +++ b/build.ps1 @@ -79,7 +79,7 @@ function Release $functionsToExport = Get-ChildItem "$BuildRoot\SnipeitPS\Public" | ForEach-Object {$_.BaseName} Set-ModuleFunctions -Name "$releasePath\SnipeitPS\SnipeitPS.psd1" -FunctionsToExport $functionsToExport - Remove-Module SnipeitPS + #Remove-Module SnipeitPS Import-Module $env:CI_PROJECT_DIR\SnipeitPS\SnipeitPS.psd1 -ErrorAction Stop Publish-Module -Name SnipeitPS -Repository InternalPowerShellModules -NuGetApiKey 123456789 } From 14fc468937d5a686d1b1594f7c1d69d7ada2a111 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sun, 31 Dec 2017 21:27:15 +0000 Subject: [PATCH 17/20] force load module --- build.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.ps1 b/build.ps1 index 662bd48..2c7d024 100644 --- a/build.ps1 +++ b/build.ps1 @@ -80,7 +80,7 @@ function Release Set-ModuleFunctions -Name "$releasePath\SnipeitPS\SnipeitPS.psd1" -FunctionsToExport $functionsToExport #Remove-Module SnipeitPS - Import-Module $env:CI_PROJECT_DIR\SnipeitPS\SnipeitPS.psd1 -ErrorAction Stop + Import-Module $env:CI_PROJECT_DIR\SnipeitPS\SnipeitPS.psd1 -force -ErrorAction Stop Publish-Module -Name SnipeitPS -Repository InternalPowerShellModules -NuGetApiKey 123456789 } From eb60cf8824a8fe3331b8532a6354c2e50cdeb1d1 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Mon, 22 Jan 2018 08:32:04 +0000 Subject: [PATCH 18/20] Add more methods as well, detected unauth requests and changed impact levels --- SnipeitPS/Private/Invoke-SnipeitMethod.ps1 | 3 + SnipeitPS/Public/Get-Asset.ps1 | 3 + SnipeitPS/Public/Get-Department.ps1 | 39 +++++++++++ SnipeitPS/Public/Get-Location.ps1 | 39 +++++++++++ SnipeitPS/Public/New-Asset.ps1 | 2 +- SnipeitPS/Public/New-Component.ps1 | 2 +- SnipeitPS/Public/New-Department.ps1 | 77 +++++++++++++++++++++ SnipeitPS/Public/New-Manufacturer.ps1 | 2 +- SnipeitPS/Public/New-Model.ps1 | 2 +- SnipeitPS/Public/Set-Asset.ps1 | 2 +- SnipeitPS/Public/Set-AssetOwner.ps1 | 2 +- SnipeitPS/Public/Set-Components.ps1 | 2 +- SnipeitPS/SnipeItPS.psd1 | Bin 8524 -> 8658 bytes 13 files changed, 168 insertions(+), 7 deletions(-) create mode 100644 SnipeitPS/Public/Get-Department.ps1 create mode 100644 SnipeitPS/Public/Get-Location.ps1 create mode 100644 SnipeitPS/Public/New-Department.ps1 diff --git a/SnipeitPS/Private/Invoke-SnipeitMethod.ps1 b/SnipeitPS/Private/Invoke-SnipeitMethod.ps1 index f340fa6..8400267 100644 --- a/SnipeitPS/Private/Invoke-SnipeitMethod.ps1 +++ b/SnipeitPS/Private/Invoke-SnipeitMethod.ps1 @@ -106,6 +106,9 @@ $result } } + elseif ($webResponse.StatusCode -eq "Unauthorized") { + Write-Error "[$($MyInvocation.MyCommand.Name)] You are not Authorized to access the resource, check your token is correct" + } else { # No content, although statusCode < 400 # This could be wanted behavior of the API diff --git a/SnipeitPS/Public/Get-Asset.ps1 b/SnipeitPS/Public/Get-Asset.ps1 index 4eb0e2d..2cf5ed6 100644 --- a/SnipeitPS/Public/Get-Asset.ps1 +++ b/SnipeitPS/Public/Get-Asset.ps1 @@ -29,6 +29,9 @@ function Get-Asset() $Parameters = @{ Uri = "$url/api/v1/hardware" Method = 'Get' + GetParameters = @{ + limit = 9999 + } Token = $apiKey } diff --git a/SnipeitPS/Public/Get-Department.ps1 b/SnipeitPS/Public/Get-Department.ps1 new file mode 100644 index 0000000..d28cadf --- /dev/null +++ b/SnipeitPS/Public/Get-Department.ps1 @@ -0,0 +1,39 @@ +<# +.SYNOPSIS +# Gets a list of Snipe-it Departments + +.PARAMETER url +URL of Snipeit system, can be set using Set-Info command + +.PARAMETER apiKey +Users API Key for Snipeit, can be set using Set-Info command + +.EXAMPLE +Get-Department -url "https://assets.example.com" -token "token..." + +.EXAMPLE +Get-Department -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "Department1" } + +#> + +function Get-Department() +{ + Param( + [parameter(mandatory=$true)] + [string]$url, + + [parameter(mandatory=$true)] + [string]$apiKey + ) + + $Parameters = @{ + Uri = "$url/api/v1/departments" + Method = 'Get' + Token = $apiKey + } + + $result = Invoke-SnipeitMethod @Parameters + + $result +} + diff --git a/SnipeitPS/Public/Get-Location.ps1 b/SnipeitPS/Public/Get-Location.ps1 new file mode 100644 index 0000000..53218a4 --- /dev/null +++ b/SnipeitPS/Public/Get-Location.ps1 @@ -0,0 +1,39 @@ +<# +.SYNOPSIS +# Gets a list of Snipe-it Locations + +.PARAMETER url +URL of Snipeit system, can be set using Set-Info command + +.PARAMETER apiKey +Users API Key for Snipeit, can be set using Set-Info command + +.EXAMPLE +Get-Location -url "https://assets.example.com" -token "token..." + +.EXAMPLE +Get-Location -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "Location1" } + +#> + +function Get-Location() +{ + Param( + [parameter(mandatory=$true)] + [string]$url, + + [parameter(mandatory=$true)] + [string]$apiKey + ) + + $Parameters = @{ + Uri = "$url/api/v1/locations" + Method = 'Get' + Token = $apiKey + } + + $result = Invoke-SnipeitMethod @Parameters + + $result +} + diff --git a/SnipeitPS/Public/New-Asset.ps1 b/SnipeitPS/Public/New-Asset.ps1 index e6a8876..7d1678b 100644 --- a/SnipeitPS/Public/New-Asset.ps1 +++ b/SnipeitPS/Public/New-Asset.ps1 @@ -37,7 +37,7 @@ function New-Asset() { [CmdletBinding( SupportsShouldProcess = $true, - ConfirmImpact = "High" + ConfirmImpact = "Low" )] Param( diff --git a/SnipeitPS/Public/New-Component.ps1 b/SnipeitPS/Public/New-Component.ps1 index 7105811..690b1c8 100644 --- a/SnipeitPS/Public/New-Component.ps1 +++ b/SnipeitPS/Public/New-Component.ps1 @@ -31,7 +31,7 @@ function New-Component() { [CmdletBinding( SupportsShouldProcess = $true, - ConfirmImpact = "High" + ConfirmImpact = "Low" )] Param( diff --git a/SnipeitPS/Public/New-Department.ps1 b/SnipeitPS/Public/New-Department.ps1 new file mode 100644 index 0000000..0fe2536 --- /dev/null +++ b/SnipeitPS/Public/New-Department.ps1 @@ -0,0 +1,77 @@ +<# + .SYNOPSIS + Short description + + .DESCRIPTION + Long description + + .PARAMETER name + Parameter description + + .PARAMETER category_id + Parameter description + + .PARAMETER qty + Parameter description + + .PARAMETER url + Parameter description + + .PARAMETER apiKey + Parameter description + + .EXAMPLE + An example + + .NOTES + General notes +#> + +function New-Department() +{ + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "Low" + )] + + Param( + [parameter(mandatory = $true)] + [string]$name, + + [string]$company_id, + + [string]$location_id, + + [string]$manager_id, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + $Values = @{ + "name" = $name + "company_id" = $company_id + "location_id" = $location_id + "manager_id" = $manager_id + } + + $Body = $Values | ConvertTo-Json; + + $Parameters = @{ + Uri = "$url/api/v1/departments" + Method = 'POST' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) + { + $result = Invoke-SnipeitMethod @Parameters + } + + $result +} + diff --git a/SnipeitPS/Public/New-Manufacturer.ps1 b/SnipeitPS/Public/New-Manufacturer.ps1 index b198a60..d85ee18 100644 --- a/SnipeitPS/Public/New-Manufacturer.ps1 +++ b/SnipeitPS/Public/New-Manufacturer.ps1 @@ -22,7 +22,7 @@ function New-Manufacturer() { [CmdletBinding( SupportsShouldProcess = $true, - ConfirmImpact = "High" + ConfirmImpact = "Low" )] Param( diff --git a/SnipeitPS/Public/New-Model.ps1 b/SnipeitPS/Public/New-Model.ps1 index c7a5067..af21b76 100644 --- a/SnipeitPS/Public/New-Model.ps1 +++ b/SnipeitPS/Public/New-Model.ps1 @@ -31,7 +31,7 @@ function New-Model() { [CmdletBinding( SupportsShouldProcess = $true, - ConfirmImpact = "High" + ConfirmImpact = "Low" )] Param( diff --git a/SnipeitPS/Public/Set-Asset.ps1 b/SnipeitPS/Public/Set-Asset.ps1 index a53391a..a7decfb 100644 --- a/SnipeitPS/Public/Set-Asset.ps1 +++ b/SnipeitPS/Public/Set-Asset.ps1 @@ -37,7 +37,7 @@ function Set-Asset() { [CmdletBinding( SupportsShouldProcess = $true, - ConfirmImpact = "High" + ConfirmImpact = "Medium" )] Param( diff --git a/SnipeitPS/Public/Set-AssetOwner.ps1 b/SnipeitPS/Public/Set-AssetOwner.ps1 index 44d792e..3ecbc1c 100644 --- a/SnipeitPS/Public/Set-AssetOwner.ps1 +++ b/SnipeitPS/Public/Set-AssetOwner.ps1 @@ -2,7 +2,7 @@ function Set-AssetOwner() { [CmdletBinding( SupportsShouldProcess = $true, - ConfirmImpact = "High" + ConfirmImpact = "Medium" )] Param( diff --git a/SnipeitPS/Public/Set-Components.ps1 b/SnipeitPS/Public/Set-Components.ps1 index 84dd6b8..92f44f8 100644 --- a/SnipeitPS/Public/Set-Components.ps1 +++ b/SnipeitPS/Public/Set-Components.ps1 @@ -2,7 +2,7 @@ function Set-Component() { [CmdletBinding( SupportsShouldProcess = $true, - ConfirmImpact = "High" + ConfirmImpact = "Medium" )] Param( diff --git a/SnipeitPS/SnipeItPS.psd1 b/SnipeitPS/SnipeItPS.psd1 index 3b16a4eb52d4db127170a5560f145a1963689ac3..2a45466aa6629aba3cc601ea56b7bbc38365044b 100644 GIT binary patch delta 76 zcmX@(bjf+cGm*(Zgd})f7*ZJu7!nzZ7)ls&Cl?A!PL31iz#^I_#KG^wkk60|R9nK3 N31sDMek_v70|0QU6(s-w delta 12 TcmccQe8y?RGm*_XqG>z;DVGIw From bd9db2d9be67535433a4e2fa67793b2fc1bdabe7 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sat, 17 Mar 2018 21:23:11 +0000 Subject: [PATCH 19/20] Added new Ability to create users and update them as well as add new locations --- SnipeitPS/Public/Get-Company.ps1 | 38 ++++++++ SnipeitPS/Public/New-Location.ps1 | 80 +++++++++++++++++ SnipeitPS/Public/New-User.ps1 | 143 ++++++++++++++++++++++++++++++ SnipeitPS/Public/Set-User.ps1 | 131 +++++++++++++++++++++++++++ SnipeitPS/SnipeItPS.psd1 | Bin 8658 -> 8992 bytes 5 files changed, 392 insertions(+) create mode 100644 SnipeitPS/Public/Get-Company.ps1 create mode 100644 SnipeitPS/Public/New-Location.ps1 create mode 100644 SnipeitPS/Public/New-User.ps1 create mode 100644 SnipeitPS/Public/Set-User.ps1 diff --git a/SnipeitPS/Public/Get-Company.ps1 b/SnipeitPS/Public/Get-Company.ps1 new file mode 100644 index 0000000..df66964 --- /dev/null +++ b/SnipeitPS/Public/Get-Company.ps1 @@ -0,0 +1,38 @@ +<# +.SYNOPSIS +# Gets a list of Snipe-it Companies + +.PARAMETER url +URL of Snipeit system, can be set using Set-Info command + +.PARAMETER apiKey +Users API Key for Snipeit, can be set using Set-Info command + +.EXAMPLE +Get-Company -url "https://assets.example.com" -token "token..." + +.EXAMPLE +Get-Company -url "https://assets.example.com" -token "token..." | Where-Object {$_.name -eq "Company1" } + +#> + +function Get-Company() +{ + Param( + [parameter(mandatory=$true)] + [string]$url, + + [parameter(mandatory=$true)] + [string]$apiKey + ) + + $Parameters = @{ + Uri = "$url/api/v1/companies" + Method = 'Get' + Token = $apiKey + } + + $result = Invoke-SnipeitMethod @Parameters + + $result +} diff --git a/SnipeitPS/Public/New-Location.ps1 b/SnipeitPS/Public/New-Location.ps1 new file mode 100644 index 0000000..d6cce02 --- /dev/null +++ b/SnipeitPS/Public/New-Location.ps1 @@ -0,0 +1,80 @@ +<# + .SYNOPSIS + Add a new Model to Snipe-it asset system + + .DESCRIPTION + Long description + + .PARAMETER name + Name of the Asset Model + + .PARAMETER category_id + Category ID that the asset belongs to this can be got using Get-Category + + .PARAMETER manufacturer_id + Manufacturer ID that the asset belongs to this can be got using Get-Manufacturer + + .PARAMETER fieldset_id + Fieldset ID that the asset uses (Custom fields) + + .PARAMETER url + URL of Snipeit system, can be set using Set-Info command + + .PARAMETER apiKey + Users API Key for Snipeit, can be set using Set-Info command + + .EXAMPLE + New-Model -name "DL380" -manufacturer_id 2 -fieldset_id 2 -category_id 1 +#> + +function New-Location() { + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "Low" + )] + + Param( + [parameter(mandatory = $true)] + [string]$name, + + [string]$address, + + [string]$address2, + + [string]$state, + + [string]$country, + + [string]$zip, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + $Values = @{ + name = $name + address = $address + address2 = $address2 + state = $state + country = $country + zip = $zip + } + + $Body = $Values | ConvertTo-Json; + + $Parameters = @{ + Uri = "$url/api/v1/locations" + Method = 'post' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) { + $result = Invoke-SnipeitMethod @Parameters + } + + $result +} diff --git a/SnipeitPS/Public/New-User.ps1 b/SnipeitPS/Public/New-User.ps1 new file mode 100644 index 0000000..6801075 --- /dev/null +++ b/SnipeitPS/Public/New-User.ps1 @@ -0,0 +1,143 @@ +<# + .SYNOPSIS + Short description + + .DESCRIPTION + Long description + + .PARAMETER firstName + Parameter description + + .PARAMETER lastName + Parameter description + + .PARAMETER userName + Parameter description + + .PARAMETER jobTitle + Parameter description + + .PARAMETER email + Parameter description + + .PARAMETER phone + Parameter description + + .PARAMETER company_id + Parameter description + + .PARAMETER location_id + Parameter description + + .PARAMETER department_id + Parameter description + + .PARAMETER manager_id + Parameter description + + .PARAMETER employee_num + Parameter description + + .PARAMETER ldap_user + Parameter description + + .PARAMETER url + Parameter description + + .PARAMETER apiKey + Parameter description + + .EXAMPLE + An example + + .NOTES + General notes + #> +function New-User() { + + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "Low" + )] + + Param( + [parameter(mandatory = $true)] + [string]$firstName, + + [parameter(mandatory = $true)] + [string]$lastName, + + [parameter(mandatory = $true)] + [string]$userName, + + [string]$jobTitle, + + [string]$email, + + [string]$phone, + + [int]$company_id, + + [int]$location_id, + + [int]$department_id, + + [int]$manager_id, + + [string]$employee_num, + + [bool]$ldap_user = $false, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + $Values = @{ + first_name = $firstName + last_name = $lastName + username = $userName + + email = $email + phone = $phone + company_id = $company_id + location_id = $location_id + department_id = $department_id + manager_id = $manager_id + jobtitle = $jobTitle + employee_num = $employee_num + notes = "Imported using SnipeitPS Script" + activated = 1 + } + + if ($ldap_user -eq $false) { + $ldap = @{ + password = $password + ldap_import = 0 + } + $Values += $ldap + } + else { + $ldap = @{ + ldap_import = 1 + } + $Values += $ldap + } + + $Body = $Values | ConvertTo-Json; + + $Parameters = @{ + Uri = "$url/api/v1/users" + Method = 'post' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) { + $result = Invoke-SnipeitMethod @Parameters + } + + $result +} diff --git a/SnipeitPS/Public/Set-User.ps1 b/SnipeitPS/Public/Set-User.ps1 new file mode 100644 index 0000000..f305e74 --- /dev/null +++ b/SnipeitPS/Public/Set-User.ps1 @@ -0,0 +1,131 @@ +<# + .SYNOPSIS + Short description + + .DESCRIPTION + Long description + + .PARAMETER id + Parameter description + + .PARAMETER first_name + Parameter description + + .PARAMETER last_name + Parameter description + + .PARAMETER userName + Parameter description + + .PARAMETER jobTitle + Parameter description + + .PARAMETER email + Parameter description + + .PARAMETER phone + Parameter description + + .PARAMETER company_id + Parameter description + + .PARAMETER location_id + Parameter description + + .PARAMETER department_id + Parameter description + + .PARAMETER manager_id + Parameter description + + .PARAMETER employee_num + Parameter description + + .PARAMETER activated + Parameter description + + .PARAMETER notes + Parameter description + + .PARAMETER url + Parameter description + + .PARAMETER apiKey + Parameter description + + .EXAMPLE + An example + + .NOTES + General notes + #> +function Set-User() { + + [CmdletBinding( + SupportsShouldProcess = $true, + ConfirmImpact = "Medium" + )] + + Param( + [parameter(mandatory = $true)] + [int]$id, + + [string]$first_name, + + [string]$last_name, + + [string]$userName, + + [string]$jobTitle, + + [string]$email, + + [string]$phone, + + [int]$company_id, + + [int]$location_id, + + [int]$department_id, + + [int]$manager_id, + + [string]$employee_num, + + [bool]$activated, + + [string]$notes, + + [parameter(mandatory = $true)] + [string]$url, + + [parameter(mandatory = $true)] + [string]$apiKey + ) + + $Values = @{} + + $exclude = @('id', 'url', 'apiKey') + $excludeRegex = [string]::Join('|', $exclude) # create the regex + + foreach ($psbp in $PSBoundParameters.GetEnumerator()) { + if ($psbp.Key -notmatch $excludeRegex) { + $Values.Add($psbp.Key, $psbp.Value) + } + } + + $Body = $Values | ConvertTo-Json; + + $Parameters = @{ + Uri = "$url/api/v1/users/$id" + Method = 'PATCH' + Body = $Body + Token = $apiKey + } + + If ($PSCmdlet.ShouldProcess("ShouldProcess?")) { + $result = Invoke-SnipeitMethod @Parameters + } + + $result +} diff --git a/SnipeitPS/SnipeItPS.psd1 b/SnipeitPS/SnipeItPS.psd1 index 2a45466aa6629aba3cc601ea56b7bbc38365044b..4e10ab59002769975316eb060501136e64159a8e 100644 GIT binary patch delta 290 zcmccQyufWkj?iR3IgZJvM7SoG2}yz36NFU2^bH}A$qhmRP_`aioq(_coNXnn1ZKww z>wxJFC=D`ipRfj4?3u6;T)mPA#10z~h#d(c5dEh_cqaEjcGx#y2GL%nVFCq;!PYZ7DKd5<1q6l|Ji3&05Om>tLm4)hL&}Hyp$Y)4qNMtBs h$ON+T7}OcSDnS0{bq0#$G86!1^B5{OXNqR>008ZZQXBvP delta 104 zcmZ4BcFB1|j?m;1A(hDsfY?ivYw|TADKO0>tTI_oSZi{Eu+HQuKn#+*B&;;~kFe2X xGZCZ71tKbw=KwKSTts5>ClR&D3ZhDr=ZR`fz96bMnN3V@vW=L`=3QcGJOCQiA^89R From 57512d50f7c5ba667060efb859675a7223994085 Mon Sep 17 00:00:00 2001 From: Stephen Maunder Date: Sat, 17 Mar 2018 21:35:46 +0000 Subject: [PATCH 20/20] Fix build download for pandoc --- SnipeItPS.build.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/SnipeItPS.build.ps1 b/SnipeItPS.build.ps1 index 5bbf1b5..2044ef4 100644 --- a/SnipeItPS.build.ps1 +++ b/SnipeItPS.build.ps1 @@ -56,6 +56,7 @@ task InstallPandoc -If (-not (Test-Path Tools\pandoc.exe)) { # Get latest bits $latestRelease = "https://github.com/jgm/pandoc/releases/download/1.19.2.1/pandoc-1.19.2.1-windows.msi" + [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 Invoke-WebRequest -Uri $latestRelease -OutFile "$($env:temp)\pandoc.msi" # Extract bits