Skip to content

Commit

Permalink
add error for custom cmdlet when file too big
Browse files Browse the repository at this point in the history
  • Loading branch information
grhuangmsft committed Jan 19, 2024
1 parent e2cc76e commit 07ace3d
Show file tree
Hide file tree
Showing 8 changed files with 359 additions and 14 deletions.
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-AzSupportFileAndUpload', 'New-AzSupportFilesNoSubscription', 'New-AzSupportFileWorkspace', 'New-AzSupportFileWorkspacesNoSubscription', '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', 'Invoke-AzSupportUploadFile', 'Invoke-AzSupportUploadFilesNoSubscription', 'New-AzSupportCommunication', 'New-AzSupportCommunicationsNoSubscription', 'New-AzSupportFile', 'New-AzSupportFileAndUpload', 'New-AzSupportFilesNoSubscription', 'New-AzSupportFileWorkspace', 'New-AzSupportFileWorkspacesNoSubscription', 'New-AzSupportTicket', 'New-AzSupportTicketsNoSubscription', 'Test-AzSupportCommunicationNameAvailability', 'Test-AzSupportCommunicationsNoSubscriptionNameAvailability', 'Test-AzSupportTicketNameAvailability', 'Test-AzSupportTicketsNoSubscriptionNameAvailability', 'Update-AzSupportCommunication', 'Update-AzSupportCommunicationsNoSubscription', 'Update-AzSupportFile', 'Update-AzSupportFilesNoSubscription', 'Update-AzSupportTicket', 'Update-AzSupportTicketsNoSubscription'
PrivateData = @{
PSData = @{
Tags = 'Azure', 'ResourceManager', 'ARM', 'PSModule', 'Support'
Expand Down
89 changes: 77 additions & 12 deletions src/Support/Support.Autorest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,79 @@ subject-prefix: $(service-name)
# nested-object-to-string: true

directive:
# Remove the default value of subscriptionId
# - from: source-file-csharp
# where: $
# transform: $ = $.replace(' [Microsoft.Azure.PowerShell.Cmdlets.Support.Runtime.DefaultInfo(\n Name = @"",\n Description =@"",\n Script = @"(Get-AzContext).Subscription.Id",\n SetCondition = @"")]\n', '')
# Rename the operation ids of NoSubscription to make them can be combined automatically
# - from: swagger-document
# where: '$.paths["/providers/Microsoft.Support/checkNameAvailability"].post'
# transform: >
# $["operationId"] = "SupportTickets_CheckNameAvailabilityWithNoSubscriptionId";
# - from: swagger-document
# where: '$.paths["/providers/Microsoft.Support/supportTickets"].get'
# transform: >
# $["operationId"] = "SupportTickets_ListWithNoSubscriptionId";
# - from: swagger-document
# where: '$.paths["/providers/Microsoft.Support/supportTickets/{supportTicketName}"].get'
# transform: >
# $["operationId"] = "SupportTickets_GetWithNoSubscriptionId";
# - from: swagger-document
# where: '$.paths["/providers/Microsoft.Support/supportTickets/{supportTicketName}"].patch'
# transform: >
# $["operationId"] = "SupportTickets_UpdateWithNoSubscriptionId";
# - from: swagger-document
# where: '$.paths["/providers/Microsoft.Support/supportTickets/{supportTicketName}"].put'
# transform: >
# $["operationId"] = "SupportTickets_CreateWithNoSubscriptionId";
# - from: swagger-document
# where: '$.paths["/providers/Microsoft.Support/supportTickets/{supportTicketName}/checkNameAvailability"].post'
# transform: >
# $["operationId"] = "Communications_CheckNameAvailabilityWithNoSubscriptionId";
# - from: swagger-document
# where: '$.paths["/providers/Microsoft.Support/supportTickets/{supportTicketName}/communications"].get'
# transform: >
# $["operationId"] = "SupportTicketCommunications_ListWithNoSubscriptionId";
# - from: swagger-document
# where: '$.paths["/providers/Microsoft.Support/supportTickets/{supportTicketName}/communications/{communicationName}"].get'
# transform: >
# $["operationId"] = "Communications_GetWithNoSubscriptionId";
# - from: swagger-document
# where: '$.paths["/providers/Microsoft.Support/supportTickets/{supportTicketName}/communications/{communicationName}"].put'
# transform: >
# $["operationId"] = "Communications_CreateWithNoSubscriptionId";
# - from: swagger-document
# where: '$.paths["/providers/Microsoft.Support/supportTickets/{supportTicketName}/chatTranscripts"].get'
# transform: >
# $["operationId"] = "SupportTicketChatTranscripts_ListWithNoSubscriptionId";
# - from: swagger-document
# where: '$.paths["/providers/Microsoft.Support/supportTickets/{supportTicketName}/chatTranscripts/{chatTranscriptName}"].get'
# transform: >
# $["operationId"] = "ChatTranscripts_GetWithNoSubscriptionId";
# - from: swagger-document
# where: '$.paths["/providers/Microsoft.Support/fileWorkspaces/{fileWorkspaceName}"].get'
# transform: >
# $["operationId"] = "FileWorkspaces_GetWithNoSubscriptionId";
# - from: swagger-document
# where: '$.paths["/providers/Microsoft.Support/fileWorkspaces/{fileWorkspaceName}"].put'
# transform: >
# $["operationId"] = "FileWorkspaces_CreateWithNoSubscriptionId";
# - from: swagger-document
# where: '$.paths["/providers/Microsoft.Support/fileWorkspaces/{fileWorkspaceName}/files"].get'
# transform: >
# $["operationId"] = "Files_ListWithNoSubscriptionId";
# - from: swagger-document
# where: '$.paths["/providers/Microsoft.Support/fileWorkspaces/{fileWorkspaceName}/files/{fileName}"].get'
# transform: >
# $["operationId"] = "Files_GetWithNoSubscriptionId";
# - from: swagger-document
# where: '$.paths["/providers/Microsoft.Support/fileWorkspaces/{fileWorkspaceName}/files/{fileName}"].put'
# transform: >
# $["operationId"] = "Files_CreateWithNoSubscriptionId";
# - from: swagger-document
# where: '$.paths["/providers/Microsoft.Support/fileWorkspaces/{fileWorkspaceName}/files/{fileName}/upload"].post'
# transform: >
# $["operationId"] = "Files_UploadWithNoSubscriptionId";
- where:
model-name: ProblemClassification
set:
Expand All @@ -81,22 +154,14 @@ directive:
- ChunkSize
- FileSize
- NumberOfChunks
- where:
verb: New
subject: File
hide: true
#- where:
#verb: New
#subject: File
#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:
# verb: New
# subject: AzSupportFileWorkspace
# remove: false
# - where:
# verb: New
# subject: AzSupportFileWorkspacesNoSubscription
# remove: false
- where:
variant: ^(Create|Update)(?!.*?Expanded|JsonFilePath|JsonString)
subject: ^(?!FileWorkspace|FileWorkspacesNoSubscription$).*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ process {
$FileContentBytes = Get-Content -Path $FilePath -Raw
$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}
Write-Output "Length of byte array: " $FileSize
Write-Output "Max chunk size: " $MaxChunkSize
Expand All @@ -193,7 +196,13 @@ process {
Write-Output "Number of chunks: " $NumberOfChunks

# try{
if($SubscriptionId)
{
New-AzSupportFile -SubscriptionId $SubscriptionId -Name $Name -WorkspaceName $WorkspaceName -FileSize $FileSize -ChunkSize $ChunkSize -NumberOfChunk $NumberOfChunks
}
else{
New-AzSupportFile -Name $Name -WorkspaceName $WorkspaceName -FileSize $FileSize -ChunkSize $ChunkSize -NumberOfChunk $NumberOfChunks
}
# }
# catch{
# Write-Host $_
Expand All @@ -213,7 +222,12 @@ process {
Write-Output "end index: " + $endIndex
$FileContent = [convert]::ToBase64String($FileContentByteArray[$startIndex..$endIndex])
#Write-Output "contents of file: " $FileContent
Invoke-AzSupportUploadFile -FileName $Name -FileWorkspaceName $WorkspaceName -ChunkIndex $chunkIndex -Content $FileContent
if($SubscriptionId){
Invoke-AzSupportUploadFile -SubscriptionId $SubscriptionId -FileName $Name -FileWorkspaceName $WorkspaceName -ChunkIndex $chunkIndex -Content $FileContent
}
else{
Invoke-AzSupportUploadFile -FileName $Name -FileWorkspaceName $WorkspaceName -ChunkIndex $chunkIndex -Content $FileContent
}
$chunkIndex++
$startIndex = $endIndex + 1
$endIndex = $FileSize - 1
Expand Down
3 changes: 3 additions & 0 deletions src/Support/Support.Autorest/docs/Az.Support.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ Adds a new customer communication to an Azure support ticket.
### [New-AzSupportCommunicationsNoSubscription](New-AzSupportCommunicationsNoSubscription.md)
Adds a new customer communication to an Azure support ticket.

### [New-AzSupportFile](New-AzSupportFile.md)
Creates a new file under a workspace for the specified subscription.

### [New-AzSupportFileAndUpload](New-AzSupportFileAndUpload.md)
Creates and uploads a new file under a workspace for the specified subscription.

Expand Down
199 changes: 199 additions & 0 deletions src/Support/Support.Autorest/docs/New-AzSupportFile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
---
external help file:
Module Name: Az.Support
online version: https://learn.microsoft.com/powershell/module/az.support/new-azsupportfile
schema: 2.0.0
---

# New-AzSupportFile

## SYNOPSIS
Creates a new file under a workspace for the specified subscription.

## SYNTAX

```
New-AzSupportFile -Name <String> -WorkspaceName <String> [-SubscriptionId <String>] [-ChunkSize <Single>]
[-FileSize <Single>] [-NumberOfChunk <Single>] [-DefaultProfile <PSObject>] [-Confirm] [-WhatIf]
[<CommonParameters>]
```

## DESCRIPTION
Creates a new file under a workspace for the specified subscription.

## EXAMPLES

### Example 1: {{ Add title here }}
```powershell
{{ Add code here }}
```

```output
{{ Add output here (remove the output block if the example doesn't have an output) }}
```

{{ Add description here }}

### Example 2: {{ Add title here }}
```powershell
{{ Add code here }}
```

```output
{{ Add output here (remove the output block if the example doesn't have an output) }}
```

{{ Add description here }}

## PARAMETERS

### -ChunkSize
Size of each chunk

```yaml
Type: System.Single
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -DefaultProfile
The DefaultProfile parameter is not functional.
Use the SubscriptionId parameter when available if executing the cmdlet against a different subscription.
```yaml
Type: System.Management.Automation.PSObject
Parameter Sets: (All)
Aliases: AzureRMContext, AzureCredential

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -FileSize
Size of the file to be uploaded
```yaml
Type: System.Single
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Name
File name.
```yaml
Type: System.String
Parameter Sets: (All)
Aliases: FileName

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -NumberOfChunk
Number of chunks to be uploaded
```yaml
Type: System.Single
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -SubscriptionId
Azure subscription Id.
```yaml
Type: System.String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: (Get-AzContext).Subscription.Id
Accept pipeline input: False
Accept wildcard characters: False
```
### -WorkspaceName
File workspace name.
```yaml
Type: System.String
Parameter Sets: (All)
Aliases: FileWorkspaceName

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -Confirm
Prompts you for confirmation before running the cmdlet.
```yaml
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases: cf

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -WhatIf
Shows what would happen if the cmdlet runs.
The cmdlet is not run.
```yaml
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases: wi

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
## INPUTS
## OUTPUTS
### Microsoft.Azure.PowerShell.Cmdlets.Support.Models.IFileDetails
## NOTES
## RELATED LINKS
22 changes: 22 additions & 0 deletions src/Support/Support.Autorest/examples/New-AzSupportFile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
### Example 1: {{ Add title here }}
```powershell
{{ Add code here }}
```

```output
{{ Add output here (remove the output block if the example doesn't have an output) }}
```

{{ Add description here }}

### Example 2: {{ Add title here }}
```powershell
{{ Add code here }}
```

```output
{{ Add output here (remove the output block if the example doesn't have an output) }}
```

{{ Add description here }}

Loading

0 comments on commit 07ace3d

Please sign in to comment.