Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1b15859
correct readme to include file workspace create
grhuangmsft Jan 11, 2024
c2e620c
add custom cmdlet for creating and uploading the file
grhuangmsft Jan 12, 2024
e2cc76e
chunking logic for larger files
grhuangmsft Jan 17, 2024
07ace3d
add error for custom cmdlet when file too big
grhuangmsft Jan 19, 2024
69b3443
combined cmdlets
grhuangmsft Jan 19, 2024
f414931
edit custom file upload command to not use default subscriptionid
grhuangmsft Jan 19, 2024
a7546e4
no default value for subid in custom file upload
grhuangmsft Jan 19, 2024
1f7f741
separate subscription and no subscription commands
grhuangmsft Jan 23, 2024
a22e254
remove comments from combined cmd for file
grhuangmsft Jan 23, 2024
5dea32a
fix cmd
grhuangmsft Jan 23, 2024
a5b213d
custom no subscription file upload commands
grhuangmsft Jan 23, 2024
b953811
autogen docs for no sub file upload
grhuangmsft Jan 23, 2024
276498c
hide individual file commands
grhuangmsft Jan 23, 2024
487bef6
add back workspace commands
grhuangmsft Jan 23, 2024
ef75f6b
add name as alias for fileworkspacename fileworkspacesnosubscription
grhuangmsft Jan 24, 2024
ec6d597
remove update files and add alias for nosubscription file commands
grhuangmsft Jan 24, 2024
9715b15
tests for get service
grhuangmsft Jan 26, 2024
b1b98b7
tests for problem classification
grhuangmsft Jan 26, 2024
d19fb89
try adding erroractionpreference = stop
grhuangmsft Jan 29, 2024
1d8bed2
tests for new file workspace
grhuangmsft Jan 29, 2024
41e373b
tests for get file workspace
grhuangmsft Jan 30, 2024
f41fe6c
more tests
grhuangmsft Jan 30, 2024
1313bdc
add tests for new file and upload, removefile name as a parameter
grhuangmsft Jan 31, 2024
5332d08
remove new files no subscription
grhuangmsft Jan 31, 2024
683579a
tests for get file
grhuangmsft Jan 31, 2024
f4e7b8e
erroraction stop
grhuangmsft Feb 1, 2024
60b7341
remove unnecessary comments and print statements
grhuangmsft Feb 1, 2024
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
2 changes: 1 addition & 1 deletion src/Support/Support.Autorest/Az.Support.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
DotNetFrameworkVersion = '4.7.2'
RequiredAssemblies = './bin/Az.Support.private.dll'
FormatsToProcess = './Az.Support.format.ps1xml'
FunctionsToExport = 'Get-AzSupportChatTranscript', 'Get-AzSupportChatTranscriptsNoSubscription', 'Get-AzSupportCommunication', 'Get-AzSupportCommunicationsNoSubscription', 'Get-AzSupportFile', 'Get-AzSupportFilesNoSubscription', 'Get-AzSupportFileWorkspace', 'Get-AzSupportFileWorkspacesNoSubscription', 'Get-AzSupportProblemClassification', 'Get-AzSupportService', 'Get-AzSupportTicket', 'Get-AzSupportTicketChatTranscriptsNoSubscription', 'Get-AzSupportTicketCommunicationsNoSubscription', 'Get-AzSupportTicketsNoSubscription', 'Invoke-AzSupportUploadFile', 'Invoke-AzSupportUploadFilesNoSubscription', 'New-AzSupportCommunication', 'New-AzSupportCommunicationsNoSubscription', 'New-AzSupportFile', 'New-AzSupportFilesNoSubscription', 'New-AzSupportTicket', 'New-AzSupportTicketsNoSubscription', 'Test-AzSupportCommunicationNameAvailability', 'Test-AzSupportCommunicationsNoSubscriptionNameAvailability', 'Test-AzSupportTicketNameAvailability', 'Test-AzSupportTicketsNoSubscriptionNameAvailability', 'Update-AzSupportCommunication', 'Update-AzSupportCommunicationsNoSubscription', 'Update-AzSupportFile', 'Update-AzSupportFilesNoSubscription', 'Update-AzSupportTicket', 'Update-AzSupportTicketsNoSubscription'
FunctionsToExport = 'Get-AzSupportChatTranscript', 'Get-AzSupportChatTranscriptsNoSubscription', 'Get-AzSupportCommunication', 'Get-AzSupportCommunicationsNoSubscription', 'Get-AzSupportFile', 'Get-AzSupportFilesNoSubscription', 'Get-AzSupportFileWorkspace', 'Get-AzSupportFileWorkspacesNoSubscription', 'Get-AzSupportProblemClassification', 'Get-AzSupportService', 'Get-AzSupportTicket', 'Get-AzSupportTicketChatTranscriptsNoSubscription', 'Get-AzSupportTicketCommunicationsNoSubscription', 'Get-AzSupportTicketsNoSubscription', 'New-AzSupportCommunication', 'New-AzSupportCommunicationsNoSubscription', 'New-AzSupportFileAndUpload', 'New-AzSupportFileAndUploadNoSubscription', 'New-AzSupportFileWorkspace', 'New-AzSupportFileWorkspacesNoSubscription', 'New-AzSupportTicket', 'New-AzSupportTicketsNoSubscription', 'Test-AzSupportCommunicationNameAvailability', 'Test-AzSupportCommunicationsNoSubscriptionNameAvailability', 'Test-AzSupportTicketNameAvailability', 'Test-AzSupportTicketsNoSubscriptionNameAvailability', 'Update-AzSupportCommunication', 'Update-AzSupportCommunicationsNoSubscription', 'Update-AzSupportTicket', 'Update-AzSupportTicketsNoSubscription'
PrivateData = @{
PSData = @{
Tags = 'Azure', 'ResourceManager', 'ARM', 'PSModule', 'Support'
Expand Down
65 changes: 53 additions & 12 deletions src/Support/Support.Autorest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -60,39 +57,83 @@ directive:
set:
format-table:
properties:
# - Id
- DisplayName
- Name
- SecondaryConsentEnabled # Do we need this?
# - Type
- SecondaryConsentEnabled

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?

Copy link
Owner Author

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?

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?

- 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

Choose a reason for hiding this comment

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

why is there another alias 'Name' instead of 'WorkspaceName' here?

Copy link
Owner Author

Choose a reason for hiding this comment

The 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

Choose a reason for hiding this comment

The 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?

Copy link
Owner Author

Choose a reason for hiding this comment

The 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.*$
Expand Down
145 changes: 145 additions & 0 deletions src/Support/Support.Autorest/custom/New-AzSupportFileAndUpload.ps1
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
}
}
}
Loading