Skip to content

Commit

Permalink
Aws s3 support (#8)
Browse files Browse the repository at this point in the history
* Issue #3
- Added the concept of private functions.
- AWS S3 bucker support for Get-ISHPrerequisites and Set-ISHToolAntennaHouseLicense
- Some refactoring

* #3
Fixed small issues in the Publish-Module.ps1
  • Loading branch information
Sarafian authored Feb 6, 2017
1 parent 2b06778 commit ecb982e
Show file tree
Hide file tree
Showing 37 changed files with 335 additions and 62 deletions.
13 changes: 6 additions & 7 deletions Automation/Publish-Module.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ param(
[string]$NuGetApiKey=$null,
[Parameter(Mandatory=$true,ParameterSetName="KC2016+Dev")]
[ValidateScript({$_ -ne "PSGallery"})]
[string]$DevRepository,
[string]$DevRepository #,
<#
[Parameter(Mandatory=$true,ParameterSetName="KC2016")]
[Parameter(Mandatory=$false,ParameterSetName="KC2016+Dev")]
[switch]$ISH12=$false,
[Parameter(Mandatory=$true,ParameterSetName="KC2016+Dev")]
[Parameter(Mandatory=$false,ParameterSetName="KC2016+Dev")]
[switch]$ISH13=$false
#>
)

$moduleNamesToPublish=@()
Expand All @@ -40,10 +42,7 @@ switch ($PSCmdlet.ParameterSetName)
'KC2016+Dev' {
$publishDebug=$true
$repository=$DevRepository
if($ISH12)
{
$moduleNamesToPublish+="ISHServer.12"
}
$moduleNamesToPublish+="ISHServer.12"
$moduleNamesToPublish+="ISHServer.13"
break
}
Expand Down Expand Up @@ -88,7 +87,7 @@ foreach($moduleName in $moduleNamesToPublish)
New-Item -Path $modulePath -ItemType Directory|Out-Null
Write-Verbose "Temporary working folder $modulePath is ready"

Copy-Item -Path "$PSScriptRoot\..\Source\Modules\ISHServer\*.*" -Destination $modulePath -Recurse
Copy-Item -Path "$PSScriptRoot\..\Source\Modules\ISHServer\*" -Destination $modulePath -Recurse
switch ($moduleName)
{
'ISHServer.12' {
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
**1.1**

- Upgraded the SDLDevTools PowerShell module to version 0.2
- `Get-ISHPrerequisites` now supports S3 buckets as source.
- `Set-ISHToolAntennaHouseLicense` now supports S3 buckets as source.
- `Test-RunningAsElevated` is now a private function in the module.

**1.0**

- Split from [ISHBootstrap](https://github.com/Sarafian/ISHBootstrap).
Expand Down
60 changes: 52 additions & 8 deletions Source/Modules/ISHServer/Get-ISHPrerequisites.ISH12.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ function Get-ISHPrerequisites
[pscredential]$Credential,
[Parameter(Mandatory=$true,ParameterSetName="From FTP")]
[string]$FTPFolder,
[Parameter(Mandatory=$true,ParameterSetName="From AWS S3")]
[string]$BucketName,
[Parameter(Mandatory=$true,ParameterSetName="From AWS S3")]
[string]$FolderKey,
[Parameter(Mandatory=$false,ParameterSetName="From AWS S3")]
[string]$AccessKey,
[Parameter(Mandatory=$false,ParameterSetName="From AWS S3")]
[string]$ProfileName,
[Parameter(Mandatory=$false,ParameterSetName="From AWS S3")]
[string]$ProfileLocation,
[Parameter(Mandatory=$false,ParameterSetName="From AWS S3")]
[string]$Region,
[Parameter(Mandatory=$false,ParameterSetName="From AWS S3")]
[string]$SecretKey,
[Parameter(Mandatory=$false,ParameterSetName="From AWS S3")]
[string]$SessionToken,
[Parameter(Mandatory=$true,ParameterSetName="No Download")]
[switch]$FileNames
)
Expand All @@ -32,12 +48,21 @@ function Get-ISHPrerequisites
{
if($PSCmdlet.ParameterSetName -ne "No Download")
{
. $PSScriptRoot\Test-RunningAsElevated.ps1
. $PSScriptRoot\Private\Test-RunningAsElevated.ps1
Test-RunningAsElevated -StopCallerPSCmdlet $PSCmdlet
}

. $PSScriptRoot\Get-ISHServerFolderPath.ps1
. $PSScriptRoot\Get-ISHOSInfo.ps1

if(-not ($FTPFolder.EndsWith("/")))
{
$FTPFolder+="/"
}
if(-not ($FolderKey.EndsWith("/")))
{
$FolderKey+="/"
}
}

process
Expand Down Expand Up @@ -68,16 +93,35 @@ function Get-ISHPrerequisites
switch ($PSCmdlet.ParameterSetName)
{
'From FTP' {
Import-Module PSFTP -ErrorAction Stop
. $PSScriptRoot\Private\Get-ISHFTPItem.ps1

$localPath=Get-ISHServerFolderPath
Set-FTPConnection -Server $FTPHost -Credentials $Credential -UseBinary -KeepAlive -UsePassive | Out-Null
$paths=@()
$filesToDownload | ForEach-Object {
$ftpUrl="$FTPFolder$_"

Write-Debug "ftpUrl=$ftpUrl"
Get-FTPItem -Path $ftpUrl -LocalPath $localPath -Overwrite | Out-Null
Write-Verbose "Downloaded $ftpUrl"
$paths+="$FTPFolder$_"
}
Get-ISHFTPItem -FTPHost $FTPHost -Credential $Credential -Path $paths -LocalPath $localPath
break
}
'From AWS S3' {
. $PSScriptRoot\Private\Get-ISHS3Object.ps1

$localPath=Get-ISHServerFolderPath
$hash=@{
BucketName=$BucketName
LocalFolder=$localPath
AccessKey=$AccessKey
ProfileName=$ProfileName
ProfileLocation=$ProfileLocation
Region=$Region
SecretKey=$SecretKey
SessionToken=$SessionToken
}
$keys=@()
$filesToDownload | ForEach-Object {
$keys+="$FolderKey$_"
}
Get-ISHS3Object -Key $keys @hash
break
}
'No Download' {
Expand Down
60 changes: 52 additions & 8 deletions Source/Modules/ISHServer/Get-ISHPrerequisites.ISH13.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ function Get-ISHPrerequisites
[pscredential]$Credential,
[Parameter(Mandatory=$true,ParameterSetName="From FTP")]
[string]$FTPFolder,
[Parameter(Mandatory=$true,ParameterSetName="From AWS S3")]
[string]$BucketName,
[Parameter(Mandatory=$true,ParameterSetName="From AWS S3")]
[string]$FolderKey,
[Parameter(Mandatory=$false,ParameterSetName="From AWS S3")]
[string]$AccessKey,
[Parameter(Mandatory=$false,ParameterSetName="From AWS S3")]
[string]$ProfileName,
[Parameter(Mandatory=$false,ParameterSetName="From AWS S3")]
[string]$ProfileLocation,
[Parameter(Mandatory=$false,ParameterSetName="From AWS S3")]
[string]$Region,
[Parameter(Mandatory=$false,ParameterSetName="From AWS S3")]
[string]$SecretKey,
[Parameter(Mandatory=$false,ParameterSetName="From AWS S3")]
[string]$SessionToken,
[Parameter(Mandatory=$true,ParameterSetName="No Download")]
[switch]$FileNames
)
Expand All @@ -32,12 +48,21 @@ function Get-ISHPrerequisites
{
if($PSCmdlet.ParameterSetName -ne "No Download")
{
. $PSScriptRoot\Test-RunningAsElevated.ps1
. $PSScriptRoot\Private\Test-RunningAsElevated.ps1
Test-RunningAsElevated -StopCallerPSCmdlet $PSCmdlet
}

. $PSScriptRoot\Get-ISHServerFolderPath.ps1
. $PSScriptRoot\Get-ISHOSInfo.ps1

if(-not ($FTPFolder.EndsWith("/")))
{
$FTPFolder+="/"
}
if(-not ($FolderKey.EndsWith("/")))
{
$FolderKey+="/"
}
}

process
Expand Down Expand Up @@ -77,16 +102,35 @@ function Get-ISHPrerequisites
switch ($PSCmdlet.ParameterSetName)
{
'From FTP' {
Import-Module PSFTP -ErrorAction Stop
. $PSScriptRoot\Private\Get-ISHFTPItem.ps1

$localPath=Get-ISHServerFolderPath
Set-FTPConnection -Server $FTPHost -Credentials $Credential -UseBinary -KeepAlive -UsePassive | Out-Null
$paths=@()
$filesToDownload | ForEach-Object {
$ftpUrl="$FTPFolder$_"

Write-Debug "ftpUrl=$ftpUrl"
Get-FTPItem -Path $ftpUrl -LocalPath $localPath -Overwrite | Out-Null
Write-Verbose "Downloaded $ftpUrl"
$paths+="$FTPFolder$_"
}
Get-ISHFTPItem -FTPHost $FTPHost -Credential $Credential -Path $paths -LocalPath $localPath
break
}
'From AWS S3' {
. $PSScriptRoot\Private\Get-ISHS3Object.ps1

$localPath=Get-ISHServerFolderPath
$hash=@{
BucketName=$BucketName
LocalFolder=$localPath
AccessKey=$AccessKey
ProfileName=$ProfileName
ProfileLocation=$ProfileLocation
Region=$Region
SecretKey=$SecretKey
SessionToken=$SessionToken
}
$keys=@()
$filesToDownload | ForEach-Object {
$keys+="$FolderKey$_"
}
Get-ISHS3Object -Key $keys @hash
break
}
'No Download' {
Expand Down
7 changes: 6 additions & 1 deletion Source/Modules/ISHServer/Get-ISHServerFolderPath.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@ function Get-ISHServerFolderPath

begin
{
. $PSScriptRoot\Test-RunningAsElevated.ps1
. $PSScriptRoot\Private\Test-RunningAsElevated.ps1
Test-RunningAsElevated -StopCallerPSCmdlet $PSCmdlet
}

process
{
$moduleName=$($MyInvocation.MyCommand.Module)
if(-not $moduleName)
{
$moduleName="ISHServer.Debug"
Write-Warning "Executed the cmdlet directly. Setting module name to $moduleName"
}
$programDataPath=Join-Path $env:ProgramData $moduleName
if(-not (Test-Path $programDataPath))
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Modules/ISHServer/Grant-ISHUserLogOnAsService.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function Grant-ISHUserLogOnAsService{

begin
{
. $PSScriptRoot\Test-RunningAsElevated.ps1
. $PSScriptRoot\Private\Test-RunningAsElevated.ps1
Test-RunningAsElevated -StopCallerPSCmdlet $PSCmdlet
}

Expand Down
13 changes: 10 additions & 3 deletions Source/Modules/ISHServer/ISHServer.12.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
#>

$importNames=@(
$exportNames=@(
#region Helpers
"Get-ISHOSInfo"
"Get-ISHNETInfo"
Expand Down Expand Up @@ -68,7 +68,14 @@ $importNames=@(
#endregion
)

$importNames | ForEach-Object {. $PSScriptRoot\$_.ps1 }
$privateNames=@(
"Get-ISHFTPItem"
"Get-ISHS3Object"
"Test-RunningAsElevated"
)

$privateNames | ForEach-Object {. $PSScriptRoot\Private\$_.ps1 }
$exportNames | ForEach-Object {. $PSScriptRoot\$_.ps1 }

$exportedMemberNames=$importNames -replace "\.ISH[0-9]+",""
$exportedMemberNames=$exportNames -replace "\.ISH[0-9]+",""
Export-ModuleMember $exportedMemberNames
13 changes: 10 additions & 3 deletions Source/Modules/ISHServer/ISHServer.13.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.
#>

$importNames=@(
$exportNames=@(
#region Helpers
"Get-ISHOSInfo"
"Get-ISHNETInfo"
Expand Down Expand Up @@ -65,7 +65,14 @@ $importNames=@(
#endregion
)

$importNames | ForEach-Object {. $PSScriptRoot\$_.ps1 }
$privateNames=@(
"Get-ISHFTPItem"
"Get-ISHS3Object"
"Test-RunningAsElevated"
)

$privateNames | ForEach-Object {. $PSScriptRoot\Private\$_.ps1 }
$exportNames | ForEach-Object {. $PSScriptRoot\$_.ps1 }

$exportedMemberNames=$importNames -replace "\.ISH[0-9]+",""
$exportedMemberNames=$exportNames -replace "\.ISH[0-9]+",""
Export-ModuleMember $exportedMemberNames
2 changes: 1 addition & 1 deletion Source/Modules/ISHServer/Initialize-ISHIIS.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function Initialize-ISHIIS

begin
{
. $PSScriptRoot\Test-RunningAsElevated.ps1
. $PSScriptRoot\Private\Test-RunningAsElevated.ps1
Test-RunningAsElevated -StopCallerPSCmdlet $PSCmdlet
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Modules/ISHServer/Initialize-ISHLocale.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function Initialize-ISHLocale

begin
{
. $PSScriptRoot\Test-RunningAsElevated.ps1
. $PSScriptRoot\Private\Test-RunningAsElevated.ps1
Test-RunningAsElevated -StopCallerPSCmdlet $PSCmdlet
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Modules/ISHServer/Initialize-ISHMSDTCSettings.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function Initialize-ISHMSDTCSettings

begin
{
. $PSScriptRoot\Test-RunningAsElevated.ps1
. $PSScriptRoot\Private\Test-RunningAsElevated.ps1
Test-RunningAsElevated -StopCallerPSCmdlet $PSCmdlet
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function Initialize-ISHMSDTCTransactionTimeout

begin
{
. $PSScriptRoot\Test-RunningAsElevated.ps1
. $PSScriptRoot\Private\Test-RunningAsElevated.ps1
Test-RunningAsElevated -StopCallerPSCmdlet $PSCmdlet
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Modules/ISHServer/Initialize-ISHRegional.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function Initialize-ISHRegional

begin
{
. $PSScriptRoot\Test-RunningAsElevated.ps1
. $PSScriptRoot\Private\Test-RunningAsElevated.ps1
Test-RunningAsElevated -StopCallerPSCmdlet $PSCmdlet
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Modules/ISHServer/Initialize-ISHRegionalDefault.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function Initialize-ISHRegionalDefault

begin
{
. $PSScriptRoot\Test-RunningAsElevated.ps1
. $PSScriptRoot\Private\Test-RunningAsElevated.ps1
Test-RunningAsElevated -StopCallerPSCmdlet $PSCmdlet
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Modules/ISHServer/Initialize-ISHUser.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function Initialize-ISHUser

begin
{
. $PSScriptRoot\Test-RunningAsElevated.ps1
. $PSScriptRoot\Private\Test-RunningAsElevated.ps1
Test-RunningAsElevated -StopCallerPSCmdlet $PSCmdlet
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Modules/ISHServer/Install-ISHToolAntennaHouse.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function Install-ISHToolAntennaHouse

begin
{
. $PSScriptRoot\Test-RunningAsElevated.ps1
. $PSScriptRoot\Private\Test-RunningAsElevated.ps1
Test-RunningAsElevated -StopCallerPSCmdlet $PSCmdlet

. $PSScriptRoot\Get-ISHServerFolderPath.ps1
Expand Down
2 changes: 1 addition & 1 deletion Source/Modules/ISHServer/Install-ISHToolDotNET.ISH13.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function Install-ISHToolDotNET

begin
{
. $PSScriptRoot\Test-RunningAsElevated.ps1
. $PSScriptRoot\Private\Test-RunningAsElevated.ps1
Test-RunningAsElevated -StopCallerPSCmdlet $PSCmdlet

. $PSScriptRoot\Get-ISHServerFolderPath.ps1
Expand Down
2 changes: 1 addition & 1 deletion Source/Modules/ISHServer/Install-ISHToolHtmlHelp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function Install-ISHToolHtmlHelp

begin
{
. $PSScriptRoot\Test-RunningAsElevated.ps1
. $PSScriptRoot\Private\Test-RunningAsElevated.ps1
Test-RunningAsElevated -StopCallerPSCmdlet $PSCmdlet

. $PSScriptRoot\Get-ISHServerFolderPath.ps1
Expand Down
Loading

0 comments on commit ecb982e

Please sign in to comment.