Skip to content

Commit

Permalink
Merge pull request #13 from pspete/dev
Browse files Browse the repository at this point in the history
Update Minimum PowerShell Version
  • Loading branch information
pspete authored Mar 27, 2020
2 parents 731a4ce + 3282926 commit 318f057
Show file tree
Hide file tree
Showing 10 changed files with 354 additions and 124 deletions.
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# CredentialRetriever Changelog

## 3.4.19 (March 27th 2020)

- Changed minimum required PowerShell version to 5.1

## 3.3.16 (December 12th 2019)

- Update `Get-CCPCredential`
- Added `certificate` parameter for specifyng an x509 certificate to use for the connection.
- Added `certificate` parameter for specifying an x509 certificate to use for the connection.

## 3.2.11 (April 30th 2019)
## 3.2.12 (April 30th 2019)

- Fix `Get-AIMCredential`
- Adds support for spaces in application names.
Expand Down Expand Up @@ -35,4 +39,4 @@ Module updated to work with a locally installed Credential Provider in addition

## 1.0.0 (April 2018)

Initial Release
Initial Release
6 changes: 3 additions & 3 deletions CredentialRetriever/CredentialRetriever.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
# CompanyName = ''

# Copyright statement for this module
Copyright = '(c) 2018 Pete Maan. All rights reserved.'
Copyright = '(c) 2020 PSPETE LTD. All rights reserved.'

# Description of the functionality provided by this module
Description = 'Retrieve Credentials from CyberArk Central Credential Provider Web Service, or Local Credential Provider using CLIPasswordSDK'

# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '3.0'
PowerShellVersion = '5.1'

# Name of the Windows PowerShell host required by this module
# PowerShellHostName = ''
Expand Down Expand Up @@ -69,7 +69,7 @@
PSData = @{

# Tags applied to this module. These help with module discovery in online galleries.
Tags = @('CyberArk', 'REST', 'API', 'Security', 'AIM', 'CentralCredentialProvider', 'CredentialProvider', 'CLIPasswordSDK')
Tags = @('CyberArk', 'REST', 'API', 'Security', 'AIM', 'AAM', 'CentralCredentialProvider', 'CredentialProvider', 'CLIPasswordSDK')

# A URL to the license for this module.
LicenseUri = 'https://github.com/pspete/CredentialRetriever/blob/master/LICENSE.md'
Expand Down
27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
# CredentialRetriever

[![Build status](https://ci.appveyor.com/api/projects/status/s2x3alg52ctp2pyl/branch/master?svg=true)](https://ci.appveyor.com/project/pspete/CredentialRetriever/branch/master)
[![AppVeyor tests](https://img.shields.io/appveyor/tests/pspete/CredentialRetriever.svg)](https://ci.appveyor.com/project/pspete/CredentialRetriever)
[![Coverage Status](https://coveralls.io/repos/github/pspete/CredentialRetriever/badge.svg)](https://coveralls.io/github/pspete/CredentialRetriever)
[![PowerShell Gallery](https://img.shields.io/powershellgallery/v/CredentialRetriever.svg)](https://www.powershellgallery.com/packages/CredentialRetriever)
[![license](https://img.shields.io/github/license/pspete/CredentialRetriever.svg)](https://github.com/pspete/CredentialRetriever/blob/master/LICENSE)
| Master Branch | Latest Build | CodeFactor | Coverage | PowerShell Gallery | License |
|--------------------------|-------------------------|---------------------------|-----------------------------|---------------------------|----------------------------|
|[![appveyor][]][av-site] |[![tests][]][tests-site] | [![codefactor][]][cf-site]| [![codecov][]][codecov-link]| [![psgallery][]][ps-site] |[![license][]][license-link]|
| | | | [![coveralls][]][cv-site] | [![downloads][]][ps-site] | |

[appveyor]:https://ci.appveyor.com/api/projects/status/s2x3alg52ctp2pyl/branch/master?svg=true
[av-site]:https://ci.appveyor.com/project/pspete/CredentialRetriever/branch/master
[coveralls]:https://coveralls.io/repos/github/pspete/CredentialRetriever/badge.svg?branch=master
[cv-site]:https://coveralls.io/github/pspete/CredentialRetriever?branch=master
[psgallery]:https://img.shields.io/powershellgallery/v/CredentialRetriever.svg
[ps-site]:https://www.powershellgallery.com/packages/CredentialRetriever
[tests]:https://img.shields.io/appveyor/tests/pspete/CredentialRetriever.svg
[tests-site]:https://ci.appveyor.com/project/pspete/CredentialRetriever
[downloads]:https://img.shields.io/powershellgallery/dt/credentialretriever.svg?color=blue
[cf-site]:https://www.codefactor.io/repository/github/pspete/credentialretriever
[codefactor]:https://www.codefactor.io/repository/github/pspete/credentialretriever/badge
[codecov]:https://codecov.io/gh/pspete/CredentialRetriever/branch/master/graph/badge.svg
[codecov-link]:https://codecov.io/gh/pspete/CredentialRetriever
[license]:https://img.shields.io/github/license/pspete/credentialretriever.svg
[license-link]:https://github.com/pspete/CredentialRetriever/blob/master/LICENSE.md

## **CyberArk Central Credential Provider PowerShell Retriever**

Expand Down Expand Up @@ -49,7 +64,7 @@ Use the `ToCredential()` Method to convert the returned Username/Password to a `

### Prerequisites

- Requires Powershell v3 (minimum)
- Requires Powershell v5.1 (minimum)
- CyberArk Central Credential Provider Web Service, And\Or
- CyberArk Credential Provider

Expand Down
22 changes: 19 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
# version format
version: 3.3.{build}
version: 3.4.{build}

environment:
#GIT_TRACE: 1
access_token:
secure: eWAovbJD8C/F5ObWegnOimwNFyeU1vXzW6lwbJzhHpSUgjT+CMexMcPUBMKrm+Wl
psgallery_key:
secure: FuPgJskczZMptxRgdUlBAy7OYmXBQl4zq86kXXSmBt6wKudnM2PK7W6cM7bj0te1
coveralls_key:
secure: 9FaqY8bTu/NyXmXKDGw3qDHe/JbyZPY6F1Y0NcJ9Yrm/m0qGVemONpUvLYn9Es2U
github_email:
secure: x5ljenzXfYXkzpEu9eX7AQvb3AkFbiXG2NndMzw9Zc4=
#sig_key:
#secure: LPEv2aGCLb1WPw89OFF8gmhk5tVZtOAPaUJ9cAATBnD1+qREYmvh/fH53NbJSNPD9sMryoTv+hwq+McL2sNw3WAnd5iAnKIN3gu34TFM21sYsA2UOSS7sNXXdkfjzLZlnqQlj9hmokNsbEbUQhPffRcX93HZ5ykrH+NKgc3AeYc20JfdLgqUzt/TYumPlw3DXtHbmAD3Pt8ZDW9VXEozGHzMCDRwCT+WnF4hhOa+mw6l82yqIJLYQSD9TTq8weANNAK3XZFpJZ6ssdyvzzS/q72F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H71KsByAlrt3+65zVIgYr5F0HiadU3gly1mQ85tHi8ycd9f1mGVpsD4FXRY9baklVaW5NhZL8Uzg9UvhfdRhF2ousToYql9kvmFBARASA2HczwqmUPOuX+g==
#PfxSecure:
#secure: Kkp5iutKCw8ACijkd5Et8xUjF4e39dJRuoaTWIHem5tVaF5QeqUnrPSjkPsNDwro

skip_tags: true

skip_commits:
files:
- docs\*
- .github\*
- .vscode\*
- README.md
Expand All @@ -32,13 +42,19 @@ only_commits:
image: Visual Studio 2017

install:
- ps: . .\build\install.ps1
- pwsh.exe -File .\build\install.ps1

build_script:
- pwsh.exe -File .\build\build.ps1
- ps: . .\build\build.ps1

test_script:
#- ps: . .\build\test.ps1
- pwsh.exe -File .\build\test.ps1

deploy_script:
- pwsh.exe -File .\build\deploy.ps1
- ps: . .\build\deploy-github.ps1
- pwsh.exe -File .\build\deploy-psgallery.ps1

on_failure:
- ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
84 changes: 69 additions & 15 deletions build/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,88 @@ Write-Host "Build version : $env:APPVEYOR_BUILD_VERSION"
Write-Host "Manifest version : $CurrentVersion"
Write-Host "Author : $env:APPVEYOR_REPO_COMMIT_AUTHOR"
Write-Host "Branch : $env:APPVEYOR_REPO_BRANCH"
Write-Host "Build Folder : $env:APPVEYOR_BUILD_FOLDER"

#---------------------------------#
# BuildScript #
#---------------------------------#
#---------------------------------#
# Update module manifest #
#---------------------------------#
if($CurrentVersion -eq $env:APPVEYOR_BUILD_VERSION) {
If ([System.Version]$($env:APPVEYOR_BUILD_VERSION) -le [System.Version]$CurrentVersion) {

Write-Host "No build tasks required... skipping"
throw "Build Version Not Greater than Current Version"

}

else {

Write-Host "Updating Manifest Version to $env:APPVEYOR_BUILD_VERSION"
Else {

Try {

#---------------------------------#
# BuildScript #
#---------------------------------#
#---------------------------------#
# Update module manifest #
#---------------------------------#
Write-Host "Updating Manifest Version to $env:APPVEYOR_BUILD_VERSION" -ForegroundColor Cyan

#Replace version in manifest with build version from appveyor
((Get-Content $ManifestPath).replace("= '$($currentVersion)'", "= '$($env:APPVEYOR_BUILD_VERSION)'")) |
Set-Content $ManifestPath -ErrorAction Stop
((Get-Content $ManifestPath).replace("= '$($currentVersion)'", "= '$($env:APPVEYOR_BUILD_VERSION)'")) | Set-Content $ManifestPath -ErrorAction Stop

<#-- Package Version Release --#>
$Directory = New-Item -ItemType Directory -Path "Release\$($env:APPVEYOR_PROJECT_NAME)\$($env:APPVEYOR_BUILD_VERSION)" -Force -ErrorAction Stop
$OutputArchive = "$($env:APPVEYOR_PROJECT_NAME)-v$($env:APPVEYOR_BUILD_VERSION).zip"

$OutputArchive = "$($env:APPVEYOR_PROJECT_NAME)-v$($env:APPVEYOR_BUILD_VERSION).zip"
$ReleaseSource = $(Resolve-Path .\$env:APPVEYOR_PROJECT_NAME)

<#-- Create Release Folder --#>
$Directory = New-Item -ItemType Directory -Path "..\Release\$($env:APPVEYOR_PROJECT_NAME)\$($env:APPVEYOR_BUILD_VERSION)" -Force -ErrorAction Stop

<#-- Copy Module Files --#>
Copy-Item -Path $ReleaseSource\* -Recurse -Destination $($Directory.Fullname) -Force -ErrorAction Stop


If ((-not ($ENV:APPVEYOR_PULL_REQUEST_NUMBER)) -and (($ENV:APPVEYOR_REPO_BRANCH -eq 'master') -and ($ENV:APPVEYOR_BUILD_VERSION -ge "1.0.0"))) {

If (($ENV:sig_key) -and ($ENV:PfxSecure)) {

Write-Host "Signing Files" -ForegroundColor Cyan

Try {
$KeyPath = Join-Path $([System.Environment]::GetEnvironmentVariable("TEMP")) cert.pfx
[IO.File]::WriteAllBytes($KeyPath, [Convert]::FromBase64String($($env:sig_key)))

$SecurePW = ConvertTo-SecureString -String $($env:PfxSecure) -Force -AsPlainText
$Cred = New-Object -TypeName "System.Management.Automation.PSCredential" -ArgumentList "UserName", $SecurePW

$Cert = Get-ChildItem -Path $KeyPath | Import-PfxCertificate -CertStoreLocation "Cert:\CurrentUser\My" -Password $Cred.Password

$null = Get-ChildItem -Path "$($Directory.Fullname)\*.ps*" -Recurse | Set-AuthenticodeSignature -Certificate $Cert -TimestampServer 'http://timestamp.digicert.com'
$null = New-FileCatalog -CatalogVersion 2 -CatalogFilePath "$($Directory.Fullname)\$($env:APPVEYOR_PROJECT_NAME).cat" -Path $($Directory.Fullname)
$null = Set-AuthenticodeSignature -Certificate $Cert -TimestampServer 'http://timestamp.digicert.com' -FilePath "$($Directory.Fullname)\$($env:APPVEYOR_PROJECT_NAME).cat"
}
Catch {
Throw $_
}
Finally {

Get-ChildItem -Path "Cert:\CurrentUser\My" -Recurse -CodeSigningCert | Remove-Item -Force
Remove-Item -Path $KeyPath -Force
Remove-Variable -Name SecurePW -Force
Remove-Variable -Name Cred -Force

}

}

}

<#-- Create Package ---#>
Compress-Archive $Directory -DestinationPath ..\$OutputArchive -ErrorAction Stop

<#-- Release Artifact --#>
Write-Host "Release Artifact : $OutputArchive"
Push-AppveyorArtifact ..\$OutputArchive -FileName $OutputArchive -DeploymentName "$env:APPVEYOR_PROJECT_NAME-latest"

}

Catch {

Write-Warning "Manifest Update failed."
throw $_

}
Expand Down
116 changes: 116 additions & 0 deletions build/deploy-github.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<#---------------------------------
Update version number on GitHub to match build version
---------------------------------#>


if (-not ($ENV:APPVEYOR_PULL_REQUEST_NUMBER)) {

If ($ENV:APPVEYOR_REPO_BRANCH -eq 'master') {

<# Master Branch #>
Write-Host "Deploy Process: GitHub Repository" -ForegroundColor Yellow

<#---------------------------------#>
<# If Not a PR #>
<# Push psd1 file to ORIGIN Branch #>
<#---------------------------------#>

Try {

Write-Host "Push Updated $($env:APPVEYOR_PROJECT_NAME).psd1 to GitHub..." -ForegroundColor Yellow

git config --global core.safecrlf false
git config --global credential.helper store
Add-Content "$HOME\.git-credentials" "https://$($env:access_token):x-oauth-basic@github.com`n"
git config --global user.email "$($env:github_email)"
git config --global user.name "Pete Maan"

git checkout -q $($ENV:APPVEYOR_REPO_BRANCH)

git add $(Join-Path -Path (Join-Path -Path "$env:APPVEYOR_BUILD_FOLDER" -ChildPath "$env:APPVEYOR_PROJECT_NAME") -ChildPath "$env:APPVEYOR_PROJECT_NAME.psd1")

git status

git commit -s -m "Update Version: $($env:APPVEYOR_BUILD_VERSION)"

git push --porcelain origin $($ENV:APPVEYOR_REPO_BRANCH)

Write-Host "$($env:APPVEYOR_PROJECT_NAME) version $($env:APPVEYOR_BUILD_VERSION) pushed to GitHub." -ForegroundColor Cyan

}

Catch {

Write-Host "Push to GitHub failed." -ForegroundColor Red
throw $_

}

Write-Host "Deploy Process: GitHub Release" -ForegroundColor Yellow

If ($env:APPVEYOR_BUILD_VERSION -ge "1.0.0") {

<# Create New Release #>

$token = $env:access_token
$uploadFilePath = Resolve-Path "..\$($env:APPVEYOR_PROJECT_NAME)-v$($env:APPVEYOR_BUILD_VERSION).zip"
$releaseName = "v$($env:APPVEYOR_BUILD_VERSION)"
$repo = "pspete/$env:APPVEYOR_PROJECT_NAME"

$headers = @{
"Authorization" = "token $token"
"Content-type" = "application/json"
}

$body = @{
tag_name = $releaseName
name = $releaseName
body = "$($env:APPVEYOR_PROJECT_NAME) v$($env:APPVEYOR_BUILD_VERSION)"
draft = $false
prerelease = $false
}

Write-Host "Creating release $releaseName..." -NoNewline

try {
$json = (ConvertTo-Json $body)
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/$repo/releases" -Headers $headers -Method POST -Body $json
$uploadUrl = $release.upload_url.Replace("{?name,label}", "") + "?name=" + [IO.Path]::GetFileName($uploadFilePath)
Write-Host "OK" -ForegroundColor Green

Write-Host "Uploading asset $($env:APPVEYOR_PROJECT_NAME)-v$($env:APPVEYOR_BUILD_VERSION).zip..." -NoNewline

$data = [System.IO.File]::ReadAllBytes($uploadFilePath)
$wc = New-Object Net.WebClient
$wc.Headers['Content-type'] = 'application/octet-stream'
$wc.Headers['Authorization'] = "token $token"

$null = $wc.UploadData($uploadUrl, "POST", $data)
Write-Host "OK" -ForegroundColor Green
}
catch {

Write-Host "GitHub Release Failed." -ForegroundColor Red
throw $_

}

}

}

Else {

<# Not Master Branch #>
Write-Host "$ENV:APPVEYOR_REPO_BRANCH Branch; No Release" -ForegroundColor Cyan
exit;

}

}

Else {

Write-Host "Skipping Deploy Process: GitHub Repository" -ForegroundColor Yellow

}
Loading

0 comments on commit 318f057

Please sign in to comment.