Skip to content

Commit 07ace3d

Browse files
committed
add error for custom cmdlet when file too big
1 parent e2cc76e commit 07ace3d

File tree

8 files changed

+359
-14
lines changed

8 files changed

+359
-14
lines changed

src/Support/Support.Autorest/Az.Support.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
DotNetFrameworkVersion = '4.7.2'
1212
RequiredAssemblies = './bin/Az.Support.private.dll'
1313
FormatsToProcess = './Az.Support.format.ps1xml'
14-
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'
14+
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'
1515
PrivateData = @{
1616
PSData = @{
1717
Tags = 'Azure', 'ResourceManager', 'ARM', 'PSModule', 'Support'

src/Support/Support.Autorest/README.md

Lines changed: 77 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,79 @@ subject-prefix: $(service-name)
5555
# nested-object-to-string: true
5656

5757
directive:
58+
# Remove the default value of subscriptionId
59+
# - from: source-file-csharp
60+
# where: $
61+
# transform: $ = $.replace(' [Microsoft.Azure.PowerShell.Cmdlets.Support.Runtime.DefaultInfo(\n Name = @"",\n Description =@"",\n Script = @"(Get-AzContext).Subscription.Id",\n SetCondition = @"")]\n', '')
62+
# Rename the operation ids of NoSubscription to make them can be combined automatically
63+
# - from: swagger-document
64+
# where: '$.paths["/providers/Microsoft.Support/checkNameAvailability"].post'
65+
# transform: >
66+
# $["operationId"] = "SupportTickets_CheckNameAvailabilityWithNoSubscriptionId";
67+
# - from: swagger-document
68+
# where: '$.paths["/providers/Microsoft.Support/supportTickets"].get'
69+
# transform: >
70+
# $["operationId"] = "SupportTickets_ListWithNoSubscriptionId";
71+
# - from: swagger-document
72+
# where: '$.paths["/providers/Microsoft.Support/supportTickets/{supportTicketName}"].get'
73+
# transform: >
74+
# $["operationId"] = "SupportTickets_GetWithNoSubscriptionId";
75+
# - from: swagger-document
76+
# where: '$.paths["/providers/Microsoft.Support/supportTickets/{supportTicketName}"].patch'
77+
# transform: >
78+
# $["operationId"] = "SupportTickets_UpdateWithNoSubscriptionId";
79+
# - from: swagger-document
80+
# where: '$.paths["/providers/Microsoft.Support/supportTickets/{supportTicketName}"].put'
81+
# transform: >
82+
# $["operationId"] = "SupportTickets_CreateWithNoSubscriptionId";
83+
# - from: swagger-document
84+
# where: '$.paths["/providers/Microsoft.Support/supportTickets/{supportTicketName}/checkNameAvailability"].post'
85+
# transform: >
86+
# $["operationId"] = "Communications_CheckNameAvailabilityWithNoSubscriptionId";
87+
# - from: swagger-document
88+
# where: '$.paths["/providers/Microsoft.Support/supportTickets/{supportTicketName}/communications"].get'
89+
# transform: >
90+
# $["operationId"] = "SupportTicketCommunications_ListWithNoSubscriptionId";
91+
# - from: swagger-document
92+
# where: '$.paths["/providers/Microsoft.Support/supportTickets/{supportTicketName}/communications/{communicationName}"].get'
93+
# transform: >
94+
# $["operationId"] = "Communications_GetWithNoSubscriptionId";
95+
# - from: swagger-document
96+
# where: '$.paths["/providers/Microsoft.Support/supportTickets/{supportTicketName}/communications/{communicationName}"].put'
97+
# transform: >
98+
# $["operationId"] = "Communications_CreateWithNoSubscriptionId";
99+
# - from: swagger-document
100+
# where: '$.paths["/providers/Microsoft.Support/supportTickets/{supportTicketName}/chatTranscripts"].get'
101+
# transform: >
102+
# $["operationId"] = "SupportTicketChatTranscripts_ListWithNoSubscriptionId";
103+
# - from: swagger-document
104+
# where: '$.paths["/providers/Microsoft.Support/supportTickets/{supportTicketName}/chatTranscripts/{chatTranscriptName}"].get'
105+
# transform: >
106+
# $["operationId"] = "ChatTranscripts_GetWithNoSubscriptionId";
107+
# - from: swagger-document
108+
# where: '$.paths["/providers/Microsoft.Support/fileWorkspaces/{fileWorkspaceName}"].get'
109+
# transform: >
110+
# $["operationId"] = "FileWorkspaces_GetWithNoSubscriptionId";
111+
# - from: swagger-document
112+
# where: '$.paths["/providers/Microsoft.Support/fileWorkspaces/{fileWorkspaceName}"].put'
113+
# transform: >
114+
# $["operationId"] = "FileWorkspaces_CreateWithNoSubscriptionId";
115+
# - from: swagger-document
116+
# where: '$.paths["/providers/Microsoft.Support/fileWorkspaces/{fileWorkspaceName}/files"].get'
117+
# transform: >
118+
# $["operationId"] = "Files_ListWithNoSubscriptionId";
119+
# - from: swagger-document
120+
# where: '$.paths["/providers/Microsoft.Support/fileWorkspaces/{fileWorkspaceName}/files/{fileName}"].get'
121+
# transform: >
122+
# $["operationId"] = "Files_GetWithNoSubscriptionId";
123+
# - from: swagger-document
124+
# where: '$.paths["/providers/Microsoft.Support/fileWorkspaces/{fileWorkspaceName}/files/{fileName}"].put'
125+
# transform: >
126+
# $["operationId"] = "Files_CreateWithNoSubscriptionId";
127+
# - from: swagger-document
128+
# where: '$.paths["/providers/Microsoft.Support/fileWorkspaces/{fileWorkspaceName}/files/{fileName}/upload"].post'
129+
# transform: >
130+
# $["operationId"] = "Files_UploadWithNoSubscriptionId";
58131
- where:
59132
model-name: ProblemClassification
60133
set:
@@ -81,22 +154,14 @@ directive:
81154
- ChunkSize
82155
- FileSize
83156
- NumberOfChunks
84-
- where:
85-
verb: New
86-
subject: File
87-
hide: true
157+
#- where:
158+
#verb: New
159+
#subject: File
160+
#hide: true
88161
# Following are common directives which are normally required in all the RPs
89162
# 1. Remove the unexpanded parameter set
90163
# 2. For New-* cmdlets, ViaIdentity is not required
91164
# Following two directives are v4 specific
92-
# - where:
93-
# verb: New
94-
# subject: AzSupportFileWorkspace
95-
# remove: false
96-
# - where:
97-
# verb: New
98-
# subject: AzSupportFileWorkspacesNoSubscription
99-
# remove: false
100165
- where:
101166
variant: ^(Create|Update)(?!.*?Expanded|JsonFilePath|JsonString)
102167
subject: ^(?!FileWorkspace|FileWorkspacesNoSubscription$).*

src/Support/Support.Autorest/custom/New-AzSupportFileAndUpload.ps1

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ process {
181181
$FileContentBytes = Get-Content -Path $FilePath -Raw
182182
$FileContentByteArray = [System.Text.Encoding]::UTF8.GetBytes($FileContentBytes)
183183
$FileSize = $FileContentByteArray.Length
184+
if($FileSize -gt $MaxFileSize){
185+
throw "File size is greater than the maximum file size of 5 MB"
186+
}
184187
$ChunkSize = If($FileSize -gt $MaxChunkSize) {$MaxChunkSize} Else {$FileSize}
185188
Write-Output "Length of byte array: " $FileSize
186189
Write-Output "Max chunk size: " $MaxChunkSize
@@ -193,7 +196,13 @@ process {
193196
Write-Output "Number of chunks: " $NumberOfChunks
194197

195198
# try{
199+
if($SubscriptionId)
200+
{
201+
New-AzSupportFile -SubscriptionId $SubscriptionId -Name $Name -WorkspaceName $WorkspaceName -FileSize $FileSize -ChunkSize $ChunkSize -NumberOfChunk $NumberOfChunks
202+
}
203+
else{
196204
New-AzSupportFile -Name $Name -WorkspaceName $WorkspaceName -FileSize $FileSize -ChunkSize $ChunkSize -NumberOfChunk $NumberOfChunks
205+
}
197206
# }
198207
# catch{
199208
# Write-Host $_
@@ -213,7 +222,12 @@ process {
213222
Write-Output "end index: " + $endIndex
214223
$FileContent = [convert]::ToBase64String($FileContentByteArray[$startIndex..$endIndex])
215224
#Write-Output "contents of file: " $FileContent
216-
Invoke-AzSupportUploadFile -FileName $Name -FileWorkspaceName $WorkspaceName -ChunkIndex $chunkIndex -Content $FileContent
225+
if($SubscriptionId){
226+
Invoke-AzSupportUploadFile -SubscriptionId $SubscriptionId -FileName $Name -FileWorkspaceName $WorkspaceName -ChunkIndex $chunkIndex -Content $FileContent
227+
}
228+
else{
229+
Invoke-AzSupportUploadFile -FileName $Name -FileWorkspaceName $WorkspaceName -ChunkIndex $chunkIndex -Content $FileContent
230+
}
217231
$chunkIndex++
218232
$startIndex = $endIndex + 1
219233
$endIndex = $FileSize - 1

src/Support/Support.Autorest/docs/Az.Support.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ Adds a new customer communication to an Azure support ticket.
7474
### [New-AzSupportCommunicationsNoSubscription](New-AzSupportCommunicationsNoSubscription.md)
7575
Adds a new customer communication to an Azure support ticket.
7676

77+
### [New-AzSupportFile](New-AzSupportFile.md)
78+
Creates a new file under a workspace for the specified subscription.
79+
7780
### [New-AzSupportFileAndUpload](New-AzSupportFileAndUpload.md)
7881
Creates and uploads a new file under a workspace for the specified subscription.
7982

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
---
2+
external help file:
3+
Module Name: Az.Support
4+
online version: https://learn.microsoft.com/powershell/module/az.support/new-azsupportfile
5+
schema: 2.0.0
6+
---
7+
8+
# New-AzSupportFile
9+
10+
## SYNOPSIS
11+
Creates a new file under a workspace for the specified subscription.
12+
13+
## SYNTAX
14+
15+
```
16+
New-AzSupportFile -Name <String> -WorkspaceName <String> [-SubscriptionId <String>] [-ChunkSize <Single>]
17+
[-FileSize <Single>] [-NumberOfChunk <Single>] [-DefaultProfile <PSObject>] [-Confirm] [-WhatIf]
18+
[<CommonParameters>]
19+
```
20+
21+
## DESCRIPTION
22+
Creates a new file under a workspace for the specified subscription.
23+
24+
## EXAMPLES
25+
26+
### Example 1: {{ Add title here }}
27+
```powershell
28+
{{ Add code here }}
29+
```
30+
31+
```output
32+
{{ Add output here (remove the output block if the example doesn't have an output) }}
33+
```
34+
35+
{{ Add description here }}
36+
37+
### Example 2: {{ Add title here }}
38+
```powershell
39+
{{ Add code here }}
40+
```
41+
42+
```output
43+
{{ Add output here (remove the output block if the example doesn't have an output) }}
44+
```
45+
46+
{{ Add description here }}
47+
48+
## PARAMETERS
49+
50+
### -ChunkSize
51+
Size of each chunk
52+
53+
```yaml
54+
Type: System.Single
55+
Parameter Sets: (All)
56+
Aliases:
57+
58+
Required: False
59+
Position: Named
60+
Default value: None
61+
Accept pipeline input: False
62+
Accept wildcard characters: False
63+
```
64+
65+
### -DefaultProfile
66+
The DefaultProfile parameter is not functional.
67+
Use the SubscriptionId parameter when available if executing the cmdlet against a different subscription.
68+
69+
```yaml
70+
Type: System.Management.Automation.PSObject
71+
Parameter Sets: (All)
72+
Aliases: AzureRMContext, AzureCredential
73+
74+
Required: False
75+
Position: Named
76+
Default value: None
77+
Accept pipeline input: False
78+
Accept wildcard characters: False
79+
```
80+
81+
### -FileSize
82+
Size of the file to be uploaded
83+
84+
```yaml
85+
Type: System.Single
86+
Parameter Sets: (All)
87+
Aliases:
88+
89+
Required: False
90+
Position: Named
91+
Default value: None
92+
Accept pipeline input: False
93+
Accept wildcard characters: False
94+
```
95+
96+
### -Name
97+
File name.
98+
99+
```yaml
100+
Type: System.String
101+
Parameter Sets: (All)
102+
Aliases: FileName
103+
104+
Required: True
105+
Position: Named
106+
Default value: None
107+
Accept pipeline input: False
108+
Accept wildcard characters: False
109+
```
110+
111+
### -NumberOfChunk
112+
Number of chunks to be uploaded
113+
114+
```yaml
115+
Type: System.Single
116+
Parameter Sets: (All)
117+
Aliases:
118+
119+
Required: False
120+
Position: Named
121+
Default value: None
122+
Accept pipeline input: False
123+
Accept wildcard characters: False
124+
```
125+
126+
### -SubscriptionId
127+
Azure subscription Id.
128+
129+
```yaml
130+
Type: System.String
131+
Parameter Sets: (All)
132+
Aliases:
133+
134+
Required: False
135+
Position: Named
136+
Default value: (Get-AzContext).Subscription.Id
137+
Accept pipeline input: False
138+
Accept wildcard characters: False
139+
```
140+
141+
### -WorkspaceName
142+
File workspace name.
143+
144+
```yaml
145+
Type: System.String
146+
Parameter Sets: (All)
147+
Aliases: FileWorkspaceName
148+
149+
Required: True
150+
Position: Named
151+
Default value: None
152+
Accept pipeline input: False
153+
Accept wildcard characters: False
154+
```
155+
156+
### -Confirm
157+
Prompts you for confirmation before running the cmdlet.
158+
159+
```yaml
160+
Type: System.Management.Automation.SwitchParameter
161+
Parameter Sets: (All)
162+
Aliases: cf
163+
164+
Required: False
165+
Position: Named
166+
Default value: None
167+
Accept pipeline input: False
168+
Accept wildcard characters: False
169+
```
170+
171+
### -WhatIf
172+
Shows what would happen if the cmdlet runs.
173+
The cmdlet is not run.
174+
175+
```yaml
176+
Type: System.Management.Automation.SwitchParameter
177+
Parameter Sets: (All)
178+
Aliases: wi
179+
180+
Required: False
181+
Position: Named
182+
Default value: None
183+
Accept pipeline input: False
184+
Accept wildcard characters: False
185+
```
186+
187+
### CommonParameters
188+
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).
189+
190+
## INPUTS
191+
192+
## OUTPUTS
193+
194+
### Microsoft.Azure.PowerShell.Cmdlets.Support.Models.IFileDetails
195+
196+
## NOTES
197+
198+
## RELATED LINKS
199+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
### Example 1: {{ Add title here }}
2+
```powershell
3+
{{ Add code here }}
4+
```
5+
6+
```output
7+
{{ Add output here (remove the output block if the example doesn't have an output) }}
8+
```
9+
10+
{{ Add description here }}
11+
12+
### Example 2: {{ Add title here }}
13+
```powershell
14+
{{ Add code here }}
15+
```
16+
17+
```output
18+
{{ Add output here (remove the output block if the example doesn't have an output) }}
19+
```
20+
21+
{{ Add description here }}
22+

0 commit comments

Comments
 (0)