Skip to content

Commit 01e526e

Browse files
authored
Add utils folder include a script to decrypt securestring (#682)
* Enable two test cases, and drop the workaround for x-ms-enum * Add utils folder include a script to decrypt securestring
1 parent 1c7f54c commit 01e526e

File tree

6 files changed

+30
-2
lines changed

6 files changed

+30
-2
lines changed

powershell/autorest-configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ module-folder: $(current-folder)/generated
6363
cmdlet-folder: $(module-folder)/cmdlets
6464
model-cmdlet-folder: $(module-folder)/model-cmdlets
6565
custom-cmdlet-folder: $(current-folder)/custom
66+
utils-cmdlet-folder: $(current-folder)/utils
6667
internal-cmdlet-folder: $(current-folder)/internal
6768
test-folder: $(current-folder)/test
6869
runtime-folder: $(module-folder)/runtime

powershell/generators/nuspec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export async function generateNuspec(project: Project | NewProject) {
4141
<file src="${removeCd(project.customFolder)}/**/*.*" exclude="${removeCd(project.customFolder)}/readme.md;${removeCd(project.customFolder)}/**/*.cs" />
4242
<file src="${removeCd(project.docsFolder)}/**/*.md" exclude="${removeCd(project.docsFolder)}/readme.md" />
4343
<file src="${removeCd(project.exportsFolder)}/**/ProxyCmdletDefinitions.ps1" />
44+
<file src="${removeCd(project.utilsFolder)}/**/*.*" />
4445
</files>
4546
</package>`, undefined, 'source-file-other');
4647
}

powershell/internal/project.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ export class Project extends codeDomProject {
9292
public cmdletFolder!: string;
9393

9494
public customFolder!: string;
95+
public utilsFolder!: string;
9596
public internalFolder!: string;
9697
public testFolder!: string;
9798
public runtimeFolder!: string;
@@ -193,6 +194,7 @@ export class Project extends codeDomProject {
193194
this.cmdletFolder = await this.state.getValue('cmdlet-folder');
194195

195196
this.customFolder = await this.state.getValue('custom-cmdlet-folder');
197+
this.utilsFolder = await this.state.getValue('utils-cmdlet-folder');
196198
this.internalFolder = await this.state.getValue('internal-cmdlet-folder');
197199
this.testFolder = await this.state.getValue('test-folder');
198200
this.runtimeFolder = await this.state.getValue('runtime-folder');
@@ -250,6 +252,7 @@ export class NewProject extends codeDomProject {
250252
public cmdletFolder!: string;
251253

252254
public customFolder!: string;
255+
public utilsFolder!: string;
253256
public internalFolder!: string;
254257
public testFolder!: string;
255258
public runtimeFolder!: string;
@@ -353,6 +356,7 @@ export class NewProject extends codeDomProject {
353356
this.cmdletFolder = await this.state.getValue('cmdlet-folder');
354357

355358
this.customFolder = await this.state.getValue('custom-cmdlet-folder');
359+
this.utilsFolder = await this.state.getValue('utils-cmdlet-folder');
356360
this.internalFolder = await this.state.getValue('internal-cmdlet-folder');
357361
this.testFolder = await this.state.getValue('test-folder');
358362
this.runtimeFolder = await this.state.getValue('runtime-folder');

powershell/plugins/powershell-v2.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ async function copyRequiredFiles(project: NewProject) {
3232
// Runtime files
3333
await copyResources(join(resources, 'psruntime'), async (fname, content) => project.state.writeFile(join(project.runtimeFolder, fname), content, undefined, sourceFileCSharp), project.overrides, transformOutput);
3434

35+
// utils cmdlets
36+
await copyResources(join(resources, 'utils'), async (fname, content) => project.state.writeFile(join(project.utilsFolder, fname), content, undefined, sourceFileCSharp), project.overrides, transformOutput);
37+
3538
// Modules files
3639
await copyBinaryResources(join(resources, 'modules'), async (fname, content) => project.state.writeFile(join(project.dependencyModuleFolder, fname), content, undefined, 'binary-file'));
3740

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#This script converts securestring to plaintext
2+
3+
param(
4+
[Parameter(Mandatory, ValueFromPipeline)]
5+
[System.Security.SecureString]
6+
${SecureString}
7+
)
8+
9+
$ssPtr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($SecureString)
10+
try {
11+
$plaintext = [System.Runtime.InteropServices.Marshal]::PtrToStringBSTR($ssPtr)
12+
} finally {
13+
[System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($ssPtr)
14+
}
15+
16+
return $plaintext

tests-upgrade/AutoRestUpgradeTest.ps1

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ function IsNeedIgnore([string]$inputFileName , [Array]$ignoreArray)
6666
{
6767
$Ignore =$True
6868
break
69+
} elseif ($ignoreDetail.Contains("*.") -and $inputFileName.EndsWith($ignoreDetail.Split(".")[-1])) {
70+
$Ignore =$True
71+
break
6972
}
7073
}
7174
return $Ignore
@@ -117,8 +120,8 @@ function CompareGeneratedCode([string]$inputSourcePath,[string]$inputTargetPath,
117120
#in m3Path
118121
cd $inputSourcePath
119122
$initFileList = Get-ChildItem -Recurse -force
120-
$initIgnoreFileList = (($inputSourcePath+'\generated\modules'), ($inputSourcePath+'\.gitignore'),($inputSourcePath+'\tools\Resources\.gitignore'))
121-
$targetIgnoreFileList = (($inputTargetPath+'\generated\modules'), ($inputTargetPath+'\.gitignore'),($inputTargetPath+'\tools\Resources\.gitignore'))
123+
$initIgnoreFileList = (($inputSourcePath+'\generated\modules'), ($inputSourcePath+'\utils'), ($inputSourcePath+'\*.nuspec'), ($inputSourcePath+'\.gitignore'),($inputSourcePath+'\tools\Resources\.gitignore'))
124+
$targetIgnoreFileList = (($inputTargetPath+'\generated\modules'), ($inputTargetPath+'\utils'),($inputTargetPath+'\*.nuspec'),($inputTargetPath+'\.gitignore'),($inputTargetPath+'\tools\Resources\.gitignore'))
122125
#foreach initFileList and get the hashcode of them
123126
foreach( $initFile in $initFileList)
124127
{

0 commit comments

Comments
 (0)