Skip to content

Commit 7bdc9aa

Browse files
authored
Merge pull request #1 from grhuangmsft/users/grhuang/azsupport-autorest-feature
Users/grhuang/azsupport autorest feature
2 parents 6a3baa3 + 60b7341 commit 7bdc9aa

File tree

53 files changed

+1887
-1328
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1887
-1328
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-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'
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', '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'
1515
PrivateData = @{
1616
PSData = @{
1717
Tags = 'Azure', 'ResourceManager', 'ARM', 'PSModule', 'Support'

src/Support/Support.Autorest/README.md

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,10 @@ commit: 99b27b136352e2f16c3f868857fa33157ace895f
3535
require:
3636
# readme.azure.noprofile.md is the common configuration file
3737
- $(this-folder)/../../readme.azure.noprofile.md
38-
# - $(repo)/specification/support/resource-manager/readme.md
3938
# If the swagger has not been put in the repo, you may uncomment the following line and refer to it locally
4039
# - (this-folder)/relative-path-to-your-local-readme.md
4140
input-file:
4241
- $(repo)/specification/support/resource-manager/Microsoft.Support/preview/2022-09-01-preview/support.json
43-
# try-require:
44-
# - $(repo)/specification/support/resource-manager/readme.powershell.md
4542

4643
# For new RP, the version is 0.1.0
4744
module-version: 0.1.0
@@ -60,39 +57,83 @@ directive:
6057
set:
6158
format-table:
6259
properties:
63-
# - Id
6460
- DisplayName
6561
- Name
66-
- SecondaryConsentEnabled # Do we need this?
67-
# - Type
62+
- SecondaryConsentEnabled
6863
- where:
6964
model-name: Service
7065
set:
7166
format-table:
7267
properties:
73-
# - Id
7468
- DisplayName
7569
- Name
76-
- ResourceType # Do we need this?
77-
# - Type
70+
- ResourceType
7871
- where:
7972
model-name: FileDetails
8073
set:
8174
format-table:
8275
properties:
83-
# - Id
8476
- Name
8577
- CreatedOn
8678
- ChunkSize
8779
- FileSize
8880
- NumberOfChunks
89-
# - Type
81+
- where:
82+
subject: UploadFile
83+
parameter-name: FileWorkspaceName
84+
set:
85+
alias: WorkspaceName
86+
- where:
87+
subject: UploadFilesNoSubscription
88+
parameter-name: FileWorkspaceName
89+
set:
90+
alias: WorkspaceName
91+
- where:
92+
subject: FileWorkspacesNoSubscription
93+
parameter-name: FileWorkspaceName
94+
set:
95+
alias: Name
96+
- where:
97+
subject: FilesNoSubscription
98+
parameter-name: FileName
99+
set:
100+
alias: Name
101+
- where:
102+
subject: FilesNoSubscription
103+
parameter-name: FileWorkspaceName
104+
set:
105+
alias: WorkspaceName
106+
- where:
107+
verb: New
108+
subject: File
109+
hide: true
110+
- where:
111+
verb: New
112+
subject: FilesNoSubscription
113+
hide: true
114+
- where:
115+
verb: Update
116+
subject: File
117+
remove: true
118+
- where:
119+
verb: Update
120+
subject: FilesNoSubscription
121+
remove: true
122+
- where:
123+
verb: Invoke
124+
subject: UploadFile
125+
hide: true
126+
- where:
127+
verb: Invoke
128+
subject: UploadFilesNoSubscription
129+
hide: true
90130
# Following are common directives which are normally required in all the RPs
91131
# 1. Remove the unexpanded parameter set
92132
# 2. For New-* cmdlets, ViaIdentity is not required
93133
# Following two directives are v4 specific
94134
- where:
95-
variant: ^(Create|Update)(?!.*?Expanded)
135+
variant: ^(Create|Update)(?!.*?Expanded|JsonFilePath|JsonString)
136+
subject: ^(?!FileWorkspace|FileWorkspacesNoSubscription$).*
96137
remove: true
97138
- where:
98139
variant: ^CreateViaIdentity.*$
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
2+
# ----------------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# Code generated by Microsoft (R) AutoRest Code Generator.Changes may cause incorrect behavior and will be lost if the code
14+
# is regenerated.
15+
# ----------------------------------------------------------------------------------
16+
17+
<#
18+
.Synopsis
19+
Creates and uploads a new file under a workspace for the specified subscription.
20+
.Description
21+
Creates and uploads a new file under a workspace for the specified subscription.
22+
.Example
23+
{{ Add code here }}
24+
.Example
25+
{{ Add code here }}
26+
27+
.Outputs
28+
Microsoft.Azure.PowerShell.Cmdlets.Support.Models.IFileDetails
29+
.Link
30+
https://learn.microsoft.com/powershell/module/az.support/new-azsupportfile
31+
#>
32+
function New-AzSupportFileAndUpload {
33+
[OutputType([Microsoft.Azure.PowerShell.Cmdlets.Support.Models.IFileDetails])]
34+
[CmdletBinding(DefaultParameterSetName='CreateExpanded', PositionalBinding=$false, SupportsShouldProcess, ConfirmImpact='Medium')]
35+
param(
36+
[Parameter(Mandatory)]
37+
[Alias('FileWorkspaceName')]
38+
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Path')]
39+
[System.String]
40+
# File workspace name.
41+
${WorkspaceName},
42+
43+
[Parameter()]
44+
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Path')]
45+
[Microsoft.Azure.PowerShell.Cmdlets.Support.Runtime.DefaultInfo(Script='(Get-AzContext).Subscription.Id')]
46+
[System.String]
47+
# Azure subscription Id.
48+
${SubscriptionId},
49+
50+
[Parameter(Mandatory)]
51+
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Body')]
52+
[System.String]
53+
# Path of the file to be uploaded
54+
${FilePath},
55+
56+
[Parameter()]
57+
[Alias('AzureRMContext', 'AzureCredential')]
58+
[ValidateNotNull()]
59+
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Azure')]
60+
[System.Management.Automation.PSObject]
61+
# The DefaultProfile parameter is not functional.
62+
# Use the SubscriptionId parameter when available if executing the cmdlet against a different subscription.
63+
${DefaultProfile},
64+
65+
[Parameter(DontShow)]
66+
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Runtime')]
67+
[System.Management.Automation.SwitchParameter]
68+
# Wait for .NET debugger to attach
69+
${Break},
70+
71+
[Parameter(DontShow)]
72+
[ValidateNotNull()]
73+
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Runtime')]
74+
[Microsoft.Azure.PowerShell.Cmdlets.Support.Runtime.SendAsyncStep[]]
75+
# SendAsync Pipeline Steps to be appended to the front of the pipeline
76+
${HttpPipelineAppend},
77+
78+
[Parameter(DontShow)]
79+
[ValidateNotNull()]
80+
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Runtime')]
81+
[Microsoft.Azure.PowerShell.Cmdlets.Support.Runtime.SendAsyncStep[]]
82+
# SendAsync Pipeline Steps to be prepended to the front of the pipeline
83+
${HttpPipelinePrepend},
84+
85+
[Parameter(DontShow)]
86+
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Runtime')]
87+
[System.Uri]
88+
# The URI for the proxy server to use
89+
${Proxy},
90+
91+
[Parameter(DontShow)]
92+
[ValidateNotNull()]
93+
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Runtime')]
94+
[System.Management.Automation.PSCredential]
95+
# Credentials for a proxy server to use for the remote call
96+
${ProxyCredential},
97+
98+
[Parameter(DontShow)]
99+
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Runtime')]
100+
[System.Management.Automation.SwitchParameter]
101+
# Use the default credentials for the proxy
102+
${ProxyUseDefaultCredentials}
103+
)
104+
105+
process {
106+
$FileName = Split-Path $FilePath -Leaf
107+
$MaxChunkSize = 2.5 * 1024 * 1024 #2.5 MB
108+
$MaxFileSize = 5 * 1024 * 1024 #5 MB
109+
$FileContentBytes = Get-Content -Path $FilePath -Raw
110+
111+
if($FileContentBytes -eq $Null){
112+
throw "File cannot be empty"
113+
}
114+
115+
$FileContentByteArray = [System.Text.Encoding]::UTF8.GetBytes($FileContentBytes)
116+
$FileSize = $FileContentByteArray.Length
117+
118+
if($FileSize -gt $MaxFileSize){
119+
throw "File size is greater than the maximum file size of 5 MB"
120+
}
121+
122+
$ChunkSize = If($FileSize -gt $MaxChunkSize) {$MaxChunkSize} Else {$FileSize}
123+
$NumberOfChunks = [int][Math]::Floor($FileSize / $ChunkSize);
124+
125+
If($FileSize % $ChunkSize -gt 0)
126+
{
127+
$NumberOfChunks++
128+
}
129+
130+
$PSBoundParameters.Remove('FilePath') | Out-Null
131+
New-AzSupportFile -ErrorAction Stop -Name $FileName -FileSize $FileSize -ChunkSize $ChunkSize -NumberOfChunk $NumberOfChunks @PSBoundParameters
132+
133+
$chunkIndex = 0
134+
$startIndex = 0
135+
$endIndex = $ChunkSize - 1
136+
137+
while($chunkIndex -lt $NumberOfChunks){
138+
$FileContent = [convert]::ToBase64String($FileContentByteArray[$startIndex..$endIndex])
139+
Invoke-AzSupportUploadFile -ErrorAction Stop -FileName $FileName -ChunkIndex $chunkIndex -Content $FileContent @PSBoundParameters
140+
$chunkIndex++
141+
$startIndex = $endIndex + 1
142+
$endIndex = $FileSize - 1
143+
}
144+
}
145+
}

0 commit comments

Comments
 (0)