forked from loafle/openapi-generator-original
[PS] Allow CI to publish the module (#7091)
* better code format in powershell code * add code to publish ps module
This commit is contained in:
@@ -23,5 +23,5 @@ LONG DESCRIPTION
|
||||
|
||||
Frameworks supported:
|
||||
|
||||
* PowerShell 3.0+
|
||||
* PowerShell {{{powershellVersion}}} or later
|
||||
* .NET 4.0 or later
|
||||
|
||||
@@ -15,3 +15,10 @@ test_script:
|
||||
$host.SetShouldExit($Result.FailedCount)
|
||||
exit $Result.FailedCount
|
||||
}
|
||||
- ps: |
|
||||
if ($env:APPVEYOR_REPO_TAG -eq $true -and $env:NuGetApiKey -ne $null)
|
||||
{
|
||||
choco install NuGet.CommandLine
|
||||
Install-PackageProvider -Name NuGet -Force
|
||||
Publish-Module -NuGetApiKey $env:NuGetApiKey -Path .\ -Confirm:$False -Verbose
|
||||
}
|
||||
|
||||
@@ -49,8 +49,7 @@ function Get-{{{apiNamePrefix}}}HttpSignedHeader {
|
||||
$bodyHash = Get-{{{apiNamePrefix}}}StringHash -String $Body -HashName $httpSigningConfiguration.HashAlgorithm
|
||||
if ($httpSigningConfiguration.HashAlgorithm -eq "SHA256") {
|
||||
$Digest = [String]::Format("SHA-256={0}", [Convert]::ToBase64String($bodyHash))
|
||||
}
|
||||
elseif ($httpSigningConfiguration.HashAlgorithm -eq "SHA512") {
|
||||
} elseif ($httpSigningConfiguration.HashAlgorithm -eq "SHA512") {
|
||||
$Digest = [String]::Format("SHA-512={0}", [Convert]::ToBase64String($bodyHash))
|
||||
}
|
||||
|
||||
@@ -63,25 +62,20 @@ function Get-{{{apiNamePrefix}}}HttpSignedHeader {
|
||||
if ($headerItem -eq $HEADER_REQUEST_TARGET) {
|
||||
$requestTargetPath = [string]::Format("{0} {1}{2}", $Method.ToLower(), $UriBuilder.Path, $UriBuilder.Query)
|
||||
$HttpSignatureHeader.Add($HEADER_REQUEST_TARGET, $requestTargetPath)
|
||||
}
|
||||
elseif ($headerItem -eq $HEADER_CREATED) {
|
||||
} elseif ($headerItem -eq $HEADER_CREATED) {
|
||||
$created = Get-{{{apiNamePrefix}}}UnixTime -Date $dateTime -TotalTime TotalSeconds
|
||||
$HttpSignatureHeader.Add($HEADER_CREATED, $created)
|
||||
}
|
||||
elseif ($headerItem -eq $HEADER_EXPIRES) {
|
||||
} elseif ($headerItem -eq $HEADER_EXPIRES) {
|
||||
$expire = $dateTime.AddSeconds($httpSigningConfiguration.SignatureValidityPeriod)
|
||||
$expireEpocTime = Get-{{{apiNamePrefix}}}UnixTime -Date $expire -TotalTime TotalSeconds
|
||||
$HttpSignatureHeader.Add($HEADER_EXPIRES, $expireEpocTime)
|
||||
}
|
||||
elseif ($headerItem -eq $HEADER_HOST) {
|
||||
} elseif ($headerItem -eq $HEADER_HOST) {
|
||||
$HttpSignedRequestHeader[$HEADER_HOST] = $TargetHost
|
||||
$HttpSignatureHeader.Add($HEADER_HOST.ToLower(), $TargetHost)
|
||||
}
|
||||
elseif ($headerItem -eq $HEADER_DATE) {
|
||||
} elseif ($headerItem -eq $HEADER_DATE) {
|
||||
$HttpSignedRequestHeader[$HEADER_DATE] = $currentDate
|
||||
$HttpSignatureHeader.Add($HEADER_DATE.ToLower(), $currentDate)
|
||||
}
|
||||
elseif ($headerItem -eq $HEADER_DIGEST) {
|
||||
} elseif ($headerItem -eq $HEADER_DIGEST) {
|
||||
$HttpSignedRequestHeader[$HEADER_DIGEST] = $Digest
|
||||
$HttpSignatureHeader.Add($HEADER_DIGEST.ToLower(), $Digest)
|
||||
} elseif($RequestHeader.ContainsKey($headerItem)) {
|
||||
@@ -112,8 +106,7 @@ function Get-{{{apiNamePrefix}}}HttpSignedHeader {
|
||||
-HashAlgorithmName $httpSigningConfiguration.HashAlgorithm `
|
||||
-KeyPassPhrase $httpSigningConfiguration.KeyPassPhrase `
|
||||
-SigningAlgorithm $httpSigningConfiguration.SigningAlgorithm
|
||||
}
|
||||
elseif ($KeyType -eq "EC") {
|
||||
} elseif ($KeyType -eq "EC") {
|
||||
$headerSignatureStr = Get-{{{apiNamePrefix}}}ECDSASignature -ECKeyFilePath $httpSigningConfiguration.KeyFilePath `
|
||||
-DataToSign $signatureHashString `
|
||||
-HashAlgorithmName $httpSigningConfiguration.HashAlgorithm `
|
||||
@@ -171,8 +164,7 @@ function Get-{{{apiNamePrefix}}}RSASignature {
|
||||
|
||||
if ($hashAlgorithmName -eq "sha256") {
|
||||
$hashAlgo = [System.Security.Cryptography.HashAlgorithmName]::SHA256
|
||||
}
|
||||
elseif ($hashAlgorithmName -eq "sha512") {
|
||||
} elseif ($hashAlgorithmName -eq "sha512") {
|
||||
$hashAlgo = [System.Security.Cryptography.HashAlgorithmName]::SHA512
|
||||
}
|
||||
|
||||
@@ -188,12 +180,10 @@ function Get-{{{apiNamePrefix}}}RSASignature {
|
||||
|
||||
if ($SigningAlgorithm -eq "RSASSA-PSS") {
|
||||
$signedBytes = $rsa.SignHash($DataToSign, $hashAlgo, [System.Security.Cryptography.RSASignaturePadding]::Pss)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$signedBytes = $rsa.SignHash($DataToSign, $hashAlgo, [System.Security.Cryptography.RSASignaturePadding]::Pkcs1)
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$rsa_provider_path = Join-Path -Path $PSScriptRoot -ChildPath "{{{apiNamePrefix}}}RSAEncryptionProvider.cs"
|
||||
$rsa_provider_sourceCode = Get-Content -Path $rsa_provider_path -Raw
|
||||
Add-Type -TypeDefinition $rsa_provider_sourceCode
|
||||
@@ -202,17 +192,14 @@ function Get-{{{apiNamePrefix}}}RSASignature {
|
||||
|
||||
if ($SigningAlgorithm -eq "RSASSA-PSS") {
|
||||
throw "$SigningAlgorithm is not supported on $($PSVersionTable.PSVersion)"
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$signedBytes = $rsa.SignHash($DataToSign, $hashAlgo, [System.Security.Cryptography.RSASignaturePadding]::Pkcs1)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$signedString = [Convert]::ToBase64String($signedBytes)
|
||||
return $signedString
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
throw $_
|
||||
}
|
||||
}
|
||||
@@ -265,25 +252,21 @@ function Get-{{{apiNamePrefix}}}ECDSASignature {
|
||||
[int]$bytCount =0
|
||||
if (![string]::IsNullOrEmpty($KeyPassPhrase)) {
|
||||
$ecdsa.ImportEncryptedPkcs8PrivateKey($KeyPassPhrase,$keyBytes,[ref]$bytCount)
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$ecdsa.ImportPkcs8PrivateKey($keyBytes,[ref]$bytCount)
|
||||
}
|
||||
|
||||
if ($HashAlgorithmName -eq "sha512") {
|
||||
$ecdsa.HashAlgorithm = [System.Security.Cryptography.CngAlgorithm]::Sha512
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$ecdsa.HashAlgorithm = [System.Security.Cryptography.CngAlgorithm]::Sha256
|
||||
}
|
||||
|
||||
$signedBytes = $ecdsa.SignHash($DataToSign)
|
||||
$signedString = [System.Convert]::ToBase64String($signedBytes)
|
||||
return $signedString
|
||||
|
||||
}
|
||||
|
||||
|
||||
<#
|
||||
.Synopsis
|
||||
Gets the hash of string.
|
||||
@@ -359,7 +342,6 @@ function Get-{{{apiNamePrefix}}}CryptographicScheme {
|
||||
return $SigningAlgorithm
|
||||
}
|
||||
|
||||
|
||||
<#
|
||||
.Synopsis
|
||||
Gets the key type from the pem file.
|
||||
@@ -390,19 +372,15 @@ function Get-{{{apiNamePrefix}}}KeyTypeFromFile {
|
||||
|
||||
if ($key[0] -match $rsaPrivateKeyHeader -and $key[$key.Length - 1] -match $rsaPrivateFooter) {
|
||||
$KeyType = "RSA"
|
||||
|
||||
}
|
||||
elseif ($key[0] -match $ecPrivateKeyHeader -and $key[$key.Length - 1] -match $ecPrivateKeyFooter) {
|
||||
} elseif ($key[0] -match $ecPrivateKeyHeader -and $key[$key.Length - 1] -match $ecPrivateKeyFooter) {
|
||||
$keyType = "EC"
|
||||
}
|
||||
elseif ($key[0] -match $ecPrivateKeyHeader -and $key[$key.Length - 1] -match $ecPrivateKeyFooter) {
|
||||
} elseif ($key[0] -match $ecPrivateKeyHeader -and $key[$key.Length - 1] -match $ecPrivateKeyFooter) {
|
||||
<#this type of key can hold many type different types of private key, but here due lack of pem header
|
||||
Considering this as EC key
|
||||
#>
|
||||
#TODO :- update the key based on oid
|
||||
$keyType = "EC"
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw "Either the key is invalid or key is not supported"
|
||||
}
|
||||
return $keyType
|
||||
|
||||
@@ -21,3 +21,10 @@ test_script:
|
||||
$host.SetShouldExit($Result.FailedCount)
|
||||
exit $Result.FailedCount
|
||||
}
|
||||
- ps: |
|
||||
if ($env:APPVEYOR_REPO_TAG -eq $true -and $env:NuGetApiKey -ne $null)
|
||||
{
|
||||
choco install NuGet.CommandLine
|
||||
Install-PackageProvider -Name NuGet -Force
|
||||
Publish-Module -NuGetApiKey $env:NuGetApiKey -Path .\ -Confirm:$False -Verbose
|
||||
}
|
||||
|
||||
@@ -55,8 +55,7 @@ function Get-PSHttpSignedHeader {
|
||||
$bodyHash = Get-PSStringHash -String $Body -HashName $httpSigningConfiguration.HashAlgorithm
|
||||
if ($httpSigningConfiguration.HashAlgorithm -eq "SHA256") {
|
||||
$Digest = [String]::Format("SHA-256={0}", [Convert]::ToBase64String($bodyHash))
|
||||
}
|
||||
elseif ($httpSigningConfiguration.HashAlgorithm -eq "SHA512") {
|
||||
} elseif ($httpSigningConfiguration.HashAlgorithm -eq "SHA512") {
|
||||
$Digest = [String]::Format("SHA-512={0}", [Convert]::ToBase64String($bodyHash))
|
||||
}
|
||||
|
||||
@@ -69,25 +68,20 @@ function Get-PSHttpSignedHeader {
|
||||
if ($headerItem -eq $HEADER_REQUEST_TARGET) {
|
||||
$requestTargetPath = [string]::Format("{0} {1}{2}", $Method.ToLower(), $UriBuilder.Path, $UriBuilder.Query)
|
||||
$HttpSignatureHeader.Add($HEADER_REQUEST_TARGET, $requestTargetPath)
|
||||
}
|
||||
elseif ($headerItem -eq $HEADER_CREATED) {
|
||||
} elseif ($headerItem -eq $HEADER_CREATED) {
|
||||
$created = Get-PSUnixTime -Date $dateTime -TotalTime TotalSeconds
|
||||
$HttpSignatureHeader.Add($HEADER_CREATED, $created)
|
||||
}
|
||||
elseif ($headerItem -eq $HEADER_EXPIRES) {
|
||||
} elseif ($headerItem -eq $HEADER_EXPIRES) {
|
||||
$expire = $dateTime.AddSeconds($httpSigningConfiguration.SignatureValidityPeriod)
|
||||
$expireEpocTime = Get-PSUnixTime -Date $expire -TotalTime TotalSeconds
|
||||
$HttpSignatureHeader.Add($HEADER_EXPIRES, $expireEpocTime)
|
||||
}
|
||||
elseif ($headerItem -eq $HEADER_HOST) {
|
||||
} elseif ($headerItem -eq $HEADER_HOST) {
|
||||
$HttpSignedRequestHeader[$HEADER_HOST] = $TargetHost
|
||||
$HttpSignatureHeader.Add($HEADER_HOST.ToLower(), $TargetHost)
|
||||
}
|
||||
elseif ($headerItem -eq $HEADER_DATE) {
|
||||
} elseif ($headerItem -eq $HEADER_DATE) {
|
||||
$HttpSignedRequestHeader[$HEADER_DATE] = $currentDate
|
||||
$HttpSignatureHeader.Add($HEADER_DATE.ToLower(), $currentDate)
|
||||
}
|
||||
elseif ($headerItem -eq $HEADER_DIGEST) {
|
||||
} elseif ($headerItem -eq $HEADER_DIGEST) {
|
||||
$HttpSignedRequestHeader[$HEADER_DIGEST] = $Digest
|
||||
$HttpSignatureHeader.Add($HEADER_DIGEST.ToLower(), $Digest)
|
||||
} elseif($RequestHeader.ContainsKey($headerItem)) {
|
||||
@@ -118,8 +112,7 @@ function Get-PSHttpSignedHeader {
|
||||
-HashAlgorithmName $httpSigningConfiguration.HashAlgorithm `
|
||||
-KeyPassPhrase $httpSigningConfiguration.KeyPassPhrase `
|
||||
-SigningAlgorithm $httpSigningConfiguration.SigningAlgorithm
|
||||
}
|
||||
elseif ($KeyType -eq "EC") {
|
||||
} elseif ($KeyType -eq "EC") {
|
||||
$headerSignatureStr = Get-PSECDSASignature -ECKeyFilePath $httpSigningConfiguration.KeyFilePath `
|
||||
-DataToSign $signatureHashString `
|
||||
-HashAlgorithmName $httpSigningConfiguration.HashAlgorithm `
|
||||
@@ -177,8 +170,7 @@ function Get-PSRSASignature {
|
||||
|
||||
if ($hashAlgorithmName -eq "sha256") {
|
||||
$hashAlgo = [System.Security.Cryptography.HashAlgorithmName]::SHA256
|
||||
}
|
||||
elseif ($hashAlgorithmName -eq "sha512") {
|
||||
} elseif ($hashAlgorithmName -eq "sha512") {
|
||||
$hashAlgo = [System.Security.Cryptography.HashAlgorithmName]::SHA512
|
||||
}
|
||||
|
||||
@@ -194,12 +186,10 @@ function Get-PSRSASignature {
|
||||
|
||||
if ($SigningAlgorithm -eq "RSASSA-PSS") {
|
||||
$signedBytes = $rsa.SignHash($DataToSign, $hashAlgo, [System.Security.Cryptography.RSASignaturePadding]::Pss)
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$signedBytes = $rsa.SignHash($DataToSign, $hashAlgo, [System.Security.Cryptography.RSASignaturePadding]::Pkcs1)
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$rsa_provider_path = Join-Path -Path $PSScriptRoot -ChildPath "PSRSAEncryptionProvider.cs"
|
||||
$rsa_provider_sourceCode = Get-Content -Path $rsa_provider_path -Raw
|
||||
Add-Type -TypeDefinition $rsa_provider_sourceCode
|
||||
@@ -208,17 +198,14 @@ function Get-PSRSASignature {
|
||||
|
||||
if ($SigningAlgorithm -eq "RSASSA-PSS") {
|
||||
throw "$SigningAlgorithm is not supported on $($PSVersionTable.PSVersion)"
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$signedBytes = $rsa.SignHash($DataToSign, $hashAlgo, [System.Security.Cryptography.RSASignaturePadding]::Pkcs1)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$signedString = [Convert]::ToBase64String($signedBytes)
|
||||
return $signedString
|
||||
}
|
||||
catch {
|
||||
} catch {
|
||||
throw $_
|
||||
}
|
||||
}
|
||||
@@ -271,25 +258,21 @@ function Get-PSECDSASignature {
|
||||
[int]$bytCount =0
|
||||
if (![string]::IsNullOrEmpty($KeyPassPhrase)) {
|
||||
$ecdsa.ImportEncryptedPkcs8PrivateKey($KeyPassPhrase,$keyBytes,[ref]$bytCount)
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
$ecdsa.ImportPkcs8PrivateKey($keyBytes,[ref]$bytCount)
|
||||
}
|
||||
|
||||
if ($HashAlgorithmName -eq "sha512") {
|
||||
$ecdsa.HashAlgorithm = [System.Security.Cryptography.CngAlgorithm]::Sha512
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
$ecdsa.HashAlgorithm = [System.Security.Cryptography.CngAlgorithm]::Sha256
|
||||
}
|
||||
|
||||
$signedBytes = $ecdsa.SignHash($DataToSign)
|
||||
$signedString = [System.Convert]::ToBase64String($signedBytes)
|
||||
return $signedString
|
||||
|
||||
}
|
||||
|
||||
|
||||
<#
|
||||
.Synopsis
|
||||
Gets the hash of string.
|
||||
@@ -365,7 +348,6 @@ function Get-PSCryptographicScheme {
|
||||
return $SigningAlgorithm
|
||||
}
|
||||
|
||||
|
||||
<#
|
||||
.Synopsis
|
||||
Gets the key type from the pem file.
|
||||
@@ -396,19 +378,15 @@ function Get-PSKeyTypeFromFile {
|
||||
|
||||
if ($key[0] -match $rsaPrivateKeyHeader -and $key[$key.Length - 1] -match $rsaPrivateFooter) {
|
||||
$KeyType = "RSA"
|
||||
|
||||
}
|
||||
elseif ($key[0] -match $ecPrivateKeyHeader -and $key[$key.Length - 1] -match $ecPrivateKeyFooter) {
|
||||
} elseif ($key[0] -match $ecPrivateKeyHeader -and $key[$key.Length - 1] -match $ecPrivateKeyFooter) {
|
||||
$keyType = "EC"
|
||||
}
|
||||
elseif ($key[0] -match $ecPrivateKeyHeader -and $key[$key.Length - 1] -match $ecPrivateKeyFooter) {
|
||||
} elseif ($key[0] -match $ecPrivateKeyHeader -and $key[$key.Length - 1] -match $ecPrivateKeyFooter) {
|
||||
<#this type of key can hold many type different types of private key, but here due lack of pem header
|
||||
Considering this as EC key
|
||||
#>
|
||||
#TODO :- update the key based on oid
|
||||
$keyType = "EC"
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw "Either the key is invalid or key is not supported"
|
||||
}
|
||||
return $keyType
|
||||
|
||||
@@ -15,5 +15,5 @@ LONG DESCRIPTION
|
||||
|
||||
Frameworks supported:
|
||||
|
||||
* PowerShell 3.0+
|
||||
* PowerShell 5.0 or later
|
||||
* .NET 4.0 or later
|
||||
|
||||
Reference in New Issue
Block a user