Skip to content

Commit 939a136

Browse files
Merge remote-tracking branch 'origin/peer-v4.3.1' into peer-v7.8.0
Conflicts: modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellExperimentalClientCodegen.java modules/openapi-generator/src/main/resources/powershell-experimental/api.mustache modules/openapi-generator/src/main/resources/powershell/utils.mustache
2 parents 6bdc452 + 7f8b80d commit 939a136

6 files changed

Lines changed: 120 additions & 3 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PowerShellClientCodegen.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ public void processOpts() {
770770
supportingFiles.add(new SupportingFile("Out-DebugParameter.mustache", infrastructureFolder + File.separator + "Private" + File.separator, "Out-DebugParameter.ps1"));
771771
supportingFiles.add(new SupportingFile("http_signature_auth.mustache", infrastructureFolder + "Private", apiNamePrefix + "HttpSignatureAuth.ps1"));
772772
supportingFiles.add(new SupportingFile("rsa_provider.mustache", infrastructureFolder + "Private", apiNamePrefix + "RSAEncryptionProvider.cs"));
773+
supportingFiles.add(new SupportingFile("utils.mustache", infrastructureFolder + "Private" + File.separator, "utils.ps1"));
773774

774775

775776
// en-US

modules/openapi-generator/src/main/resources/powershell/api.mustache

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ function {{{vendorExtensions.x-powershell-method-name}}} {
223223
{{/isApiKey}}
224224
{{#isBasicBasic}}
225225
if ($Configuration["Username"] -and $Configuration["Password"]) {
226-
$LocalVarBytes = [System.Text.Encoding]::UTF8.GetBytes($Configuration["Username"] + ":" + $Configuration["Password"])
226+
$Password = Get-PlainTextPassword -Password $Configuration["Password"]
227+
$LocalVarBytes = [System.Text.Encoding]::UTF8.GetBytes($Configuration["Username"] + ":" + $Password)
227228
$LocalVarBase64Text =[Convert]::ToBase64String($LocalVarBytes)
228229
$LocalVarHeaderParameters['Authorization'] = "Basic " + $LocalVarBase64Text
229230
Write-Verbose ("Using HTTP basic authentication in {0}" -f $MyInvocation.MyCommand)

modules/openapi-generator/src/main/resources/powershell/configuration.mustache

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ Username in HTTP basic authentication
7575
.PARAMETER Password
7676
Password in HTTP basic authentication
7777

78+
.PARAMETER SecurePassword
79+
Password in HTTP basic authentication, in secure string format
80+
7881
.PARAMETER ApiKey
7982
API Keys for authentication/authorization
8083

@@ -115,6 +118,7 @@ function Set-{{{apiNamePrefix}}}Configuration {
115118
[string]$Username,
116119
[AllowEmptyString()]
117120
[string]$Password,
121+
[securestring]$SecurePassword,
118122
[hashtable]$ApiKey,
119123
[hashtable]$ApiKeyPrefix,
120124
[AllowEmptyString()]
@@ -143,7 +147,11 @@ function Set-{{{apiNamePrefix}}}Configuration {
143147
}
144148

145149
If ($Password) {
146-
$Script:Configuration['Password'] = $Password
150+
$Script:Configuration['Password'] = ConvertTo-SecureString -String $Password -AsPlainText -Force
151+
}
152+
153+
If ($SecurePassword) {
154+
$Script:Configuration['Password'] = $SecurePassword
147155
}
148156

149157
If ($ApiKey) {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{{> partial_header}}
2+
<#
3+
.SYNOPSIS
4+
A wrapper function that extracts the password from a SecureString as plain text.
5+
6+
.DESCRIPTION
7+
A wrapper function that extracts the password from a SecureString as plain text.
8+
For PowerShell Core the function calls the ConvertFrom-SecureString cmdlet directly.
9+
For PowerShell 5.1 the System.Runtime.InteropServices.Marshal type is used to extract
10+
the password from the SecureString as plain text.
11+
12+
.PARAMETER Password
13+
Specifies the SecureString Password from which the plain text password should be extracted.
14+
#>
15+
function Get-PlainTextPassword {
16+
[CmdletBinding()]
17+
[OutputType([string])]
18+
param (
19+
[Parameter(Mandatory = $true)]
20+
[SecureString]
21+
$Password
22+
)
23+
24+
$plainTextPassword = $null
25+
26+
if ($Global:PSVersionTable.PSEdition -eq 'Core') {
27+
$plainTextPassword = ConvertFrom-SecureString -SecureString $Password -AsPlainText
28+
} else {
29+
$passwordAsBinaryString = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($Password)
30+
$plainTextPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($passwordAsBinaryString)
31+
}
32+
33+
$plainTextPassword
34+
}

peer_update_version.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/usr/bin/env python3
2+
3+
"""Set the version based on the current git branch/SHA."""
4+
5+
import os
6+
import re
7+
import subprocess
8+
9+
10+
def run_cmmd_capture_stdout(command):
11+
"""Run a command and capture its stdout."""
12+
process = subprocess.run(command, check=False, capture_output=True, text=True)
13+
return process.stdout.rstrip('\n')
14+
15+
16+
def get_branch():
17+
"""Get the git branch."""
18+
return run_cmmd_capture_stdout(['git', 'rev-parse', '--abbrev-ref', '@'])
19+
20+
21+
def get_sha():
22+
"""Get the git SHA."""
23+
return run_cmmd_capture_stdout(['git', 'rev-parse', '--short=10', '@'])
24+
25+
26+
def update_version(file_path, branch, sha):
27+
"""Update version information in a pom.xml file."""
28+
encoding = 'utf-8'
29+
30+
with open(file_path, 'r', encoding=encoding) as file:
31+
filedata = file.read()
32+
33+
filedata = re.sub(
34+
# Find the version between RELEASE_VERSION tags and append the branch and SHA to it
35+
r'(?P<start><!-- RELEASE_VERSION -->\s*\n' +
36+
r'\s*<version>)' +
37+
r'(?P<version>[\d.]*)(?P<version_suffix>(-SNAPSHOT)?).*(?P<end>'
38+
r'</version>\s*\n' +
39+
r'\s*<!-- /RELEASE_VERSION -->)',
40+
r'\g<start>\g<version>\g<version_suffix>-' + branch + r'-' + sha + r'\g<end>', filedata)
41+
42+
with open(file_path, 'w', encoding=encoding) as file:
43+
file.write(filedata)
44+
45+
46+
def update_poms():
47+
"""Set the version in necessary pom.xml files to tag the openapi generator build."""
48+
branch = get_branch()
49+
sha = get_sha()
50+
files = [
51+
os.path.join('modules', 'openapi-generator-cli', 'pom.xml'),
52+
os.path.join('modules', 'openapi-generator-core', 'pom.xml'),
53+
os.path.join('modules', 'openapi-generator-gradle-plugin', 'pom.xml'),
54+
os.path.join('modules', 'openapi-generator-maven-plugin', 'pom.xml'),
55+
os.path.join('modules', 'openapi-generator-online', 'pom.xml'),
56+
os.path.join('modules', 'openapi-generator', 'pom.xml'),
57+
'pom.xml'
58+
]
59+
60+
for file in files:
61+
update_version(file, branch, sha)
62+
63+
64+
if __name__ == '__main__':
65+
update_poms()

samples/client/petstore/powershell/src/PSPetstore/Client/PSConfiguration.ps1

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ Username in HTTP basic authentication
8181
.PARAMETER Password
8282
Password in HTTP basic authentication
8383
84+
.PARAMETER SecurePassword
85+
Password in HTTP basic authentication, in secure string format
86+
8487
.PARAMETER ApiKey
8588
API Keys for authentication/authorization
8689
@@ -121,6 +124,7 @@ function Set-PSConfiguration {
121124
[string]$Username,
122125
[AllowEmptyString()]
123126
[string]$Password,
127+
[securestring]$SecurePassword,
124128
[hashtable]$ApiKey,
125129
[hashtable]$ApiKeyPrefix,
126130
[AllowEmptyString()]
@@ -149,7 +153,11 @@ function Set-PSConfiguration {
149153
}
150154

151155
If ($Password) {
152-
$Script:Configuration['Password'] = $Password
156+
$Script:Configuration['Password'] = ConvertTo-SecureString -String $Password -AsPlainText -Force
157+
}
158+
159+
If ($SecurePassword) {
160+
$Script:Configuration['Password'] = $SecurePassword
153161
}
154162

155163
If ($ApiKey) {

0 commit comments

Comments
 (0)