-
Notifications
You must be signed in to change notification settings - Fork 1
Users/grhuang/azsupport autorest feature #1
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
Changes from all commits
1b15859
c2e620c
e2cc76e
07ace3d
69b3443
f414931
a7546e4
1f7f741
a22e254
5dea32a
a5b213d
b953811
276498c
487bef6
ef75f6b
ec6d597
9715b15
b1b98b7
d19fb89
1d8bed2
41e373b
f41fe6c
1313bdc
5332d08
683579a
f4e7b8e
60b7341
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,13 +35,10 @@ commit: 99b27b136352e2f16c3f868857fa33157ace895f | |
| require: | ||
| # readme.azure.noprofile.md is the common configuration file | ||
| - $(this-folder)/../../readme.azure.noprofile.md | ||
| # - $(repo)/specification/support/resource-manager/readme.md | ||
| # If the swagger has not been put in the repo, you may uncomment the following line and refer to it locally | ||
| # - (this-folder)/relative-path-to-your-local-readme.md | ||
| input-file: | ||
| - $(repo)/specification/support/resource-manager/Microsoft.Support/preview/2022-09-01-preview/support.json | ||
| # try-require: | ||
| # - $(repo)/specification/support/resource-manager/readme.powershell.md | ||
|
|
||
| # For new RP, the version is 0.1.0 | ||
| module-version: 0.1.0 | ||
|
|
@@ -60,39 +57,83 @@ directive: | |
| set: | ||
| format-table: | ||
| properties: | ||
| # - Id | ||
| - DisplayName | ||
| - Name | ||
| - SecondaryConsentEnabled # Do we need this? | ||
| # - Type | ||
| - SecondaryConsentEnabled | ||
| - where: | ||
| model-name: Service | ||
| set: | ||
| format-table: | ||
| properties: | ||
| # - Id | ||
| - DisplayName | ||
| - Name | ||
| - ResourceType # Do we need this? | ||
| # - Type | ||
| - ResourceType | ||
| - where: | ||
| model-name: FileDetails | ||
| set: | ||
| format-table: | ||
| properties: | ||
| # - Id | ||
| - Name | ||
| - CreatedOn | ||
| - ChunkSize | ||
| - FileSize | ||
| - NumberOfChunks | ||
| # - Type | ||
| - where: | ||
| subject: UploadFile | ||
| parameter-name: FileWorkspaceName | ||
| set: | ||
| alias: WorkspaceName | ||
| - where: | ||
| subject: UploadFilesNoSubscription | ||
| parameter-name: FileWorkspaceName | ||
| set: | ||
| alias: WorkspaceName | ||
| - where: | ||
| subject: FileWorkspacesNoSubscription | ||
| parameter-name: FileWorkspaceName | ||
| set: | ||
| alias: Name | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is there another alias 'Name' instead of 'WorkspaceName' here?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Autorest automatically renames parameters when they correlate to the subject of the cmdlet (e.g. aliases FileWorkspaceName for AzSupportFileWorkspace cmdlets to Name and FileWorkspaceName for AzSupportFile cmdlets to WorkspaceName). However, it doesn't recognize the NoSubscription versions of the cmdlets as the same subject. Without that part of the readme, AzSupportFileWorkspacesNoSubscription doesn't recognize Name as an alias for FileWorkspaceName. However, now I'm wondering if we should try to keep the parameter names consistent between all cmdlets (e.g. keep FileWorkspaceName as the parameter name for all cmdlets). Let's check with Anagh |
||
| - where: | ||
| subject: FilesNoSubscription | ||
| parameter-name: FileName | ||
| set: | ||
| alias: Name | ||
| - where: | ||
| subject: FilesNoSubscription | ||
| parameter-name: FileWorkspaceName | ||
| set: | ||
| alias: WorkspaceName | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similar comment. When is the alias Name or WorkspaceName supposed to be called?
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see above |
||
| - where: | ||
| verb: New | ||
| subject: File | ||
| hide: true | ||
| - where: | ||
| verb: New | ||
| subject: FilesNoSubscription | ||
| hide: true | ||
| - where: | ||
| verb: Update | ||
| subject: File | ||
| remove: true | ||
| - where: | ||
| verb: Update | ||
| subject: FilesNoSubscription | ||
| remove: true | ||
| - where: | ||
| verb: Invoke | ||
| subject: UploadFile | ||
| hide: true | ||
| - where: | ||
| verb: Invoke | ||
| subject: UploadFilesNoSubscription | ||
| hide: true | ||
| # Following are common directives which are normally required in all the RPs | ||
| # 1. Remove the unexpanded parameter set | ||
| # 2. For New-* cmdlets, ViaIdentity is not required | ||
| # Following two directives are v4 specific | ||
| - where: | ||
| variant: ^(Create|Update)(?!.*?Expanded) | ||
| variant: ^(Create|Update)(?!.*?Expanded|JsonFilePath|JsonString) | ||
| subject: ^(?!FileWorkspace|FileWorkspacesNoSubscription$).* | ||
| remove: true | ||
| - where: | ||
| variant: ^CreateViaIdentity.*$ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
|
|
||
| # ---------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # Code generated by Microsoft (R) AutoRest Code Generator.Changes may cause incorrect behavior and will be lost if the code | ||
| # is regenerated. | ||
| # ---------------------------------------------------------------------------------- | ||
|
|
||
| <# | ||
| .Synopsis | ||
| Creates and uploads a new file under a workspace for the specified subscription. | ||
| .Description | ||
| Creates and uploads a new file under a workspace for the specified subscription. | ||
| .Example | ||
| {{ Add code here }} | ||
| .Example | ||
| {{ Add code here }} | ||
|
|
||
| .Outputs | ||
| Microsoft.Azure.PowerShell.Cmdlets.Support.Models.IFileDetails | ||
| .Link | ||
| https://learn.microsoft.com/powershell/module/az.support/new-azsupportfile | ||
| #> | ||
| function New-AzSupportFileAndUpload { | ||
| [OutputType([Microsoft.Azure.PowerShell.Cmdlets.Support.Models.IFileDetails])] | ||
| [CmdletBinding(DefaultParameterSetName='CreateExpanded', PositionalBinding=$false, SupportsShouldProcess, ConfirmImpact='Medium')] | ||
| param( | ||
| [Parameter(Mandatory)] | ||
| [Alias('FileWorkspaceName')] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Path')] | ||
| [System.String] | ||
| # File workspace name. | ||
| ${WorkspaceName}, | ||
|
|
||
| [Parameter()] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Path')] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.Support.Runtime.DefaultInfo(Script='(Get-AzContext).Subscription.Id')] | ||
| [System.String] | ||
| # Azure subscription Id. | ||
| ${SubscriptionId}, | ||
|
|
||
| [Parameter(Mandatory)] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Body')] | ||
| [System.String] | ||
| # Path of the file to be uploaded | ||
| ${FilePath}, | ||
|
|
||
| [Parameter()] | ||
| [Alias('AzureRMContext', 'AzureCredential')] | ||
| [ValidateNotNull()] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Azure')] | ||
| [System.Management.Automation.PSObject] | ||
| # The DefaultProfile parameter is not functional. | ||
| # Use the SubscriptionId parameter when available if executing the cmdlet against a different subscription. | ||
| ${DefaultProfile}, | ||
|
|
||
| [Parameter(DontShow)] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Runtime')] | ||
| [System.Management.Automation.SwitchParameter] | ||
| # Wait for .NET debugger to attach | ||
| ${Break}, | ||
|
|
||
| [Parameter(DontShow)] | ||
| [ValidateNotNull()] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Runtime')] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.Support.Runtime.SendAsyncStep[]] | ||
| # SendAsync Pipeline Steps to be appended to the front of the pipeline | ||
| ${HttpPipelineAppend}, | ||
|
|
||
| [Parameter(DontShow)] | ||
| [ValidateNotNull()] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Runtime')] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.Support.Runtime.SendAsyncStep[]] | ||
| # SendAsync Pipeline Steps to be prepended to the front of the pipeline | ||
| ${HttpPipelinePrepend}, | ||
|
|
||
| [Parameter(DontShow)] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Runtime')] | ||
| [System.Uri] | ||
| # The URI for the proxy server to use | ||
| ${Proxy}, | ||
|
|
||
| [Parameter(DontShow)] | ||
| [ValidateNotNull()] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Runtime')] | ||
| [System.Management.Automation.PSCredential] | ||
| # Credentials for a proxy server to use for the remote call | ||
| ${ProxyCredential}, | ||
|
|
||
| [Parameter(DontShow)] | ||
| [Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Runtime')] | ||
| [System.Management.Automation.SwitchParameter] | ||
| # Use the default credentials for the proxy | ||
| ${ProxyUseDefaultCredentials} | ||
| ) | ||
|
|
||
| process { | ||
| $FileName = Split-Path $FilePath -Leaf | ||
| $MaxChunkSize = 2.5 * 1024 * 1024 #2.5 MB | ||
| $MaxFileSize = 5 * 1024 * 1024 #5 MB | ||
| $FileContentBytes = Get-Content -Path $FilePath -Raw | ||
|
|
||
| if($FileContentBytes -eq $Null){ | ||
| throw "File cannot be empty" | ||
| } | ||
|
|
||
| $FileContentByteArray = [System.Text.Encoding]::UTF8.GetBytes($FileContentBytes) | ||
| $FileSize = $FileContentByteArray.Length | ||
|
|
||
| if($FileSize -gt $MaxFileSize){ | ||
| throw "File size is greater than the maximum file size of 5 MB" | ||
| } | ||
|
|
||
| $ChunkSize = If($FileSize -gt $MaxChunkSize) {$MaxChunkSize} Else {$FileSize} | ||
| $NumberOfChunks = [int][Math]::Floor($FileSize / $ChunkSize); | ||
|
|
||
| If($FileSize % $ChunkSize -gt 0) | ||
| { | ||
| $NumberOfChunks++ | ||
| } | ||
|
|
||
| $PSBoundParameters.Remove('FilePath') | Out-Null | ||
| New-AzSupportFile -ErrorAction Stop -Name $FileName -FileSize $FileSize -ChunkSize $ChunkSize -NumberOfChunk $NumberOfChunks @PSBoundParameters | ||
|
|
||
| $chunkIndex = 0 | ||
| $startIndex = 0 | ||
| $endIndex = $ChunkSize - 1 | ||
|
|
||
| while($chunkIndex -lt $NumberOfChunks){ | ||
| $FileContent = [convert]::ToBase64String($FileContentByteArray[$startIndex..$endIndex]) | ||
| Invoke-AzSupportUploadFile -ErrorAction Stop -FileName $FileName -ChunkIndex $chunkIndex -Content $FileContent @PSBoundParameters | ||
| $chunkIndex++ | ||
| $startIndex = $endIndex + 1 | ||
| $endIndex = $FileSize - 1 | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we have this here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was listed in the swagger as a problem classification property-do we not need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did not see the model-name for problem classification property. Does that need to be added in that case?