Skip to content

Commit 7d67b1d

Browse files
committed
Merge branch 'clu' of https://github.com/Azure/azure-powershell into clu
# Conflicts: # src/CLU/Commands.Common/AzurePSCmdlet.cs
2 parents 728b687 + 06248ee commit 7d67b1d

File tree

78 files changed

+101642
-46833
lines changed

Some content is hidden

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

78 files changed

+101642
-46833
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Param(
2+
[string]$rgname,
3+
[string]$resourceGroupLocation
4+
)
5+
Write-Host "=== Managing Storage Accounts Resources in Azure ==="
6+
7+
$stoname = 'sto' + $rgname;
8+
$stotype = 'Standard_GRS';
9+
$loc = 'West US';
10+
11+
New-AzureRmResourceGroup -Name $rgname -Location $resourceGroupLocation;
12+
13+
Write-Host "1. Create a new storage account"
14+
New-AzureRmStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype;
15+
16+
Write-Host "2. Get info of a storage account"
17+
$stos = Get-AzureRmStorageAccount -ResourceGroupName $rgname;
18+
19+
Write-Host "3. Update storage account type"
20+
$stotype = 'Standard_RAGRS';
21+
Set-AzureRmStorageAccount -ResourceGroupName $rgname -Name $stoname -Type $stotype;
22+
23+
Write-Host "4. Get account key of a storage account"
24+
$stokeys=Get-AzureRmStorageAccountKey -ResourceGroupName $rgname -Name $stoname;
25+
26+
Write-Host "5. Renew key1 of a storage account"
27+
New-AzureRmStorageAccountKey -ResourceGroupName $rgname -Name $stoname -KeyName key1;
28+
29+
Write-Host "6. Renew key2 of a storage account"
30+
New-AzureRmStorageAccountKey -ResourceGroupName $rgname -Name $stoname -KeyName key2;
31+
32+
Write-Host "7. Remove storage account"
33+
Remove-AzureRmStorageAccount -ResourceGroupName $rgname -Name $stoname;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
printf "\n=== Managing Storage Accounts Resources in Azure ===\n"
3+
export BASEDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
4+
5+
azure group get -n $groupName
6+
if [ $? -ne 0 ]; then
7+
printf "\n Creating group %s in location %s \n" $groupName $location
8+
azure group create -n "$groupName" --location "$location"
9+
fi
10+
11+
set -e
12+
accountName=`randomName $groupName`
13+
accountType="Standard_GRS"
14+
15+
printf "\n1. Creating storage account %s in resrouce group %s with type %s in location %s \n" $accountName $groupName $accountType $location
16+
azure storage account new -g "$groupName" -n "$accountName" -t "$accountType" -l "$location"
17+
18+
printf "\n2. Get account info of storage account %s in group %s\n" $accountName $groupName
19+
azure storage account get -g $groupName -n $accountName > $BASEDIR/$accountName.json
20+
[ $(cat $BASEDIR/$accountName.json | jq '.ResourceGroupName' --raw-output) == "$groupName" ]
21+
[ $(cat $BASEDIR/$accountName.json | jq '.StorageAccountName' --raw-output) == "$accountName" ]
22+
[ $(cat $BASEDIR/$accountName.json | jq '.AccountType' --raw-output) == "$accountType" ]
23+
[ $(cat $BASEDIR/$accountName.json | jq '.Location' --raw-output) == "$location" ]
24+
rm -f $BASEDIR/$accountName.json
25+
26+
accountType1="Standard_RAGRS"
27+
printf "\n3. Set account type from %s to %s of storage account %s in group %s\n" $accountType $accountType1 $accountName $groupName
28+
azure storage account set -g $groupName -n $accountName -t "$accountType1" > $BASEDIR/$accountName.json
29+
[ $(cat $BASEDIR/$accountName.json | jq '.AccountType' --raw-output) == "$accountType1" ]
30+
rm -f $BASEDIR/$accountName.json
31+
32+
printf "\n4. Get account key of storage account %s in group %s\n" $accountName $groupName
33+
azure storage account key get -g $groupName -n $accountName > $BASEDIR/$accountName.json
34+
key1=$(cat $BASEDIR/$accountName.json | jq '.key1' --raw-output)
35+
key2=$(cat $BASEDIR/$accountName.json | jq '.key2' --raw-output)
36+
[ $key1 != $key2 ]
37+
rm -f $BASEDIR/$accountName.json
38+
39+
printf "\n5. Renew account key1 of storage account %s in group %s\n" $accountName $groupName
40+
azure storage account key new -g $groupName -n $accountName -k "key1"
41+
azure storage account key get -g $groupName -n $accountName > $BASEDIR/$accountName.json
42+
[ $(cat $BASEDIR/$accountName.json | jq '.key1' --raw-output) != $key1 ]
43+
rm -f $BASEDIR/$accountName.json
44+
45+
printf "\n6. Renew account key2 of storage account %s in group %s\n" $accountName $groupName
46+
azure storage account key new -g $groupName -n $accountName -k "key2"
47+
azure storage account key get -g $groupName -n $accountName > $BASEDIR/$accountName.json
48+
[ $(cat $BASEDIR/$accountName.json | jq '.key2' --raw-output) != $key2 ]
49+
rm -f $BASEDIR/$accountName.json
50+
51+
printf "\n7. Removing account %s in group %s\n" $accountName $groupName
52+
azure storage account remove -g $groupName -n $accountName

src/CLU/Commands.Common/AzurePSCmdlet.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
using Microsoft.Azure.Commands.Common.Authentication.Factories;
3232
using Microsoft.ApplicationInsights;
3333
using Microsoft.ApplicationInsights.Extensibility;
34+
using Microsoft.Rest;
3435

3536
namespace Microsoft.Azure.Commands.Utilities.Common
3637
{
@@ -309,6 +310,8 @@ protected override void BeginProcessing()
309310
ModuleName, string.Format("v{0}", ModuleVersion));
310311
ClientFactory.UserAgents.Add(userAgentValue);
311312
ClientFactory.AddHandler(new CmdletInfoHandler(this.CommandRuntime.ToString(), this.ParameterSetName, this._clientRequestId));
313+
ServiceClientTracing.AddTracingInterceptor(_adalListener);
314+
ServiceClientTracing.IsEnabled = true;
312315
base.BeginProcessing();
313316
}
314317

src/CLU/Commands.Common/DebugStreamTraceListener.cs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,19 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15+
using System;
1516
using System.Collections.Concurrent;
17+
using System.Collections.Generic;
1618
using System.Diagnostics;
19+
using System.Net.Http;
20+
using Microsoft.Azure.Commands.Common.Authentication;
21+
using Microsoft.Azure.Commands.Utilities.Common;
1722
using Microsoft.IdentityModel.Clients.ActiveDirectory;
23+
using Microsoft.Rest;
1824

1925
namespace Microsoft.Azure.Commands.Common
2026
{
21-
public class DebugStreamTraceListener : TraceListener
27+
public class DebugStreamTraceListener : TraceListener, IServiceClientTracingInterceptor
2228
{
2329
public DebugStreamTraceListener(ConcurrentQueue<string> queue)
2430
{
@@ -46,5 +52,40 @@ public static void RemoveAdalTracing(DebugStreamTraceListener listener)
4652
{
4753
//AdalTrace.TraceSource.Listeners.Remove(listener);
4854
}
55+
56+
public void Configuration(string source, string name, string value)
57+
{
58+
}
59+
60+
public void ExitMethod(string invocationId, object returnValue)
61+
{
62+
WriteLine($"{invocationId}: End method with return value {returnValue}");
63+
}
64+
65+
public void Information(string message)
66+
{
67+
}
68+
69+
public void TraceError(string invocationId, Exception exception)
70+
{
71+
WriteLine($"{invocationId}: Exception {exception}");
72+
}
73+
74+
public void SendRequest(string invocationId, HttpRequestMessage request)
75+
{
76+
WriteLine($"{invocationId} REQUEST:");
77+
WriteLine($"{GeneralUtilities.GetLog(request)}");
78+
}
79+
80+
public void ReceiveResponse(string invocationId, HttpResponseMessage response)
81+
{
82+
WriteLine($"{invocationId} RESPONSE:");
83+
WriteLine($"{GeneralUtilities.GetLog(response)}");
84+
}
85+
86+
public void EnterMethod(string invocationId, object instance, string method, IDictionary<string, object> parameters)
87+
{
88+
WriteLine($"{invocationId}: Start method {method} with return value");
89+
}
4990
}
5091
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<Configuration>
3+
<ViewDefinitions>
4+
<View>
5+
<Name>Microsoft.Azure.Commands.ResourceManager.Cmdlets.Models.PSResourceObject</Name>
6+
<ViewSelectedBy>
7+
<TypeName>Microsoft.Azure.Commands.ResourceManager.Cmdlets.Models.PSResourceObject</TypeName>
8+
</ViewSelectedBy>
9+
<ListControl>
10+
<ListEntries>
11+
<ListEntry>
12+
<ListItems>
13+
<ListItem>
14+
<Label>Name</Label>
15+
<PropertyName>Name</PropertyName>
16+
</ListItem>
17+
<ListItem>
18+
<Label>ResourceId</Label>
19+
<PropertyName>ResourceId</PropertyName>
20+
</ListItem>
21+
<ListItem>
22+
<Label>ResourceName</Label>
23+
<PropertyName>ResourceName</PropertyName>
24+
</ListItem>
25+
<ListItem>
26+
<Label>ResourceType</Label>
27+
<PropertyName>ResourceType</PropertyName>
28+
</ListItem>
29+
<ListItem>
30+
<Label>ResourceGroupName</Label>
31+
<PropertyName>ResourceGroupName</PropertyName>
32+
</ListItem>
33+
<ListItem>
34+
<Label>Location</Label>
35+
<PropertyName>Location</PropertyName>
36+
</ListItem>
37+
<ListItem>
38+
<Label>SubscriptionId</Label>
39+
<PropertyName>SubscriptionId</PropertyName>
40+
</ListItem>
41+
<ListItem>
42+
<Label>Properties</Label>
43+
<PropertyName>PropertiesText</PropertyName>
44+
</ListItem>
45+
</ListItems>
46+
</ListEntry>
47+
</ListEntries>
48+
</ListControl>
49+
</View>
50+
</ViewDefinitions>
51+
</Configuration>

src/CLU/Commands.ResourceManager.Cmdlets/Extensions/ResourceExtensions.cs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Extensions
1717
using Commands.Utilities.Common;
1818
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
1919
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Resources;
20+
using Models;
2021
using Newtonsoft.Json.Linq;
2122
using System.Collections.Generic;
2223
using System.Linq;
@@ -26,11 +27,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Extensions
2627
/// </summary>
2728
internal static class ResourceExtensions
2829
{
29-
/// <summary>
30-
/// Converts a <see cref="Resource{JToken}"/> object into a <see cref="PSObject"/> object.
31-
/// </summary>
32-
/// <param name="resource">The <see cref="Resource{JToken}"/> object.</param>
33-
internal static PSObject ToPsObject(this Resource<JToken> resource)
30+
internal static PSResourceObject ToPSResourceObject(this Resource<JToken> resource)
3431
{
3532
var resourceType = string.IsNullOrEmpty(resource.Id)
3633
? null
@@ -42,28 +39,34 @@ internal static PSObject ToPsObject(this Resource<JToken> resource)
4239

4340
var objectDefinition = new Dictionary<string, object>
4441
{
45-
{ "Name", resource.Name },
46-
{ "ResourceId", string.IsNullOrEmpty(resource.Id) ? null : resource.Id },
47-
{ "ResourceName", string.IsNullOrEmpty(resource.Id) ? null : ResourceIdUtility.GetResourceName(resource.Id) },
48-
{ "ResourceType", resourceType },
4942
{ "ExtensionResourceName", string.IsNullOrEmpty(resource.Id) ? null : ResourceIdUtility.GetExtensionResourceName(resource.Id) },
5043
{ "ExtensionResourceType", extensionResourceType },
5144
{ "Kind", resource.Kind },
52-
{ "ResourceGroupName", string.IsNullOrEmpty(resource.Id) ? null : ResourceIdUtility.GetResourceGroupName(resource.Id) },
53-
{ "Location", resource.Location },
54-
{ "SubscriptionId", string.IsNullOrEmpty(resource.Id) ? null : ResourceIdUtility.GetSubscriptionId(resource.Id) },
5545
{ "Tags", TagsHelper.GetTagsHashtables(resource.Tags) },
56-
{ "Plan", resource.Plan == null ? null : resource.Plan.ToJToken().ToPsObject() },
46+
{ "Plan", resource.Plan == null ? null : resource.Plan.ToJToken() },
5747
{ "Properties", ResourceExtensions.GetProperties(resource) },
5848
{ "CreatedTime", resource.CreatedTime },
5949
{ "ChangedTime", resource.ChangedTime },
6050
{ "ETag", resource.ETag },
61-
{ "Sku", resource.Sku == null ? null : resource.Sku.ToJToken().ToPsObject() },
51+
{ "Sku", resource.Sku == null ? null : resource.Sku.ToJToken() },
6252
};
6353

64-
var psObject =
65-
PowerShellUtilities.ConstructPSObject(
66-
objectDefinition.Where(kvp => kvp.Value != null).SelectManyArray(kvp => new[] { kvp.Key, kvp.Value }));
54+
var psObject = new PSResourceObject();
55+
psObject.Name = resource.Name;
56+
psObject.ResourceId = string.IsNullOrEmpty(resource.Id) ? null : resource.Id;
57+
psObject.ResourceName = string.IsNullOrEmpty(resource.Id) ? null : ResourceIdUtility.GetResourceName(resource.Id);
58+
psObject.ResourceType = resourceType;
59+
psObject.ResourceGroupName = string.IsNullOrEmpty(resource.Id) ? null : ResourceIdUtility.GetResourceGroupName(resource.Id);
60+
psObject.Location = resource.Location;
61+
psObject.SubscriptionId = string.IsNullOrEmpty(resource.Id) ? null : ResourceIdUtility.GetSubscriptionId(resource.Id);
62+
63+
64+
var objectProperties = objectDefinition.Where(kvp => kvp.Value != null).SelectManyArray(kvp => new[] { kvp.Key, kvp.Value });
65+
66+
for(int i=0; i< objectProperties.Length; i+=2)
67+
{
68+
psObject.Properties.Add(objectProperties[i].ToString(), objectProperties[i + 1].ToString());
69+
}
6770

6871
return psObject;
6972
}

src/CLU/Commands.ResourceManager.Cmdlets/Implementation/GetAzureResourceGroupDeploymentOperationCmdlet.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
2121
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Resources;
2222
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Extensions;
2323
using Newtonsoft.Json.Linq;
24-
24+
using Models;
2525
/// <summary>
2626
/// Gets the deployment operation.
2727
/// </summary>
28-
[Cmdlet(VerbsCommon.Get, "AzureRmResourceGroupDeploymentOperation"), OutputType(typeof(Resource<JToken>))]
28+
[Cmdlet(VerbsCommon.Get, "AzureRmResourceGroupDeploymentOperation"), OutputType(typeof(PSResourceObject))]
2929
public class GetAzureResourceGroupDeploymentOperationCmdlet : ResourceManagerCmdletBase
3030
{
3131
/// <summary>
@@ -81,7 +81,9 @@ private void RunCmdlet()
8181
getFirstPage: () => this.GetResources(),
8282
getNextPage: nextLink => this.GetNextLink<JObject>(nextLink),
8383
cancellationToken: this.CancellationToken,
84-
action: resources => this.WriteObject(sendToPipeline: resources.CoalesceEnumerable().SelectArray(resource => resource.ToResource()), enumerateCollection: true));
84+
action: resources => this.WriteObject(sendToPipeline: resources.CoalesceEnumerable()
85+
.SelectArray(resource => resource.ToResource().ToPSResourceObject()),
86+
enumerateCollection: true));
8587
}
8688

8789
/// <summary>

src/CLU/Commands.ResourceManager.Cmdlets/Implementation/InvokeAzureResourceActionCmdlet.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
1919
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Extensions;
2020
using Newtonsoft.Json.Linq;
2121
using Commands.Common;
22+
using Models;
23+
2224
/// <summary>
2325
/// A cmdlet that invokes a resource action.
2426
/// </summary>
25-
[Cmdlet(VerbsLifecycle.Invoke, "AzureRmResourceAction", SupportsShouldProcess = true, DefaultParameterSetName = ResourceManipulationCmdletBase.ResourceIdParameterSet), OutputType(typeof(PSObject))]
27+
[Cmdlet(VerbsLifecycle.Invoke, "AzureRmResourceAction", SupportsShouldProcess = true, DefaultParameterSetName = ResourceManipulationCmdletBase.ResourceIdParameterSet),
28+
OutputType(typeof(PSResourceObject))]
2629
public sealed class InvokAzureResourceActionCmdlet : ResourceManipulationCmdletBase
2730
{
2831
/// <summary>

src/CLU/Commands.ResourceManager.Cmdlets/Implementation/Resource/FindAzureResourceCmdlet.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
2525
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Resources;
2626
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Extensions;
2727
using Newtonsoft.Json.Linq;
28+
using Models;
2829

2930
/// <summary>
3031
/// Cmdlet to get existing resources from ARM cache.
3132
/// </summary>
32-
[Cmdlet(VerbsCommon.Find, "AzureRmResource", DefaultParameterSetName = FindAzureResourceCmdlet.ListResourcesParameterSet), OutputType(typeof(Resource<JToken>))]
33+
[Cmdlet(VerbsCommon.Find, "AzureRmResource", DefaultParameterSetName = FindAzureResourceCmdlet.ListResourcesParameterSet), OutputType(typeof(PSResourceObject))]
3334
public sealed class FindAzureResourceCmdlet : ResourceManagerCmdletBase
3435
{
3536
/// <summary>
@@ -191,14 +192,14 @@ private void RunCmdlet()
191192
items = this.GetPopulatedResource(batch).Result;
192193
}
193194

194-
var powerShellObjects = items.SelectArray(genericResource => genericResource);
195+
var powerShellObjects = items.SelectArray(genericResource => genericResource.ToPSResourceObject());
195196

196197
this.WriteObject(sendToPipeline: powerShellObjects, enumerateCollection: true);
197198
}
198199
}
199200
else
200201
{
201-
this.WriteObject(sendToPipeline: resources.CoalesceEnumerable().SelectArray(res => res.ToResource()), enumerateCollection: true);
202+
this.WriteObject(sendToPipeline: resources.CoalesceEnumerable().SelectArray(res => res.ToResource().ToPSResourceObject()), enumerateCollection: true);
202203
}
203204
});
204205

src/CLU/Commands.ResourceManager.Cmdlets/Implementation/Resource/GetAzureResourceCmdlet.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
2525
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Resources;
2626
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Extensions;
2727
using Newtonsoft.Json.Linq;
28+
using Models;
2829

2930
/// <summary>
3031
/// Cmdlet to get existing resources.
3132
/// </summary>
32-
[Cmdlet(VerbsCommon.Get, "AzureRmResource", DefaultParameterSetName = GetAzureResourceCmdlet.ParameterlessSet), OutputType(typeof(Resource<JToken>))]
33+
[Cmdlet(VerbsCommon.Get, "AzureRmResource", DefaultParameterSetName = GetAzureResourceCmdlet.ParameterlessSet), OutputType(typeof(PSResourceObject))]
3334
public sealed class GetAzureResourceCmdlet : ResourceManagerCmdletBase
3435
{
3536
/// <summary>
@@ -228,14 +229,14 @@ private void RunCmdlet()
228229
items = this.GetPopulatedResource(batch).Result;
229230
}
230231

231-
var powerShellObjects = items.SelectArray(genericResource => genericResource);
232+
var powerShellObjects = items.SelectArray(genericResource => genericResource.ToPSResourceObject());
232233

233234
this.WriteObject(sendToPipeline: powerShellObjects, enumerateCollection: true);
234235
}
235236
}
236237
else
237238
{
238-
this.WriteObject(sendToPipeline: resources.CoalesceEnumerable().SelectArray(res => res.ToResource()), enumerateCollection: true);
239+
this.WriteObject(sendToPipeline: resources.CoalesceEnumerable().SelectArray(res => res.ToResource().ToPSResourceObject()), enumerateCollection: true);
239240
}
240241
});
241242

0 commit comments

Comments
 (0)