[FEATURE REQ] Store subscription ownerId relative to the service, the way scope already is
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 55/100
Hướng nghiên cứu
Bắt đầu với IResourceWithReference trong common/Resource.cs và đường dẫn định dạng DTO trong common/Resource.FileSystem.cs, sau đó so sánh các khai báo tham chiếu trong common/Subscription.cs và common/WorkspaceSubscription.cs. Theo dõi cách các khai báo này được truyền vào FormatInformationFileDto và Relationships.cs getReferences. Được xem là hoàn tất khi ownerId được lưu trữ theo dạng tương đối cho cả hai tài nguyên subscription mà không tạo ra các dependency của quan hệ người dùng, đồng thời các bài kiểm thử bao quát hành vi trích xuất và publishing.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
v7 relativizes cross-resource references so an artifact can be published to any instance, which is a great improvement. Subscription scope is covered, but ownerId is not, so subscription artifacts remain pinned to the instance they were extracted from.
What the extractor writes today
Extracting a subscription produces:
{
"properties": {
"displayName": "Unlimited",
"scope": "/products/unlimited",
"ownerId": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-dev/providers/Microsoft.ApiManagement/service/apim-dev/users/1",
"state": "active"
}
}
scope is relative and publishes anywhere. ownerId still carries the source instance's subscription id, resource group and service name, so publishing this artifact to another instance requires a configuration override for every subscription:
subscriptions:
- name: unlimited
properties:
ownerId: "/subscriptions/{#SUB#}/resourceGroups/{#RG#}/providers/Microsoft.ApiManagement/service/{#SVC#}/users/1"
That override is pure boilerplate. It says nothing except "the same user id, on whichever instance this is", which is exactly what a relative id already expresses.
The relative form is the documented contract
This is not a request to invent a new format. Microsoft documents ownerId as relative:
ownerId — The user resource identifier of the subscription owner. The value is a valid relative URL in the format of
/users/{userId}where{userId}is a user identifier.
APIM returns the expanded absolute form on GET, the same as it does for scope, but the documented canonical format is relative. So the extractor is persisting a shape that is less portable than the contract allows.
Why the existing mechanism cannot simply be extended
The obvious change is to add ownerId to OptionalReferencedResourceDtoProperties in SubscriptionResource, next to the two Scope entries. That does not work, for two reasons:
-
That dictionary is keyed by
IResource, and there is noUserResource. Introducing one would mean APIOps starts modelling users as an extractable and publishable resource type, which is a much larger change than this problem warrants. -
The same dictionaries feed the publisher's relationship graph in
Relationships.cs(getReferences). AUserResourcekey would create a subscription-to-user dependency edge, so the publisher would expect the user in source andSTRICT_VALIDATION=truewould report a missing predecessor. Users are typically not managed as artifacts, so that would be a false failure.
The two concerns are currently coupled: "this property holds an absolute id that should be stored relative" and "this property references a resource we manage". ownerId is the first case without the second.
Proposed change
Separate the two by adding a relativization-only declaration.
common/Resource.cs, on IResourceWithReference:
/// <summary>
/// DTO properties holding an absolute resource id that should be persisted relative to the
/// service, but whose target is not a resource APIOps manages. These take part in id
/// relativization only; they never contribute to the relationship graph.
/// </summary>
ImmutableHashSet<string> RelativeIdDtoProperties => [];
common/Resource.FileSystem.cs, include them when formatting the information file:
private static JsonObject FormatInformationFileDto(this IResourceWithReference resource, JsonObject dto) =>
resource.MandatoryReferencedResourceDtoProperties
.Union(resource.OptionalReferencedResourceDtoProperties)
.Select(kvp => kvp.Value)
.Union(resource.RelativeIdDtoProperties)
.Aggregate(dto, SetAbsoluteToRelativeId);
Union on the projected property names also removes the need for the current DistinctBy(kvp => kvp.Value), which exists because Scope is declared twice.
common/Subscription.cs and common/WorkspaceSubscription.cs:
public ImmutableHashSet<string> RelativeIdDtoProperties { get; } =
[nameof(SubscriptionDto.Properties.OwnerId)];
The interface member defaults to empty, so nothing else changes and no existing resource is affected. nameof follows the convention already used for Scope and LoggerId, which works because DTOs are parsed with JsonSerializerOptions.Web.
Scope
SubscriptionResource.OwnerIdWorkspaceSubscriptionResource.OwnerId
I looked for other properties in the same category and did not find an obvious one, but the new member gives a place for them if they turn up.
Effect
Subscription artifacts become fully instance-agnostic, and the per-subscription ownerId override disappears from every environment configuration file. In our own repo that is 21 override lines in one operator repository and 3 in each of two environment files in another.
Happy to implement
I am glad to send the PR with tests if you agree with the shape. The main open question is naming and whether you would rather see this as a separate member as proposed, or handled some other way, for example a marker on the DTO property or widening the existing dictionaries to accept a null resource key.
- Ngôn ngữ chính
- C#
- Star
- 448
- Fork
- 247
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Azure/apiops
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
Issue tương tự
-
[Feat] 조합 영역 구분선 개선 Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
type/automation type/tech-debt
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
t/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
ci-failure-cause test-failure
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100