Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
2ca81d9
move mgmt test classes into mgmt
ArcturusZhang Oct 10, 2024
2c3d949
some in progress changes
ArcturusZhang Oct 11, 2024
30fe506
wip, now the new provider could generate those methods
ArcturusZhang Oct 11, 2024
1553bc9
Merge branch 'main' into refactor-mgmt-sample-generator
ArcturusZhang Oct 11, 2024
066cd2d
follow up
ArcturusZhang Oct 11, 2024
3a03f71
Merge branch 'main' into refactor-mgmt-sample-generator
ArcturusZhang Oct 14, 2024
6f25ddb
a few progress on creating id for a resource
ArcturusZhang Oct 14, 2024
d0d5df2
a few update
ArcturusZhang Oct 14, 2024
d209e5a
add get resource statement
ArcturusZhang Oct 14, 2024
1ac3fe2
add implementation for normal operations
ArcturusZhang Oct 16, 2024
36685a3
implmeent some bodies
ArcturusZhang Oct 16, 2024
834618d
Merge branch 'main' into refactor-mgmt-sample-generator
ArcturusZhang Oct 16, 2024
ad43b46
Merge remote-tracking branch 'origin/main' into refactor-mgmt-sample-…
ArcturusZhang Oct 17, 2024
403e9ab
Merge remote-tracking branch 'origin/main' into refactor-mgmt-sample-…
ArcturusZhang Oct 17, 2024
77d3ebf
some more progress
ArcturusZhang Oct 17, 2024
ce40019
Merge remote-tracking branch 'origin/main' into refactor-mgmt-sample-…
ArcturusZhang Oct 21, 2024
64824ce
fix the scope issue
ArcturusZhang Oct 21, 2024
33bfeca
fix another scope path issue
ArcturusZhang Oct 21, 2024
f88e7c1
enable generation for collections
ArcturusZhang Oct 21, 2024
e0efd6e
implement part of the resource collection methods
ArcturusZhang Oct 21, 2024
fdeb1b0
fix inline parameter issue
ArcturusZhang Oct 21, 2024
ee9c3d8
some updates with issues
ArcturusZhang Oct 21, 2024
123c66c
fix the scope issue
ArcturusZhang Oct 22, 2024
12efc8e
fix isuses in mgmttestconfiguration
ArcturusZhang Oct 23, 2024
f1273f0
fix casing and empty lines
ArcturusZhang Oct 23, 2024
4576226
Merge branch 'main' into refactor-mgmt-sample-generator
ArcturusZhang Oct 31, 2024
9cfffd1
Merge branch 'main' into refactor-mgmt-sample-generator
ArcturusZhang Oct 31, 2024
48f7f2f
honor the skipped operation config
ArcturusZhang Oct 31, 2024
3894a9b
regen
ArcturusZhang Nov 4, 2024
2cf792d
regen
ArcturusZhang Nov 4, 2024
2931a53
implement the extension operation samples
ArcturusZhang Nov 4, 2024
010f4cf
implement the property bag part 1
ArcturusZhang Nov 5, 2024
8468e13
implement the property bag part 2
ArcturusZhang Nov 5, 2024
600b4d0
remove the configureawait part
ArcturusZhang Nov 5, 2024
d1d9e0d
fix the null value issue in code model converter
ArcturusZhang Nov 5, 2024
e65f290
fix a case in resourcemanager
ArcturusZhang Nov 5, 2024
f5c2441
fix some issues found in real rps
ArcturusZhang Nov 5, 2024
e17b225
find another case that has configureawait
ArcturusZhang Nov 5, 2024
7936159
remove useless code
ArcturusZhang Nov 5, 2024
7461fff
more removals
ArcturusZhang Nov 5, 2024
c032d67
adjust namespaces
ArcturusZhang Nov 5, 2024
441dde0
clean up
ArcturusZhang Nov 5, 2024
c323542
Merge branch 'main' into refactor-mgmt-sample-generator
ArcturusZhang Nov 6, 2024
c5704f9
refactor
ArcturusZhang Nov 6, 2024
fbf2968
more refactor
ArcturusZhang Nov 6, 2024
bf49918
regen
ArcturusZhang Nov 6, 2024
ad7549e
Merge remote-tracking branch 'origin/main' into refactor-mgmt-sample-…
ArcturusZhang Nov 11, 2024
9d7e62c
fix some more issues
ArcturusZhang Nov 11, 2024
97762f3
Merge remote-tracking branch 'origin/main' into refactor-mgmt-sample-…
ArcturusZhang Nov 12, 2024
855d575
fix userassignedidentity
ArcturusZhang Nov 12, 2024
8180473
add some notes
ArcturusZhang Nov 12, 2024
5027003
fix the optional parameter issue and regen
ArcturusZhang Nov 13, 2024
f1210ae
Merge branch 'main' into refactor-mgmt-sample-generator
ArcturusZhang Nov 13, 2024
9ce9211
Merge branch 'main' into refactor-mgmt-sample-generator
ArcturusZhang Nov 15, 2024
75098c2
Merge branch 'main' into refactor-mgmt-sample-generator
ArcturusZhang Nov 21, 2024
c36dc84
fix the armclient issue
ArcturusZhang Nov 21, 2024
642a3bd
fix some minor issues in code
ArcturusZhang Nov 21, 2024
0754dde
regen
ArcturusZhang Nov 21, 2024
0e8aac7
resolve comments
ArcturusZhang Nov 22, 2024
f861682
refine
ArcturusZhang Nov 22, 2024
1f13f5b
Merge branch 'main' into refactor-mgmt-sample-generator
ArcturusZhang Nov 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix the scope issue
  • Loading branch information
ArcturusZhang committed Oct 22, 2024
commit 123c66cb86ce7e36f26d88be577c0aa439ca0d51
1 change: 1 addition & 0 deletions src/AutoRest.CSharp/Mgmt/AutoRest/MgmtConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ internal void SaveConfiguration(Utf8JsonWriter writer)
WriteNonEmptySettings(writer, nameof(PrivilegedOperations), PrivilegedOperations);
WriteNonEmptySettings(writer, nameof(OverrideOperationName), OverrideOperationName);
WriteNonEmptySettings(writer, nameof(PartialResources), PartialResources);
WriteNonEmptySettings(writer, nameof(RawParameterizedScopes), RawParameterizedScopes);
MgmtDebug.Write(writer, nameof(MgmtDebug));
if (IsArmCore)
writer.WriteBoolean("ArmCore", IsArmCore);
Expand Down
37 changes: 32 additions & 5 deletions src/AutoRest.CSharp/Mgmt/Output/Samples/NewMgmtSampleProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -371,10 +371,9 @@ private MethodBodyStatement BuildGetCollectionStatement(ResourceCollection colle
if (parent is MgmtExtension extension && extension.ArmCoreType == typeof(ArmResource))
{
statements.Add(
// TODO -- find out the scope parameter
BuildCreateResourceIdentifierForScopePath(example, collection.RequestPath.GetScopePath(), parent.Type, out var scope)
BuildCreateScopeResourceIdentifier(example, example.RequestPath.GetScopePath(), out var scopeId)
);
arguments.Add(scope);
arguments.Add(New.Instance(typeof(ResourceIdentifier), scopeId));
}

foreach (var extraParameter in collection.ExtraConstructorParameters)
Expand Down Expand Up @@ -518,6 +517,35 @@ private MethodBodyStatement BuildCreateResourceIdentifierForUsualPath(OperationE
return statements;
}

private MethodBodyStatement BuildCreateScopeResourceIdentifier(OperationExample example, RequestPath operationScopePath, out TypedValueExpression scopeId)
{
var statements = new List<MethodBodyStatement>();
var scopeValues = new List<TypedValueExpression>();
foreach (var reference in operationScopePath.Where(segment => segment.IsReference))
{
var exampleValue = example.FindInputExampleValueFromReference(reference.Reference);
var scopeRefStatement = Declare(reference.Type, reference.ReferenceName, ExampleValueSnippets.GetExpression(reference.Type, exampleValue), out var scopeRefVar);
statements.Add(scopeRefStatement);
scopeValues.Add(scopeRefVar);
}

if (operationScopePath.Count == 1)
{
// the scope in the id is an explicit scope, such as a request path defined like: `/{scope}/providers/Microsoft.Something/roleDefinitions/{name}` therefore we do not have do anything special for it
//idArguments.AddRange(scopeValues);
scopeId = scopeValues[0];
}
else
{
// this scope is an implicit scope, such as a request path defined like: `/subscriptions/{subsId}/providers/Microsoft.Something/roleDefinitions/{name}` but we changed this in our generator to make it a scope resource
var scopeDeclarationStatement = Declare(typeof(string), "scope", new FormattableStringExpression(operationScopePath, scopeValues), out var scope);
statements.Add(scopeDeclarationStatement);
scopeId = scope;
}

return statements;
}

private MethodBodyStatement BuildCreateResourceIdentifierForScopePath(OperationExample example, RequestPath resourcePath, CSharpType typeOfResource, out TypedValueExpression id)
{
var statements = new List<MethodBodyStatement>();
Expand All @@ -544,8 +572,7 @@ private MethodBodyStatement BuildCreateResourceIdentifierForScopePath(OperationE
else
{
// this scope is an implicit scope, such as a request path defined like: `/subscriptions/{subsId}/providers/Microsoft.Something/roleDefinitions/{name}` but we changed this in our generator to make it a scope resource
var scopeSegment = resourceScopePath[0];
var scopeDeclarationStatement = Declare(scopeSegment.Reference.Type, scopeSegment.ReferenceName, new FormattableStringExpression(operationScopePath, scopeValues), out var scope);
var scopeDeclarationStatement = Declare(typeof(string), "scope", new FormattableStringExpression(operationScopePath, scopeValues), out var scope);
statements.Add(scopeDeclarationStatement);
idArguments.Add(scope);
}
Expand Down
37 changes: 27 additions & 10 deletions src/AutoRest.CSharp/MgmtTest/AutoRest/MgmtTestConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ internal class MgmtTestConfiguration
public MgmtTestConfiguration(
IReadOnlyList<string> skippedOperations,
JsonElement? sourceCodePath = default,
JsonElement? mock = default,
JsonElement? sample = default,
JsonElement? outputFolder = default,
JsonElement? clearOutputFolder = default)
Expand All @@ -43,11 +42,11 @@ public MgmtTestConfiguration(
if (testGenRoot.ValueKind != JsonValueKind.Object)
return null;

testGenRoot.TryGetProperty(nameof(SkippedOperations), out var skippedOperationsElement);
testGenRoot.TryGetProperty(nameof(SourceCodePath), out var sourceCodePath);
testGenRoot.TryGetProperty(nameof(Sample), out var sample);
testGenRoot.TryGetProperty(nameof(OutputFolder), out var testGenOutputFolder);
testGenRoot.TryGetProperty(nameof(ClearOutputFolder), out var testGenClearOutputFolder);
testGenRoot.TryGetProperty(Options.SkippedOperations, out var skippedOperationsElement);
testGenRoot.TryGetProperty(Options.SourcePath, out var sourceCodePath);
testGenRoot.TryGetProperty(Options.Sample, out var sample);
testGenRoot.TryGetProperty(Options.OutputFolder, out var testGenOutputFolder);
testGenRoot.TryGetProperty(Options.ClearOutputFolder, out var testGenClearOutputFolder);

var skippedOperations = Configuration.DeserializeArray(skippedOperationsElement);

Expand All @@ -67,23 +66,41 @@ public MgmtTestConfiguration(
return new MgmtTestConfiguration(
skippedOperations: autoRest.GetValue<string[]?>(string.Format(TestGenOptionsFormat, "skipped-operations")).GetAwaiter().GetResult() ?? Array.Empty<string>(),
sourceCodePath: autoRest.GetValue<JsonElement?>(string.Format(TestGenOptionsFormat, "source-path")).GetAwaiter().GetResult(),
mock: autoRest.GetValue<JsonElement?>(string.Format(TestGenOptionsFormat, "mock")).GetAwaiter().GetResult(),
sample: autoRest.GetValue<JsonElement?>(string.Format(TestGenOptionsFormat, "sample")).GetAwaiter().GetResult(),
outputFolder: autoRest.GetValue<JsonElement?>(string.Format(TestGenOptionsFormat, "output-folder")).GetAwaiter().GetResult(),
clearOutputFolder: autoRest.GetValue<JsonElement?>(string.Format(TestGenOptionsFormat, "clear-output-folder")).GetAwaiter().GetResult());
}

private static class Options
{
internal const string SkippedOperations = "skipped-operations";

internal const string SourcePath = "source-path";

internal const string Sample = "sample";

internal const string OutputFolder = "output-folder";

internal const string ClearOutputFolder = "clear-output-folder";
}

internal void SaveConfiguration(Utf8JsonWriter writer)
{
writer.WriteStartObject(TestGenOptionsRoot);

WriteNonEmptySettings(writer, nameof(SkippedOperations), SkippedOperations);
WriteNonEmptySettings(writer, Options.SkippedOperations, SkippedOperations);

if (SourceCodePath is not null)
writer.WriteString(nameof(SourceCodePath), SourceCodePath);
writer.WriteString(Options.SourcePath, SourceCodePath);

if (Sample)
writer.WriteBoolean(nameof(Sample), Sample);
writer.WriteBoolean(Options.Sample, Sample);

if (OutputFolder is not null)
writer.WriteString(Options.OutputFolder, OutputFolder);

if (!ClearOutputFolder)
writer.WriteBoolean(Options.ClearOutputFolder, ClearOutputFolder);

writer.WriteEndObject();
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion test/TestProjects/MgmtMockAndSample/src/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ modelerfour:

include-x-ms-examples-original-file: false
sample-gen:
mock: true
sample: true
output-folder: $(this-folder)../tests/Generated
clear-output-folder: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ public async Task CreateOrUpdate_CreateOrUpdateGuestConfigurationAssignment()
ArmClient client = new ArmClient(cred);

// get the collection of this GuestConfigurationAssignmentResource
GuestConfigurationAssignmentCollection collection = client.GetGuestConfigurationAssignments();
string subscriptionId = "mySubscriptionId";
string resourceGroupName = "myResourceGroupName";
string vmName = "myVMName";
string scope = $"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}";
GuestConfigurationAssignmentCollection collection = client.GetGuestConfigurationAssignments(new ResourceIdentifier(scope));

// invoke the operation
string guestConfigurationAssignmentName = "NotInstalledApplicationForWindows";
Expand Down Expand Up @@ -67,7 +71,11 @@ public async Task Get_GetAGuestConfigurationAssignment()
ArmClient client = new ArmClient(cred);

// get the collection of this GuestConfigurationAssignmentResource
GuestConfigurationAssignmentCollection collection = client.GetGuestConfigurationAssignments();
string subscriptionId = "mySubscriptionId";
string resourceGroupName = "myResourceGroupName";
string vmName = "myVMName";
string scope = $"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}";
GuestConfigurationAssignmentCollection collection = client.GetGuestConfigurationAssignments(new ResourceIdentifier(scope));

// invoke the operation
string guestConfigurationAssignmentName = "SecureProtocol";
Expand All @@ -93,7 +101,11 @@ public async Task GetAll_ListAllGuestConfigurationAssignmentsForAVirtualMachine(
ArmClient client = new ArmClient(cred);

// get the collection of this GuestConfigurationAssignmentResource
GuestConfigurationAssignmentCollection collection = client.GetGuestConfigurationAssignments();
string subscriptionId = "mySubscriptionId";
string resourceGroupName = "myResourceGroupName";
string vmName = "myVMName";
string scope = $"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}";
GuestConfigurationAssignmentCollection collection = client.GetGuestConfigurationAssignments(new ResourceIdentifier(scope));

// invoke the operation and iterate over the result
await foreach (GuestConfigurationAssignmentResource item in collection.GetAllAsync())
Expand Down Expand Up @@ -121,7 +133,11 @@ public async Task Exists_GetAGuestConfigurationAssignment()
ArmClient client = new ArmClient(cred);

// get the collection of this GuestConfigurationAssignmentResource
GuestConfigurationAssignmentCollection collection = client.GetGuestConfigurationAssignments();
string subscriptionId = "mySubscriptionId";
string resourceGroupName = "myResourceGroupName";
string vmName = "myVMName";
string scope = $"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}";
GuestConfigurationAssignmentCollection collection = client.GetGuestConfigurationAssignments(new ResourceIdentifier(scope));

// invoke the operation
string guestConfigurationAssignmentName = "SecureProtocol";
Expand All @@ -143,7 +159,11 @@ public async Task GetIfExists_GetAGuestConfigurationAssignment()
ArmClient client = new ArmClient(cred);

// get the collection of this GuestConfigurationAssignmentResource
GuestConfigurationAssignmentCollection collection = client.GetGuestConfigurationAssignments();
string subscriptionId = "mySubscriptionId";
string resourceGroupName = "myResourceGroupName";
string vmName = "myVMName";
string scope = $"/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}";
GuestConfigurationAssignmentCollection collection = client.GetGuestConfigurationAssignments(new ResourceIdentifier(scope));

// invoke the operation
string guestConfigurationAssignmentName = "SecureProtocol";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public async Task CreateOrUpdate_CreateRoleAssignment()
ArmClient client = new ArmClient(cred);

// get the collection of this RoleAssignmentResource
RoleAssignmentCollection collection = client.GetRoleAssignments();
string scope = "scope";
RoleAssignmentCollection collection = client.GetRoleAssignments(new ResourceIdentifier(scope));

// invoke the operation
string roleAssignmentName = "roleAssignmentName";
Expand Down Expand Up @@ -64,7 +65,8 @@ public async Task Get_GetRoleAssignmentByName()
ArmClient client = new ArmClient(cred);

// get the collection of this RoleAssignmentResource
RoleAssignmentCollection collection = client.GetRoleAssignments();
string scope = "scope";
RoleAssignmentCollection collection = client.GetRoleAssignments(new ResourceIdentifier(scope));

// invoke the operation
string roleAssignmentName = "roleAssignmentName";
Expand All @@ -90,7 +92,8 @@ public async Task GetAll_ListRoleAssignmentsForScope()
ArmClient client = new ArmClient(cred);

// get the collection of this RoleAssignmentResource
RoleAssignmentCollection collection = client.GetRoleAssignments();
string scope = "scope";
RoleAssignmentCollection collection = client.GetRoleAssignments(new ResourceIdentifier(scope));

// invoke the operation and iterate over the result
await foreach (RoleAssignmentResource item in collection.GetAllAsync())
Expand Down Expand Up @@ -118,7 +121,8 @@ public async Task Exists_GetRoleAssignmentByName()
ArmClient client = new ArmClient(cred);

// get the collection of this RoleAssignmentResource
RoleAssignmentCollection collection = client.GetRoleAssignments();
string scope = "scope";
RoleAssignmentCollection collection = client.GetRoleAssignments(new ResourceIdentifier(scope));

// invoke the operation
string roleAssignmentName = "roleAssignmentName";
Expand All @@ -140,7 +144,8 @@ public async Task GetIfExists_GetRoleAssignmentByName()
ArmClient client = new ArmClient(cred);

// get the collection of this RoleAssignmentResource
RoleAssignmentCollection collection = client.GetRoleAssignments();
string scope = "scope";
RoleAssignmentCollection collection = client.GetRoleAssignments(new ResourceIdentifier(scope));

// invoke the operation
string roleAssignmentName = "roleAssignmentName";
Expand Down