Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow specifying a Timeout value #240

Merged
merged 3 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions VenafiPS/Public/Invoke-VenafiRestMethod.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,20 @@ function Invoke-VenafiRestMethod {
[Parameter()]
[switch] $FullResponse,

[Parameter()]
[Int32] $TimeoutSec = 0,

[Parameter()]
[switch] $SkipCertificateCheck
)

$params = @{
Method = $Method
ContentType = 'application/json'
UseBasicParsing = $true
TimeoutSec = $TimeoutSec
}


if ( $PSCmdLet.ParameterSetName -eq 'Session' ) {

Expand Down Expand Up @@ -131,6 +141,7 @@ function Invoke-VenafiRestMethod {
}
}
$SkipCertificateCheck = $VenafiSession.SkipCertificateCheck
$params.TimeoutSec = $VenafiSession.TimeoutSec
break
}

Expand Down Expand Up @@ -187,14 +198,7 @@ function Invoke-VenafiRestMethod {
}
}

$uri = '{0}/{1}/{2}' -f $Server, $UriRoot, $UriLeaf

$params = @{
Method = $Method
Uri = $uri
ContentType = 'application/json'
UseBasicParsing = $true
}
$params.Uri = '{0}/{1}/{2}' -f $Server, $UriRoot, $UriLeaf

# append any headers passed in
if ( $Header ) { $allHeaders += $Header }
Expand Down
4 changes: 4 additions & 0 deletions VenafiPS/Public/New-VdcToken.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ function New-VdcToken {
You can either provide a String, SecureString, or PSCredential.
If providing a credential, the username is not used.

.PARAMETER SkipCertificateCheck
Bypass certificate validation when connecting to the server.
This can be helpful for pre-prod environments where ssl isn't setup on the website or you are connecting via IP.

.PARAMETER VenafiSession
VenafiSession object created from New-VenafiSession method.

Expand Down
26 changes: 24 additions & 2 deletions VenafiPS/Public/New-VenafiSession.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ function New-VenafiSession {
.PARAMETER SkipCertificateCheck
Bypass certificate validation when connecting to the server.
This can be helpful for pre-prod environments where ssl isn't setup on the website or you are connecting via IP.
You can also create an environment variable named VENAFIPS_SKIP_CERT_CHECK and set it to 1 for the same effect.

.PARAMETER TimeoutSec
Specifies how long the request can be pending before it times out. Enter a value in seconds. The default value, 0, specifies an indefinite time-out.

.PARAMETER PassThru
Optionally, send the session object to the pipeline instead of script scope.
Expand Down Expand Up @@ -260,9 +264,19 @@ function New-VenafiSession {
[string] $VaultVcKeyName,

[Parameter()]
[switch] $PassThru,
[Int32] $TimeoutSec = 0,

[Parameter()]
[switch] $PassThru,

[Parameter(ParameterSetName = 'TokenOAuth')]
[Parameter(ParameterSetName = 'TokenIntegrated')]
[Parameter(ParameterSetName = 'TokenCertificate')]
[Parameter(ParameterSetName = 'TokenJwt')]
[Parameter(ParameterSetName = 'AccessToken')]
[Parameter(ParameterSetName = 'RefreshToken')]
[Parameter(ParameterSetName = 'VaultAccessToken')]
[Parameter(ParameterSetName = 'VaultRefreshToken')]
[switch] $SkipCertificateCheck
)

Expand All @@ -286,6 +300,7 @@ function New-VenafiSession {
Server = $serverUrl
}

$newSession | Add-Member @{ 'TimeoutSec' = $TimeoutSec }
$newSession | Add-Member @{ 'SkipCertificateCheck' = $SkipCertificateCheck.IsPresent }

Write-Verbose ('Parameter set: {0}' -f $PSCmdlet.ParameterSetName)
Expand Down Expand Up @@ -380,6 +395,7 @@ function New-VenafiSession {
Scope = $secretInfo.Metadata.Scope
}
$newSession.SkipCertificateCheck = [bool] $secretInfo.Metadata.SkipCertificateCheck
$newSession.TimeoutSec = $secretInfo.Metadata.TimeoutSec
}
else {
throw 'Server and ClientId metadata not found. Execute New-VenafiSession -Server $server -Credential $cred -ClientId $clientId -Scope $scope -VaultAccessToken $secretName and attempt the operation again.'
Expand Down Expand Up @@ -429,6 +445,7 @@ function New-VenafiSession {
$newSession.Server = $newToken.Server
$newSession.Token.Scope = $secretInfo.Metadata.Scope | ConvertFrom-Json
$newSession.SkipCertificateCheck = [bool] $secretInfo.Metadata.SkipCertificateCheck
$newSession.TimeoutSec = $secretInfo.Metadata.TimeoutSec
}

'Vaas' {
Expand All @@ -439,7 +456,10 @@ function New-VenafiSession {
else { throw 'Unsupported type for -VcKey. Provide either a String, SecureString, or PSCredential.' }

if ( $VaultVcKeyName ) {
Set-Secret -Name $VaultVcKeyName -Secret $newSession.Key -Vault 'VenafiPS'
$metadata = @{
TimeoutSec = [int]$newSession.TimeoutSec
}
Set-Secret -Name $VaultVcKeyName -Secret $newSession.Key -Vault 'VenafiPS' -Metadata $metadata
}
}

Expand All @@ -458,13 +478,15 @@ function New-VenafiSession {
}

if ( $VaultAccessTokenName -or $VaultRefreshTokenName ) {
# save secret and all associated metadata to be retrieved later
$metadata = @{
Server = $newSession.Server
AuthServer = $newSession.Token.Server
ClientId = $newSession.Token.ClientId
Expires = $newSession.Expires
Scope = $newSession.Token.Scope | ConvertTo-Json -Compress
SkipCertificateCheck = [int]$newSession.SkipCertificateCheck
TimeoutSec = [int]$newSession.TimeoutSec
}

$metadata | ConvertTo-Json | Write-Verbose
Expand Down
Loading