Skip to content

Commit aea524d

Browse files
authored
Merge pull request #577 from Azure/dev
huangpf PR: dev <- Azure:dev
2 parents ca98ab4 + f23d6c5 commit aea524d

File tree

5 files changed

+287
-123
lines changed

5 files changed

+287
-123
lines changed

src/ResourceManager/AzureBatch/BatchModelGenerator/Program.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,14 @@ private static void GenerateModel(string fileName, Type omType, string modelName
152152
CodeCompileUnit compileUnit = new CodeCompileUnit();
153153
CodeNamespace codeNamespace = new CodeNamespace(ModelNamespace);
154154
GenerateUsingDirectives(codeNamespace);
155-
CodeTypeDeclaration codeType = new CodeTypeDeclaration(modelName);
156-
codeType.IsClass = true;
157-
codeType.TypeAttributes = TypeAttributes.Public;
155+
156+
var codeType = new CodeTypeDeclaration(modelName)
157+
{
158+
IsClass = true,
159+
TypeAttributes = TypeAttributes.Public,
160+
IsPartial = true, // allows us to provide some custom behaviours
161+
};
162+
158163
codeNamespace.Types.Add(codeType);
159164
compileUnit.Namespaces.Add(codeNamespace);
160165

@@ -262,7 +267,7 @@ private static void AddConstructorWithCopiedParameters(CodeTypeDeclaration codeT
262267
CodeExpression[] codeArgumentReferences = new CodeExpression[parameters.Length];
263268
for (int i = 0; i < parameters.Length; i++)
264269
{
265-
bool isOmTypeArg= false;
270+
bool isOmTypeArg = false;
266271

267272
string paramType = parameters[i].ParameterType.FullName;
268273
if (OMtoPSClassMappings.ContainsKey(paramType))
@@ -296,7 +301,7 @@ private static void AddConstructorWithCopiedParameters(CodeTypeDeclaration codeT
296301
CodeAssignStatement omObjectAssignStatement = new CodeAssignStatement(new CodeVariableReferenceExpression(string.Format("{0}{1}", parameters[i].Name, "OmObject")), new CodeVariableReferenceExpression(string.Format("{0}.{1}", parameters[i].Name, OmObject)));
297302
CodeBinaryOperatorExpression nullCheck = new CodeBinaryOperatorExpression(omObjectArgumentReference, CodeBinaryOperatorType.IdentityInequality, new CodePrimitiveExpression(null));
298303

299-
// if the parameter is not null, use the omObject of the PS Wrapper class
304+
// if the parameter is not null, use the omObject of the PS Wrapper class
300305
constructor.Statements.Add(new CodeConditionStatement(nullCheck, omObjectAssignStatement));
301306

302307
passedInArg = string.Format("{0}{1}", parameters[i].Name, "OmObject");
@@ -311,7 +316,7 @@ private static void AddConstructorWithCopiedParameters(CodeTypeDeclaration codeT
311316
}
312317

313318
codeArgumentReferences[i] = new CodeArgumentReferenceExpression(passedInArg);
314-
constructor.Parameters.Add(new CodeParameterDeclarationExpression(paramType, paramName));
319+
constructor.Parameters.Add(new CodeParameterDeclarationExpression(paramType, paramName));
315320
}
316321

317322
CodeObjectCreateExpression createExpression = new CodeObjectCreateExpression(implementationType, codeArgumentReferences);
@@ -338,7 +343,6 @@ private static void GenerateProperties(Type t, CodeTypeDeclaration codeType)
338343
(property.PropertyType.GetGenericTypeDefinition() == typeof(IList<>) || property.PropertyType.GetGenericTypeDefinition() == typeof(IEnumerable<>) ||
339344
property.PropertyType.GetGenericTypeDefinition() == typeof(IReadOnlyList<>));
340345

341-
342346
CodeFieldReferenceExpression wrappedObject = new CodeFieldReferenceExpression(new CodeThisReferenceExpression(), OmObject);
343347
CodePropertyReferenceExpression wrappedObjectProperty = new CodePropertyReferenceExpression(wrappedObject, property.Name);
344348
CodeFieldReferenceExpression fieldReference = null;
@@ -360,8 +364,8 @@ private static void GenerateProperties(Type t, CodeTypeDeclaration codeType)
360364
codeProperty.Name = property.Name;
361365
codeProperty.Type = new CodeTypeReference(propertyType);
362366

363-
// For properties with a backing field, the field will not be initialized in the constructor in order to avoid
364-
// hitting a run time access constraint from the OM. Instead, the field is initialized on the first access of
367+
// For properties with a backing field, the field will not be initialized in the constructor in order to avoid
368+
// hitting a run time access constraint from the OM. Instead, the field is initialized on the first access of
365369
// the property.
366370

367371
if (isGenericCollection)
@@ -404,7 +408,7 @@ private static void GenerateProperties(Type t, CodeTypeDeclaration codeType)
404408
CodeMethodInvokeExpression addToList = new CodeMethodInvokeExpression(listReference, "Add", createListItem);
405409
loopStatement.Statements.Add(addToList);
406410
}
407-
411+
408412
// Initialize the backing field with the built list on first access of the property
409413
CodeAssignStatement assignStatement;
410414
if (property.PropertyType.GetGenericTypeDefinition() == typeof(IReadOnlyList<>))

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Entities/Locks/LockLevel.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,13 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.Locks
2020
public enum LockLevel
2121
{
2222
/// <summary>
23-
/// The cannot delete lock.
23+
/// The lock blocks delete.
2424
/// </summary>
2525
CanNotDelete,
26+
27+
/// <summary>
28+
/// The lock blocks all updates and delete.
29+
/// </summary>
30+
ReadOnly
2631
}
2732
}

src/ResourceManager/Resources/Commands.ResourceManager/Cmdlets/Microsoft.Azure.Commands.ResourceManager.Cmdlets.dll-Help.xml

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2955,7 +2955,7 @@
29552955
<dev:version />
29562956
</command:details>
29572957
<maml:description>
2958-
<maml:para>Create a new resource lock. Resource Locks are useful to prevent accidental deletions of your azure resources. Once a lock is placed on a resource, it can't be deleted unless the lock is removed. </maml:para>
2958+
<maml:para>Create a new resource lock. Resource Lock is useful to prevent accidental deletion or update of your azure resource. Once a lock is placed on a resource, based on lock level it can't be deleted or updated unless the lock is removed. </maml:para>
29592959
<maml:para>If you find an issue with this cmdlet, please create an issue on https://github.com/Azure/azure-powershell/issues, with a lable "ResourceManager".</maml:para>
29602960
</maml:description>
29612961
<command:syntax>
@@ -2964,7 +2964,9 @@
29642964
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named">
29652965
<maml:name>LockLevel</maml:name>
29662966
<maml:description>
2967-
<maml:para>The level of the lock. The currently supported lock level is "CannotDelete". When this level is set on a resource, that resource cannont be deleted unless the lock is removed. </maml:para>
2967+
<maml:para>The level of the lock. The currently supported lock levels are "CannotDelete" and "ReadOnly". </maml:para>
2968+
<maml:para>CannotDelete - When this level is set on a resource, that resource cannot be deleted unless the lock is removed.</maml:para>
2969+
<maml:para>ReadOnly - When this level is set on a resource, that resource cannot updated or deleted unless the lock is removed.</maml:para>
29682970
</maml:description>
29692971
<command:parameterValue required="true" variableLength="false">LockLevel</command:parameterValue>
29702972
</command:parameter>
@@ -3058,7 +3060,9 @@
30583060
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named">
30593061
<maml:name>LockLevel</maml:name>
30603062
<maml:description>
3061-
<maml:para>The level of the lock. The currently supported lock level is "CannotDelete". When this level is set on a resource, that resource cannont be deleted unless the lock is removed. </maml:para>
3063+
<maml:para>The level of the lock. The currently supported lock levels are "CannotDelete" and "ReadOnly". </maml:para>
3064+
<maml:para>CannotDelete - When this level is set on a resource, that resource cannot be deleted unless the lock is removed.</maml:para>
3065+
<maml:para>ReadOnly - When this level is set on a resource, that resource cannot updated or deleted unless the lock is removed.</maml:para>
30623066
</maml:description>
30633067
<command:parameterValue required="true" variableLength="false">LockLevel</command:parameterValue>
30643068
</command:parameter>
@@ -3145,7 +3149,9 @@
31453149
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named">
31463150
<maml:name>LockLevel</maml:name>
31473151
<maml:description>
3148-
<maml:para>The level of the lock. The currently supported lock level is "CannotDelete". When this level is set on a resource, that resource cannont be deleted unless the lock is removed. </maml:para>
3152+
<maml:para>The level of the lock. The currently supported lock levels are "CannotDelete" and "ReadOnly". </maml:para>
3153+
<maml:para>CannotDelete - When this level is set on a resource, that resource cannot be deleted unless the lock is removed.</maml:para>
3154+
<maml:para>ReadOnly - When this level is set on a resource, that resource cannot updated or deleted unless the lock is removed.</maml:para>
31493155
</maml:description>
31503156
<command:parameterValue required="true" variableLength="false">LockLevel</command:parameterValue>
31513157
</command:parameter>
@@ -3246,7 +3252,9 @@
32463252
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named">
32473253
<maml:name>LockLevel</maml:name>
32483254
<maml:description>
3249-
<maml:para>The level of the lock. The currently supported lock level is "CannotDelete". When this level is set on a resource, that resource cannont be deleted unless the lock is removed. </maml:para>
3255+
<maml:para>The level of the lock. The currently supported lock levels are "CannotDelete" and "ReadOnly". </maml:para>
3256+
<maml:para>CannotDelete - When this level is set on a resource, that resource cannot be deleted unless the lock is removed.</maml:para>
3257+
<maml:para>ReadOnly - When this level is set on a resource, that resource cannot updated or deleted unless the lock is removed.</maml:para>
32503258
</maml:description>
32513259
<command:parameterValue required="true" variableLength="false">LockLevel</command:parameterValue>
32523260
</command:parameter>
@@ -3347,7 +3355,9 @@
33473355
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named">
33483356
<maml:name>LockLevel</maml:name>
33493357
<maml:description>
3350-
<maml:para>The level of the lock. The currently supported lock level is "CannotDelete". When this level is set on a resource, that resource cannont be deleted unless the lock is removed. </maml:para>
3358+
<maml:para>The level of the lock. The currently supported lock levels are "CannotDelete" and "ReadOnly". </maml:para>
3359+
<maml:para>CannotDelete - When this level is set on a resource, that resource cannot be deleted unless the lock is removed.</maml:para>
3360+
<maml:para>ReadOnly - When this level is set on a resource, that resource cannot updated or deleted unless the lock is removed.</maml:para>
33513361
</maml:description>
33523362
<command:parameterValue required="true" variableLength="false">LockLevel</command:parameterValue>
33533363
</command:parameter>
@@ -3427,7 +3437,9 @@
34273437
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named">
34283438
<maml:name>LockLevel</maml:name>
34293439
<maml:description>
3430-
<maml:para>The level of the lock. The currently supported lock level is "CannotDelete". When this level is set on a resource, that resource cannont be deleted unless the lock is removed.</maml:para>
3440+
<maml:para>The level of the lock. The currently supported lock levels are "CannotDelete" and "ReadOnly". </maml:para>
3441+
<maml:para>CannotDelete - When this level is set on a resource, that resource cannot be deleted unless the lock is removed.</maml:para>
3442+
<maml:para>ReadOnly - When this level is set on a resource, that resource cannot updated or deleted unless the lock is removed.</maml:para>
34313443
</maml:description>
34323444
<command:parameterValue required="true" variableLength="false">LockLevel</command:parameterValue>
34333445
</command:parameter>
@@ -3514,7 +3526,9 @@
35143526
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="false" position="named">
35153527
<maml:name>LockLevel</maml:name>
35163528
<maml:description>
3517-
<maml:para>TThe level of the lock. The currently supported lock level is "CannotDelete". When this level is set on a resource, that resource cannont be deleted unless the lock is removed. </maml:para>
3529+
<maml:para>The level of the lock. The currently supported lock levels are "CannotDelete" and "ReadOnly". </maml:para>
3530+
<maml:para>CannotDelete - When this level is set on a resource, that resource cannot be deleted unless the lock is removed.</maml:para>
3531+
<maml:para>ReadOnly - When this level is set on a resource, that resource cannot updated or deleted unless the lock is removed.</maml:para>
35183532
</maml:description>
35193533
<command:parameterValue required="true" variableLength="false">LockLevel</command:parameterValue>
35203534
<dev:type>

src/ResourceManager/Resources/Commands.Resources.Test/ScenarioTests/ResourceLockTests.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,13 @@ function Test-ResourceLockCRUD
4545
$removed = Remove-AzureRMResourceLock -ResourceId $actual.ResourceId -Force
4646
Assert-AreEqual True $removed
4747

48+
#ReadOnly lock
49+
$actual = New-AzureRMResourceLock -LockName $rname -LockLevel ReadOnly -Force -Scope $rg.ResourceId
50+
Assert-AreEqual $expected.Name $actual.Name
51+
52+
$expected = Get-AzureRMResourceLock -LockName $rname -Scope $rg.ResourceId
53+
Assert-AreEqual $expected.Properties.Level "ReadOnly"
54+
55+
$removed = Remove-AzureRMResourceLock -ResourceId $actual.ResourceId -Force
56+
Assert-AreEqual True $removed
4857
}

0 commit comments

Comments
 (0)