Skip to content

Commit aa35f44

Browse files
committed
Merge pull request #88 from Azure/dev
.
2 parents d7a961c + a0a0390 commit aa35f44

File tree

22 files changed

+1706
-969
lines changed

22 files changed

+1706
-969
lines changed

src/Common/AzurePSCmdlet.cs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using Newtonsoft.Json;
2525
using System.IO;
2626
using System.Management.Automation.Host;
27+
using System.Text;
2728
using System.Threading;
2829

2930
namespace Microsoft.WindowsAzure.Commands.Utilities.Common
@@ -39,6 +40,8 @@ public abstract class AzurePSCmdlet : PSCmdlet, IDisposable
3940

4041
private DebugStreamTraceListener _adalListener;
4142
protected static AzurePSDataCollectionProfile _dataCollectionProfile = null;
43+
protected static string _errorRecordFolderPath = null;
44+
protected const string _fileTimeStampSuffixFormat = "yyyy-MM-dd-THH-mm-ss-fff";
4245

4346
protected AzurePSQoSEvent QosEvent;
4447

@@ -254,7 +257,7 @@ protected bool IsVerbose()
254257

255258
protected new void WriteError(ErrorRecord errorRecord)
256259
{
257-
FlushDebugMessages();
260+
FlushDebugMessages(IsDataCollectionAllowed());
258261
if (QosEvent != null && errorRecord != null)
259262
{
260263
QosEvent.Exception = errorRecord.Exception;
@@ -362,8 +365,13 @@ protected void SafeWriteOutputPSObject(string typeName, params object[] args)
362365
WriteObject(customObject);
363366
}
364367

365-
private void FlushDebugMessages()
368+
private void FlushDebugMessages(bool record = false)
366369
{
370+
if (record)
371+
{
372+
RecordDebugMessages();
373+
}
374+
367375
string message;
368376
while (_debugMessages.TryDequeue(out message))
369377
{
@@ -373,6 +381,43 @@ private void FlushDebugMessages()
373381

374382
protected abstract void InitializeQosEvent();
375383

384+
private void RecordDebugMessages()
385+
{
386+
// Create 'ErrorRecords' folder under profile directory, if not exists
387+
if (string.IsNullOrEmpty(_errorRecordFolderPath) || !Directory.Exists(_errorRecordFolderPath))
388+
{
389+
_errorRecordFolderPath = Path.Combine(AzureSession.ProfileDirectory, "ErrorRecords");
390+
Directory.CreateDirectory(_errorRecordFolderPath);
391+
}
392+
393+
CommandInfo cmd = this.MyInvocation.MyCommand;
394+
395+
string filePrefix = cmd.Name;
396+
string timeSampSuffix = DateTime.Now.ToString(_fileTimeStampSuffixFormat);
397+
string fileName = filePrefix + "_" + timeSampSuffix + ".log";
398+
string filePath = Path.Combine(_errorRecordFolderPath, fileName);
399+
400+
StringBuilder sb = new StringBuilder();
401+
sb.Append("Module : ").AppendLine(cmd.ModuleName);
402+
sb.Append("Cmdlet : ").AppendLine(cmd.Name);
403+
404+
sb.AppendLine("Parameters");
405+
foreach (var item in this.MyInvocation.BoundParameters)
406+
{
407+
sb.Append(" -").Append(item.Key).Append(" : ");
408+
sb.AppendLine(item.Value == null ? "null" : item.Value.ToString());
409+
}
410+
411+
sb.AppendLine();
412+
413+
foreach (var content in _debugMessages)
414+
{
415+
sb.AppendLine(content);
416+
}
417+
418+
AzureSession.DataStore.WriteFile(filePath, sb.ToString());
419+
}
420+
376421
/// <summary>
377422
/// Invoke this method when the cmdlet is completed or terminated.
378423
/// </summary>

src/Common/Commands.ScenarioTest/Commands.ScenarioTest.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@
203203
<None Include="Resources\CredentialTests\Common.ps1">
204204
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
205205
</None>
206+
<None Include="Resources\ServiceManagement\Files\LongRoleName.Cloud.cscfg">
207+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
208+
</None>
209+
<None Include="Resources\ServiceManagement\Files\LongRoleName.Cloud.cspkg">
210+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
211+
</None>
206212
<None Include="Resources\ServiceManagement\Files\OneWebOneWorker.cscfg">
207213
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
208214
</None>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
**********************************************************************************************
4+
5+
This file was generated by a tool from the project file: ServiceConfiguration.Cloud.cscfg
6+
7+
Changes to this file may cause incorrect behavior and will be lost if the file is regenerated.
8+
9+
**********************************************************************************************
10+
-->
11+
<ServiceConfiguration serviceName="AzureCloudService2" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="4" osVersion="*" schemaVersion="2015-04.2.6">
12+
<Role name="WebRole1">
13+
<Instances count="1" />
14+
<ConfigurationSettings>
15+
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
16+
</ConfigurationSettings>
17+
</Role>
18+
<Role name="Microsoft.Contoso.Department.ProjectCodeName.Worker">
19+
<Instances count="1" />
20+
<ConfigurationSettings>
21+
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
22+
</ConfigurationSettings>
23+
</Role>
24+
</ServiceConfiguration>

src/Common/Commands.ScenarioTest/Resources/ServiceManagement/ServiceManagementTests.ps1

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -556,18 +556,20 @@ function Run-ServiceDeploymentExtensionCmdletTests
556556
$testMode = Get-ComputeTestMode;
557557
if ($testMode.ToLower() -ne 'playback')
558558
{
559-
$cspkg = '.\Resources\ServiceManagement\Files\OneWebOneWorker.cspkg';
559+
$cspkg = '.\Resources\ServiceManagement\Files\LongRoleName.Cloud.cspkg';
560560
}
561561
else
562562
{
563-
$cspkg = "https://${storageName}.blob.azure.windows.net/blob/OneWebOneWorker.cspkg";
563+
$cspkg = "https://${storageName}.blob.azure.windows.net/blob/LongRoleName.Cloud.cspkg";
564564
}
565-
$cscfg = '.\Resources\ServiceManagement\Files\OneWebOneWorker.cscfg';
566-
567-
$rdpCfg1 = New-AzureServiceRemoteDesktopExtensionConfig -Credential $credential -Role WebRole1
568-
$rdpCfg2 = New-AzureServiceRemoteDesktopExtensionConfig -Credential $credential -Role WorkerRole1;
569-
$adCfg1 = New-AzureServiceADDomainExtensionConfig -Role WebRole1 -WorkgroupName 'test1';
570-
$adCfg2 = New-AzureServiceADDomainExtensionConfig -Role WorkerRole1 -WorkgroupName 'test2';
565+
$cscfg = '.\Resources\ServiceManagement\Files\LongRoleName.Cloud.cscfg';
566+
567+
$webRoleShortName = "WebRole1";
568+
$workerRoleLongName = "Microsoft.Contoso.Department.ProjectCodeName.Worker";
569+
$rdpCfg1 = New-AzureServiceRemoteDesktopExtensionConfig -Credential $credential -Role $webRoleShortName
570+
$rdpCfg2 = New-AzureServiceRemoteDesktopExtensionConfig -Credential $credential -Role $workerRoleLongName;
571+
$adCfg1 = New-AzureServiceADDomainExtensionConfig -Role $webRoleShortName -WorkgroupName 'test1';
572+
$adCfg2 = New-AzureServiceADDomainExtensionConfig -Role $workerRoleLongName -WorkgroupName 'test2';
571573

572574
$st = New-AzureDeployment -ServiceName $svcName -Package $cspkg -Configuration $cscfg -Label $svcName -Slot Production -ExtensionConfiguration $rdpCfg1,$adCfg1;
573575
$exts = Get-AzureServiceExtension -ServiceName $svcName -Slot Production;

src/Common/Commands.ScenarioTest/SessionRecords/Microsoft.WindowsAzure.Commands.ScenarioTest.ServiceManagementTests/RunServiceDeploymentExtensionCmdletTests.json

Lines changed: 854 additions & 942 deletions
Large diffs are not rendered by default.

src/ResourceManager/ResourceManager/Commands.ResourceManager/Cmdlets/Commands.ResourceManager.Cmdlets.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@
111111
<Compile Include="Entities\Locks\LockLevel.cs" />
112112
<Compile Include="Entities\Locks\LockProperties.cs" />
113113
<Compile Include="Entities\Operations\AzureAsyncOperationResource.cs" />
114+
<Compile Include="Entities\Policy\PolicyDefinition.cs" />
115+
<Compile Include="Entities\Policy\PolicyDefinitionProperties.cs" />
116+
<Compile Include="Entities\Policy\PolicyRule.cs" />
114117
<Compile Include="Entities\Providers\ResourceProviderDefinition.cs" />
115118
<Compile Include="Entities\Providers\ResourceTypeDefinition.cs" />
116119
<Compile Include="Entities\ResourceGroup\ResourceBatchMoveParameters.cs" />
@@ -136,6 +139,11 @@
136139
<Compile Include="Implementation\InvokeAzureResourceActionCmdlet.cs" />
137140
<Compile Include="Implementation\MoveAzureResourceCmdlet.cs" />
138141
<Compile Include="Implementation\NewAzureResourceLockCmdlet.cs" />
142+
<Compile Include="Implementation\Policy\GetAzurePolicyDefinition.cs" />
143+
<Compile Include="Implementation\Policy\NewAzurePolicyDefinition.cs" />
144+
<Compile Include="Implementation\Policy\PolicyDefinitionCmdletBase.cs" />
145+
<Compile Include="Implementation\Policy\RemoveAzurePolicyDefinition.cs" />
146+
<Compile Include="Implementation\Policy\SetAzurePolicyDefinition.cs" />
139147
<Compile Include="Implementation\RemoveAzureResourceCmdlet.cs" />
140148
<Compile Include="Implementation\RemoveAzureResourceLockCmdlet.cs" />
141149
<Compile Include="Implementation\ResourceLockManagementCmdletBase.cs" />

src/ResourceManager/ResourceManager/Commands.ResourceManager/Cmdlets/Components/Constants.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ public static class Constants
2424
/// </summary>
2525
public static readonly string MicrosoftResourceNamesapce = "Microsoft.Resources";
2626

27+
/// <summary>
28+
/// The <c>Microsoft.Authorization</c> namespace.
29+
/// </summary>
30+
public static readonly string MicrosoftAuthorizationNamespace = "Microsoft.Authorization";
31+
2732
/// <summary>
2833
/// The string literal <c>ResourceGroups</c>
2934
/// </summary>
@@ -64,6 +69,11 @@ public static class Constants
6469
/// </summary>
6570
public static readonly string MicrosoftResourcesDeploymentOperationsType = Constants.MicrosoftResourceNamesapce + "/deployments/operations";
6671

72+
/// <summary>
73+
/// The policy definition resource type.
74+
/// </summary>
75+
public static readonly string MicrosoftAuthorizationPolicyDefinitionType = Constants.MicrosoftAuthorizationNamespace + "/policydefinitions";
76+
6777
/// <summary>
6878
/// The type name of the generic resource.
6979
/// </summary>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
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+
// ----------------------------------------------------------------------------------
14+
15+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Policy
16+
{
17+
using Newtonsoft.Json;
18+
19+
/// <summary>
20+
/// The policy definition object.
21+
/// </summary>
22+
public class PolicyDefinition
23+
{
24+
/// <summary>
25+
/// The policy definition properties.
26+
/// </summary>
27+
[JsonProperty(Required = Required.Default)]
28+
public PolicyDefinitionProperties Properties { get; set; }
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
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+
// ----------------------------------------------------------------------------------
14+
15+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Policy
16+
{
17+
using Newtonsoft.Json;
18+
19+
/// <summary>
20+
/// The policy definition properties.
21+
/// </summary>
22+
public class PolicyDefinitionProperties
23+
{
24+
/// <summary>
25+
/// The description.
26+
/// </summary>
27+
[JsonProperty(Required = Required.Default)]
28+
public string Description { get; set; }
29+
30+
/// <summary>
31+
/// The display name.
32+
/// </summary>
33+
[JsonProperty(Required = Required.Default)]
34+
public string DisplayName { get; set; }
35+
36+
/// <summary>
37+
/// The policy rule.
38+
/// </summary>
39+
[JsonProperty(Required = Required.Always)]
40+
public PolicyRule PolicyRule { get; set; }
41+
}
42+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
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+
// ----------------------------------------------------------------------------------
14+
15+
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Policy
16+
{
17+
using Newtonsoft.Json;
18+
19+
/// <summary>
20+
/// The policy rule object.
21+
/// </summary>
22+
public class PolicyRule
23+
{
24+
/// <summary>
25+
/// The policy rule
26+
/// </summary>
27+
[JsonProperty(Required = Required.Always)]
28+
public string Rule { get; set; }
29+
}
30+
}

0 commit comments

Comments
 (0)