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

[powershell-experimental] Adds configuration option to skip certificate check #5657

Merged
merged 1 commit into from
Mar 23, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@ function Invoke-{{{apiNamePrefix}}}ApiClient {

$Configuration = Get-{{{apiNamePrefix}}}Configuration
$RequestUri = $Configuration["BaseUrl"] + $Uri
$SkipCertificateCheck = $Configuration["SkipCertificateCheck"]

# cookie parameters
foreach ($Parameter in $CookieParameters) {
if ($CookieParameters[$Parameter]) {
$HeaderParameters["Cookie"] = $CookieParameters[$Parameter]
foreach ($Parameter in $CookieParameters.GetEnumerator()) {
if ($Parameter.Name -eq "cookieAuth") {
$HeaderParameters["Cookie"] = $Parameter.Value
} else {
$HeaderParameters[$Parameter.Name] = $Parameter.Value
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll further revise this code block later with some tests.

}
}
if ($CookieParametters -and $CookieParameters.Count -gt 1) {
if ($CookieParameters -and $CookieParameters.Count -gt 1) {
Write-Warning "Multipe cookie parameters found. Curently only the first one is supported/used"
}

Expand Down Expand Up @@ -80,11 +83,21 @@ function Invoke-{{{apiNamePrefix}}}ApiClient {
$RequestBody = $Body
}

$Response = Invoke-WebRequest -Uri $UriBuilder.Uri `
if ($SkipCertificateCheck -eq $true) {
$Response = Invoke-WebRequest -Uri $UriBuilder.Uri `
-Method $Method `
-Headers $HeaderParameters `
-Body $RequestBody `
-ErrorAction Stop `
-SkipCertificateCheck

} else {
$Response = Invoke-WebRequest -Uri $UriBuilder.Uri `
-Method $Method `
-Headers $HeaderParameters `
-Body $RequestBody `
-ErrorAction Stop
}

return @{
Response = DeserializeResponse -Response $Response -ReturnType $ReturnType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ function Get-{{apiNamePrefix}}Configuration {
$Configuration["ApiKeyPrefix"] = @{}
}

if (!$Configuration.containsKey("SkipCertificateCheck")) {
$Configuration["SkipCertificateCheck"] = $false
}

Return $Configuration

}
Expand All @@ -48,6 +52,7 @@ function Set-{{{apiNamePrefix}}}Configuration {
[AllowEmptyString()]
[string]$AccessToken,
[switch]$PassThru,
[bool]$SkipCertificateCheck,
[switch]$Force
)

Expand Down Expand Up @@ -80,6 +85,10 @@ function Set-{{{apiNamePrefix}}}Configuration {
If ($AccessToken) {
$Script:Configuration['AccessToken'] = $AccessToken
}

If ($SkipCertificateCheck) {
$Script:Configuration['SkipCertificateCheck'] = $SkipCertificateCheck
}
}
}

Expand Down