Skip to content

Commit 3ad7881

Browse files
authored
Add ResourceScope.ManagementGroup (#53638)
* Add ResourceScope.ManagementGroup * add test
1 parent e09183f commit 3ad7881

File tree

9 files changed

+207
-120
lines changed

9 files changed

+207
-120
lines changed

eng/packages/http-client-csharp-mgmt/emitter/src/resource-detection.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,8 @@ function getOperationScope(path: string): ResourceScope {
369369
return ResourceScope.ResourceGroup;
370370
} else if (path.startsWith("/subscriptions/{subscriptionId}/")) {
371371
return ResourceScope.Subscription;
372+
} else if (path.startsWith("/providers/Microsoft.Management/managementGroups/{managementGroupId}/")) {
373+
return ResourceScope.ManagementGroup;
372374
}
373375
return ResourceScope.Tenant; // all the templates work as if there is a tenant decorator when there is no such decorator
374376
}

eng/packages/http-client-csharp-mgmt/emitter/src/resource-metadata.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const ResourceGroupScopePrefix =
55
"/subscriptions/{subscriptionId}/resourceGroups";
66
const SubscriptionScopePrefix = "/subscriptions";
77
const TenantScopePrefix = "/tenants";
8+
const ManagementGroupScopePrefix = "/providers/Microsoft.Management/managementGroups";
89
const Providers = "/providers";
910

1011
export function calculateResourceTypeFromPath(path: string): string {
@@ -16,6 +17,8 @@ export function calculateResourceTypeFromPath(path: string): string {
1617
return "Microsoft.Resources/subscriptions";
1718
} else if (path.startsWith(TenantScopePrefix)) {
1819
return "Microsoft.Resources/tenants";
20+
} else if (path.startsWith(ManagementGroupScopePrefix)) {
21+
return "Microsoft.Resources/managementGroups";
1922
}
2023
throw `Path ${path} doesn't have resource type`;
2124
}
@@ -33,7 +36,8 @@ export function calculateResourceTypeFromPath(path: string): string {
3336
export enum ResourceScope {
3437
Tenant = "Tenant",
3538
Subscription = "Subscription",
36-
ResourceGroup = "ResourceGroup"
39+
ResourceGroup = "ResourceGroup",
40+
ManagementGroup = "ManagementGroup"
3741
}
3842

3943
export interface ResourceMetadata {

eng/packages/http-client-csharp-mgmt/emitter/test/resource-detection.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,4 +1147,55 @@ interface Employees {
11471147
);
11481148
ok(listByParentEntry);
11491149
});
1150+
1151+
it("resource scope as ManagementGroup", async () => {
1152+
const program = await typeSpecCompile(
1153+
`
1154+
/** An Employee resource */
1155+
model Employee is TrackedResource<EmployeeProperties> {
1156+
...ResourceNameParameter<Employee>;
1157+
}
1158+
1159+
/** Employee properties */
1160+
model EmployeeProperties {
1161+
/** Age of employee */
1162+
age?: int32;
1163+
1164+
/** City of employee */
1165+
city?: string;
1166+
}
1167+
1168+
interface Operations extends Azure.ResourceManager.Operations {}
1169+
1170+
@armResourceOperations
1171+
interface Employees {
1172+
get is Extension.Read<
1173+
Extension.ManagementGroup<"managementGroupId">,
1174+
Employee
1175+
>;
1176+
}
1177+
`,
1178+
runner
1179+
);
1180+
const context = createEmitterContext(program);
1181+
const sdkContext = await createCSharpSdkContext(context);
1182+
const root = createModel(sdkContext);
1183+
updateClients(root, sdkContext);
1184+
1185+
const employeeClient = getAllClients(root).find((c) => c.name === "Employees");
1186+
ok(employeeClient);
1187+
1188+
const employeeModel = root.models.find((m) => m.name === "Employee");
1189+
ok(employeeModel);
1190+
1191+
// Validate Employee resource metadata should be null (no CRUD operations)
1192+
const employeeResourceMetadataDecorator = employeeModel.decorators?.find(
1193+
(d) => d.name === resourceMetadata
1194+
);
1195+
ok(employeeResourceMetadataDecorator);
1196+
strictEqual(
1197+
employeeResourceMetadataDecorator.arguments.resourceScope,
1198+
"ManagementGroup"
1199+
);
1200+
});
11501201
});

eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Extensions/AzureGeneratorMgmtTypeSpecTestsExtensions.cs

Lines changed: 37 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

eng/packages/http-client-csharp-mgmt/generator/TestProjects/Local/Mgmt-TypeSpec/src/Generated/Extensions/MockableAzureGeneratorMgmtTypeSpecTestsManagementGroupResource.cs

Lines changed: 99 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)