Skip to content

Commit 0d18131

Browse files
Merge branch 'users/grhuang/azsupport-autorest' into users/shreyakumar/grhuang/azsupport-autorest
2 parents 3bad989 + 762b446 commit 0d18131

File tree

71 files changed

+2599
-1631
lines changed

Some content is hidden

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

71 files changed

+2599
-1631
lines changed

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+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
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-AzSupportFileAndUploadNoSubscription {
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(Mandatory)]
44+
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Body')]
45+
[System.String]
46+
# Path of the file to be uploaded
47+
${FilePath},
48+
49+
[Parameter()]
50+
[Alias('AzureRMContext', 'AzureCredential')]
51+
[ValidateNotNull()]
52+
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Azure')]
53+
[System.Management.Automation.PSObject]
54+
# The DefaultProfile parameter is not functional.
55+
# Use the SubscriptionId parameter when available if executing the cmdlet against a different subscription.
56+
${DefaultProfile},
57+
58+
[Parameter(DontShow)]
59+
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Runtime')]
60+
[System.Management.Automation.SwitchParameter]
61+
# Wait for .NET debugger to attach
62+
${Break},
63+
64+
[Parameter(DontShow)]
65+
[ValidateNotNull()]
66+
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Runtime')]
67+
[Microsoft.Azure.PowerShell.Cmdlets.Support.Runtime.SendAsyncStep[]]
68+
# SendAsync Pipeline Steps to be appended to the front of the pipeline
69+
${HttpPipelineAppend},
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 prepended to the front of the pipeline
76+
${HttpPipelinePrepend},
77+
78+
[Parameter(DontShow)]
79+
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Runtime')]
80+
[System.Uri]
81+
# The URI for the proxy server to use
82+
${Proxy},
83+
84+
[Parameter(DontShow)]
85+
[ValidateNotNull()]
86+
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Runtime')]
87+
[System.Management.Automation.PSCredential]
88+
# Credentials for a proxy server to use for the remote call
89+
${ProxyCredential},
90+
91+
[Parameter(DontShow)]
92+
[Microsoft.Azure.PowerShell.Cmdlets.Support.Category('Runtime')]
93+
[System.Management.Automation.SwitchParameter]
94+
# Use the default credentials for the proxy
95+
${ProxyUseDefaultCredentials}
96+
)
97+
98+
99+
process {
100+
$FileName = Split-Path $FilePath -Leaf
101+
$MaxChunkSize = 2.5 * 1024 * 1024 #2.5 MB
102+
$MaxFileSize = 5 * 1024 * 1024 #5 MB
103+
$FileContentBytes = Get-Content -Path $FilePath -Raw
104+
105+
if($FileContentBytes -eq $Null){
106+
throw "File cannot be empty"
107+
}
108+
109+
$FileContentByteArray = [System.Text.Encoding]::UTF8.GetBytes($FileContentBytes)
110+
$FileSize = $FileContentByteArray.Length
111+
112+
if($FileSize -gt $MaxFileSize){
113+
throw "File size is greater than the maximum file size of 5 MB"
114+
}
115+
116+
$ChunkSize = If($FileSize -gt $MaxChunkSize) {$MaxChunkSize} Else {$FileSize}
117+
$NumberOfChunks = [int][Math]::Floor($FileSize / $ChunkSize);
118+
119+
If($FileSize % $ChunkSize -gt 0)
120+
{
121+
$NumberOfChunks++
122+
}
123+
124+
$PSBoundParameters.Remove('FilePath') | Out-Null
125+
New-AzSupportFilesNoSubscription -ErrorAction Stop -Name $FileName -FileSize $FileSize -ChunkSize $ChunkSize -NumberOfChunk $NumberOfChunks @PSBoundParameters
126+
127+
$chunkIndex = 0
128+
$startIndex = 0
129+
$endIndex = $ChunkSize - 1
130+
131+
while($chunkIndex -lt $NumberOfChunks){
132+
$FileContent = [convert]::ToBase64String($FileContentByteArray[$startIndex..$endIndex])
133+
Invoke-AzSupportUploadFilesNoSubscription -ErrorAction Stop -FileName $FileName -ChunkIndex $chunkIndex -Content $FileContent @PSBoundParameters
134+
$chunkIndex++
135+
$startIndex = $endIndex + 1
136+
$endIndex = $FileSize - 1
137+
}
138+
}
139+
}

0 commit comments

Comments
 (0)