Skip to content

Commit

Permalink
fix #313
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Brownstein committed Dec 13, 2024
1 parent eec8edc commit 7b62b26
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion VenafiPS/Private/Get-VcData.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function Get-VcData {
}

if ( $FailOnNotFound -and -not $returnObject ) {
throw "'$InputObject' of type $Type not found"
throw "$Type '$InputObject' not found"
}

switch ($PSCmdlet.ParameterSetName) {
Expand Down
36 changes: 30 additions & 6 deletions VenafiPS/Public/New-VcCertificate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function New-VcCertificate {
[Parameter(Mandatory)]
[String] $Application,

[Parameter(Mandatory)]
[Parameter()]
[String] $IssuingTemplate,

[Parameter(ParameterSetName = 'Csr', Mandatory)]
Expand Down Expand Up @@ -175,14 +175,38 @@ function New-VcCertificate {
Test-VenafiSession $PSCmdlet.MyInvocation

# validation
$thisApp = Get-VcApplication -Application $Application
$thisApp = Get-VcData -Type Application -InputObject $Application -Object
if ( -not $thisApp ) {
throw "Application $Application does not exist"
}

$thisTemplate = Get-VcIssuingTemplate -IssuingTemplate $IssuingTemplate
if ( -not $thisTemplate ) {
throw "Issuing template $IssuingTemplate does not exist"
if ( -not $IssuingTemplate ) {
# issuing template not provided, see if the app has one
switch ($thisApp.issuingTemplate.Count) {
0 {
throw 'No templates associated with this application'
}

1 {
# there is only one template, use it
$thisTemplateId = $thisApp.issuingTemplate[0].issuingTemplateId
}

Default {
throw 'IssuingTemplate is required when the application has more than 1 template associated'
}
}
}
else {
# template provided, check if name or alias or id
if ( $IssuingTemplate -in $thisApp.issuingTemplate.name ) {
# name is an alias, get template id from app
$thisTemplateId = $thisApp.issuingTemplate | Where-Object { $_.name -eq $IssuingTemplate } | Select-Object -ExpandProperty issuingTemplateId
}
else {
# lookup provided value, name or id
$thisTemplateId = Get-VcData -Type IssuingTemplate -InputObject $IssuingTemplate -FailOnNotFound
}
}

if ( $ValidUntil ) {
Expand All @@ -202,7 +226,7 @@ function New-VcCertificate {
Body = @{
isVaaSGenerated = $true
applicationId = $thisApp.applicationId
certificateIssuingTemplateId = $thisTemplate.issuingTemplateId
certificateIssuingTemplateId = $thisTemplateId
validityPeriod = $validity
}
}
Expand Down

0 comments on commit 7b62b26

Please sign in to comment.