-
Notifications
You must be signed in to change notification settings - Fork 5k
Implement mgmt resource #47944
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Implement mgmt resource #47944
Changes from 41 commits
Commits
Show all changes
70 commits
Select commit
Hold shift + click to select a range
f041f24
wip
live1206 badf1a5
wip
live1206 69fa28a
wip
live1206 615fec1
Merge remote-tracking branch 'origin/main' into implement-mgmt-resource
live1206 d136be2
wip
live1206 a040627
wip
live1206 0296a71
Merge remote-tracking branch 'origin/main' into implement-mgmt-resource
live1206 fda752a
generate operation methods for Resource
live1206 580508a
add package back
live1206 ba12225
Merge remote-tracking branch 'origin/main' into implement-mgmt-resource
live1206 ef83882
update to latest MGC
live1206 120e164
fix test
live1206 e4bbde0
Merge branch 'main' into implement-mgmt-resource
live1206 b2842c4
Add test for ResourceProvider
live1206 5f5cee9
Merge remote-tracking branch 'origin/main' into implement-mgmt-resource
live1206 41cf53c
Add RequestPath
live1206 7bba967
remove unused property
live1206 5d3a879
address comments
live1206 2fe508f
Include custom code for convenience methods
live1206 d9fd368
add TODO
live1206 17b2a0f
merge from main
live1206 45a10a7
implement resource LRO
live1206 b06fb59
implement LRO for resource
live1206 c98e231
Implement IOperationSouce and generated MgmtTypeSpec can build now
live1206 848e6d7
update test data
live1206 0db68cb
Add test for OperationSourceProvider
live1206 2b15650
update tests
live1206 51bd7f3
cleanup
live1206 a8b2b8f
update
live1206 dc2b83d
cleanup
live1206 adbcc1c
Address comments
live1206 bb92673
Add Mgmt-TypeSpec generation to Generate.ps1
live1206 af9bd9c
Merge remote-tracking branch 'origin/main' into implement-mgmt-resource
live1206 c5ca437
Update eng/packages/http-client-csharp/generator/Azure.Generator/src/…
live1206 3ed339d
update
live1206 d800d35
Merge branch 'main' into implement-mgmt-resource
live1206 8d78f7f
fix build
live1206 8fbc8aa
update to use CanonicalView
live1206 081696d
update test
live1206 f9e8afd
Use ModelSerializationExtensions.WireOptions instead of new instance
live1206 8d7b831
update test
live1206 4dcccc7
Address comments
live1206 d00ee3a
typo
live1206 0086b11
Merge remote-tracking branch 'origin/main' into implement-mgmt-resource
live1206 e34db7b
resolve comments
live1206 417af63
fix build
live1206 965e951
update test
live1206 579dd9b
separate tests for ResourceClientProvider
live1206 682e704
Add TODO
live1206 22e08c6
fix tests
live1206 541193c
Move resource related logic to ResourceBuilder
live1206 20cdaaf
Remove clientProvider and implement client methods in Resource directly
live1206 78b5cb5
update
live1206 ff44b6b
simplify resource detection
live1206 33c30fa
Merge branch 'main' into implement-mgmt-resource
live1206 ca43fe6
replace resource detection with decorators
live1206 7ff96ba
cleanup
live1206 34478aa
Apply resourceMetadata decorator for generator to consume
live1206 f6d7776
Merge remote-tracking branch 'upstream/main' into implement-mgmt-reso…
live1206 41721a8
cleanup
live1206 949d5e1
refine
live1206 10ca791
rename
live1206 eb48437
Merge remote-tracking branch 'upstream/main' into implement-mgmt-reso…
live1206 70c212d
merge
live1206 ace3f42
address comments
live1206 4037c12
fix lint and format
live1206 79f2a3f
address comments
live1206 b2ab27a
rename
live1206 98f91a6
set update callback with options
live1206 f691c45
update MTG emitter version
live1206 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
eng/packages/http-client-csharp/generator/Azure.Generator/src/Mgmt/Models/RequestPath.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Linq; | ||
|
||
namespace Azure.Generator.Mgmt.Models | ||
{ | ||
internal class RequestPath : IEquatable<RequestPath>, IReadOnlyList<string> | ||
{ | ||
private const string ProviderPath = "/subscriptions/{subscriptionId}/providers/{resourceProviderNamespace}"; | ||
private const string FeaturePath = "/subscriptions/{subscriptionId}/providers/Microsoft.Features/providers/{resourceProviderNamespace}/features"; | ||
|
||
public const string ManagementGroupScopePrefix = "/providers/Microsoft.Management/managementGroups"; | ||
public const string ResourceGroupScopePrefix = "/subscriptions/{subscriptionId}/resourceGroups"; | ||
public const string SubscriptionScopePrefix = "/subscriptions"; | ||
public const string TenantScopePrefix = "/tenants"; | ||
public const string Providers = "/providers"; | ||
|
||
public static readonly RequestPath ManagementGroup = new("/providers/Microsoft.Management/managementGroups/{managementGroupId}"); | ||
public static readonly RequestPath ResourceGroup = new("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}"); | ||
public static readonly RequestPath Subscription = new("/subscriptions/{subscriptionId}"); | ||
public static readonly RequestPath Tenant = new(string.Empty); | ||
|
||
private string _path; | ||
private IReadOnlyList<string> _segments; | ||
|
||
public RequestPath(string path) | ||
{ | ||
_path = path; | ||
_segments = path.Split('/', StringSplitOptions.RemoveEmptyEntries); | ||
IndexOfLastProviders = _path.LastIndexOf(Providers); | ||
} | ||
|
||
public RequestPath(IEnumerable<string> segments) | ||
{ | ||
_segments = segments.ToArray(); | ||
_path = string.Join("/", _segments); | ||
} | ||
|
||
public int Count => _segments.Count; | ||
|
||
public string SerializedPath => _path; | ||
|
||
public int IndexOfLastProviders { get; } | ||
|
||
public string this[int index] => _segments[index]; | ||
|
||
/// <summary> | ||
/// Check if this <see cref="RequestPath"/> is a prefix path of the other request path. | ||
/// Note that this.IsAncestorOf(this) will return false which indicates that this method is testing the "proper ancestor" like a proper subset. | ||
/// </summary> | ||
/// <param name="other"></param> | ||
/// <returns></returns> | ||
public bool IsAncestorOf(RequestPath other) | ||
{ | ||
// To be the parent of other, you must at least be shorter than other. | ||
if (other.Count <= Count) | ||
return false; | ||
for (int i = 0; i < Count; i++) | ||
{ | ||
// we need the segment to be identical when strict is true (which is the default value) | ||
// when strict is false, we also need the segment to be identical if it is constant. | ||
// but if it is a reference, we only require they have the same type, do not require they have the same variable name. | ||
// This case happens a lot during the management group parent detection - different RP calls this different things | ||
if (!this[i].Equals(other[i])) | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
/// <summary> | ||
/// Trim this from the other and return the <see cref="RequestPath"/>that remain. | ||
/// The result is "other - this" by removing this as a prefix of other. | ||
/// If this == other, return empty request path | ||
/// </summary> | ||
/// <param name="other"></param> | ||
/// <returns></returns> | ||
/// <exception cref="InvalidOperationException">if this.IsAncestorOf(other) is false</exception> | ||
public RequestPath TrimAncestorFrom(RequestPath other) | ||
{ | ||
if (TryTrimAncestorFrom(other, out var diff)) | ||
return diff; | ||
|
||
throw new InvalidOperationException($"Request path {this} is not parent of {other}"); | ||
} | ||
|
||
private bool TryTrimAncestorFrom(RequestPath other, [MaybeNullWhen(false)] out RequestPath diff) | ||
{ | ||
diff = default; | ||
if (this == other) | ||
{ | ||
diff = Tenant; | ||
return true; | ||
} | ||
if (IsAncestorOf(other)) | ||
{ | ||
diff = new RequestPath(string.Join("", other._segments.Skip(Count))); | ||
return true; | ||
} | ||
// Handle the special case of trim provider from feature | ||
else if (_path == ProviderPath && other._path.StartsWith(FeaturePath)) | ||
{ | ||
diff = new RequestPath(string.Join("", other._segments.Skip(Count + 2))); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public bool Equals(RequestPath? other) | ||
{ | ||
if (Count != other?.Count) | ||
return false; | ||
for (int i = 0; i < Count; i++) | ||
{ | ||
if (!this[i].Equals(other[i])) | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
public override bool Equals(object? obj) => obj is RequestPath other && Equals(other); | ||
|
||
public override int GetHashCode() => _path.GetHashCode(); | ||
|
||
public override string ToString() => _path; | ||
|
||
public IEnumerator<String> GetEnumerator() => _segments.GetEnumerator(); | ||
|
||
IEnumerator IEnumerable.GetEnumerator() => _segments.GetEnumerator(); | ||
|
||
public static bool operator ==(RequestPath left, RequestPath right) | ||
{ | ||
return left.Equals(right); | ||
} | ||
|
||
public static bool operator !=(RequestPath left, RequestPath right) | ||
{ | ||
return !(left == right); | ||
} | ||
|
||
public static implicit operator string(RequestPath requestPath) | ||
{ | ||
return requestPath._path; | ||
} | ||
|
||
public static bool IsSegmentConstant(string segment) | ||
{ | ||
var trimmed = segment.TrimStart('{').TrimEnd('}'); | ||
var isScope = trimmed == "scope"; | ||
return !isScope && !segment.StartsWith('{'); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.