Skip to content
This repository has been archived by the owner on Oct 21, 2023. It is now read-only.

Commit

Permalink
!deploy fixes for #4
Browse files Browse the repository at this point in the history
  • Loading branch information
scrthq committed Jun 27, 2017
1 parent 698e206 commit 649fd2d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 15 deletions.
50 changes: 37 additions & 13 deletions Vaporshell/Public/Export-Vaporshell.ps1
Expand Up @@ -44,7 +44,11 @@ function Export-Vaporshell {
})]
[PSTypeName('Vaporshell.Template')]
$VaporshellTemplate,
[parameter(Mandatory = $true,Position = 1)]
[parameter(Mandatory = $false,Position = 1)]
[ValidateSet("JSON","YAML")]
[System.String]
$As = "JSON",
[parameter(Mandatory = $false,Position = 2)]
[System.String]
$Path,
[parameter(Mandatory = $false)]
Expand All @@ -61,23 +65,43 @@ function Export-Vaporshell {
}
}
Process {
Write-Verbose "Exporting template to: $Path"
ConvertTo-Json -Depth 100 -InputObject $VaporshellTemplate -Verbose:$false | Set-Content -Path $Path @ForcePref -Verbose:$false
Write-Verbose "Converting template object to JSON"
$JSON = ConvertTo-Json -Depth 100 -InputObject $VaporshellTemplate -Verbose:$false
}
End {
if ($ValidateTemplate) {
if (Get-Command aws) {
Write-Verbose "Validating template"
$Path = (Resolve-Path $Path).Path
$fileUrl = "$($Path.Replace("\","/"))"
if ($val = aws cloudformation validate-template --template-body fileb://$fileUrl) {
Write-Host -ForegroundColor Green "The template was validated successfully!`n"
return $val
}
if ($As -eq "YAML") {
if (Get-Command cfn-flip -ErrorAction SilentlyContinue) {
Write-Verbose "Converting JSON to YAML with cfn-flip"
$Final = $JSON | cfn-flip
}
else {
Write-Warning "AWS CLI tools not found in PATH! Skipping validation to prevent failure."
Write-Warning "cfn-flip not found in PATH! Skipping conversion to YAML to prevent failure."
$Final = $JSON
}
}
else {
$Final = $JSON
}
if ($Path) {
Write-Verbose "Exporting template to: $Path"
$Final | Set-Content -Path $Path @ForcePref -Verbose:$false
if ($ValidateTemplate) {
if (Get-Command aws -ErrorAction SilentlyContinue) {
Write-Verbose "Validating template"
$Path = (Resolve-Path $Path).Path
$fileUrl = "$($Path.Replace("\","/"))"
if ($val = aws cloudformation validate-template --template-body fileb://$fileUrl) {
Write-Host -ForegroundColor Green "The template was validated successfully!`n"
return $val
}
}
else {
Write-Warning "AWS CLI tools not found in PATH! Skipping validation to prevent failure."
}
}
}
else {
return $Final
}
}
}
8 changes: 8 additions & 0 deletions Vaporshell/Public/Import-Vaporshell.ps1
Expand Up @@ -102,6 +102,14 @@ function Import-Vaporshell {
$ObjName = "Resources"
$allowedTypes = "Vaporshell.Transform","Vaporshell.Resource"
foreach ($obj in $args) {
if ($obj.Props.Type -like "AWS::Serverless*" -and $this.Transform -ne "AWS::Serverless-2016-10-31") {
if ( -not ($this.Transform)) {
$this | Add-Member -MemberType NoteProperty -Name Transform -Value "AWS::Serverless-2016-10-31"
}
else {
$this.Transform = "AWS::Serverless-2016-10-31"
}
}
if ([string]$($obj.PSTypeNames) -match "($(($allowedTypes|ForEach-Object{[RegEx]::Escape($_)}) -join '|'))") {
if ( -not ($this.$ObjName)) {
Write-Verbose "The $ObjName property was not found on the Vaporshell template. Adding the property to the template now."
Expand Down
7 changes: 6 additions & 1 deletion Vaporshell/Public/Initialize-Vaporshell.ps1
Expand Up @@ -117,7 +117,12 @@ function Initialize-Vaporshell {
$allowedTypes = "Vaporshell.Transform","Vaporshell.Resource"
foreach ($obj in $args) {
if ($obj.Props.Type -like "AWS::Serverless*" -and $this.Transform -ne "AWS::Serverless-2016-10-31") {
$this.Transform = "AWS::Serverless-2016-10-31"
if ( -not ($this.Transform)) {
$this | Add-Member -MemberType NoteProperty -Name Transform -Value "AWS::Serverless-2016-10-31"
}
else {
$this.Transform = "AWS::Serverless-2016-10-31"
}
}
if ([string]$($obj.PSTypeNames) -match "($(($allowedTypes|ForEach-Object{[RegEx]::Escape($_)}) -join '|'))") {
if ( -not ($this.$ObjName)) {
Expand Down
Expand Up @@ -175,7 +175,7 @@ function New-SAMFunction {
}
})]
$Environment,
[parameter(Mandatory = $true)]
[parameter(Mandatory = $false)]
[ValidateScript( {
$allowedTypes = "Vaporshell.Resource.Lambda.Function.VpcConfig","System.Collections.Hashtable"
if ([string]$($_.PSTypeNames) -match "($(($allowedTypes|ForEach-Object{[RegEx]::Escape($_)}) -join '|'))") {
Expand Down

0 comments on commit 649fd2d

Please sign in to comment.