Skip to content

importer-msgraph-metadata - update for tags breaking changes in source data #4764

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 0 additions & 5 deletions config/microsoft-graph.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ service "administrativeUnits" {
available = ["beta"]
}

service "appRoleAssignments" {
name = "AppRoleAssignments"
available = ["beta"]
}

service "applications" {
name = "Applications"
available = ["stable", "beta"]
Expand Down
2 changes: 1 addition & 1 deletion submodules/msgraph-metadata
89 changes: 48 additions & 41 deletions tools/importer-msgraph-metadata/components/parser/resourceids.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func (r ResourceId) FullyQualifiedResourceName(suffixQualification *string) (*st
}

// TODO: it would be nice to do this but it's causing some clobbering issues
//name = normalize.DeDuplicateName(name)
// name = normalize.DeDuplicateName(name)

return &name, true
}
Expand Down Expand Up @@ -334,24 +334,29 @@ func NewResourceId(path string, tags []string) (id ResourceId) {
for i, s := range segments {
var segment ResourceIdSegment

if strings.HasPrefix(s, "{") && strings.HasSuffix(s, "}") {
value := s[1 : len(s)-1]
field := normalize.CleanName(value)
value = normalize.CleanNameCamel(value)
segment = ResourceIdSegment{
Type: SegmentUserValue,
Value: fmt.Sprintf("{%s}", value),
field: &field,
switch {
case strings.HasPrefix(s, "{") && strings.HasSuffix(s, "}"):
{
value := s[1 : len(s)-1]
field := normalize.CleanName(value)
value = normalize.CleanNameCamel(value)
segment = ResourceIdSegment{
Type: SegmentUserValue,
Value: fmt.Sprintf("{%s}", value),
field: &field,
}
}
} else if strings.Contains(s, "(") {
// Note: this will need updating if we are going to support complex user values such as `applications(appId='{appId}')`
segment = ResourceIdSegment{
Type: SegmentFunction,
Value: s,
field: nil,
case strings.Contains(s, "("):
{
// Note: this will need updating if we are going to support complex user values such as `applications(appId='{appId}')`
segment = ResourceIdSegment{
Type: SegmentFunction,
Value: s,
field: nil,
}
}
} else if strings.HasPrefix(strings.ToLower(s), "microsoft.graph.") || strings.HasPrefix(strings.ToLower(s), "graph.") {
if tagSuffix(".actions") {
case strings.HasPrefix(strings.ToLower(s), "microsoft.graph.") || strings.HasPrefix(strings.ToLower(s), "graph."):
{
value := s
if strings.HasPrefix(strings.ToLower(value), "microsoft.graph.") {
value = value[16:]
Expand All @@ -367,37 +372,39 @@ func NewResourceId(path string, tags []string) (id ResourceId) {
Value: value,
field: nil,
}
} else {
}
case strings.HasPrefix(s, "$"):
{
segment = ResourceIdSegment{
Type: SegmentCast,
Type: SegmentODataReference,
Value: s,
field: nil,
}
}
} else if strings.HasPrefix(s, "$") {
segment = ResourceIdSegment{
Type: SegmentODataReference,
Value: s,
field: nil,
}
} else if i == len(segments)-1 && tagSuffix(".actions") {
segment = ResourceIdSegment{
Type: SegmentAction,
Value: s,
field: nil,
case i == len(segments)-1 && tagSuffix(".actions"):
{
segment = ResourceIdSegment{
Type: SegmentAction,
Value: s,
field: nil,
}
}
} else if i == len(segments)-1 && tagSuffix(".functions") {
segment = ResourceIdSegment{
Type: SegmentFunction,
Value: s,
field: nil,
case i == len(segments)-1 && tagSuffix(".functions"):
{
segment = ResourceIdSegment{
Type: SegmentFunction,
Value: s,
field: nil,
}
}
} else {
segment = ResourceIdSegment{
Type: SegmentLabel,
Value: s,
field: nil,
plural: normalize.Pluralize(s) == s,
default:
{
segment = ResourceIdSegment{
Type: SegmentLabel,
Value: s,
field: nil,
plural: normalize.Pluralize(s) == s,
}
}
}

Expand Down
20 changes: 15 additions & 5 deletions tools/importer-msgraph-metadata/components/tags/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,23 @@ func Parse(tags openapi3.Tags) (services ServiceTags, err error) {
}
if tag.Name != "" {
t := strings.Split(tag.Name, ".")
if len(t) != 2 {
switch len(t) {
case 2:
if _, ok := services[t[0]]; !ok {
services[t[0]] = make([]string, 0)
}
services[t[0]] = append(services[t[0]], t[1])

case 3:
if _, ok := services[t[0]]; !ok {
services[t[0]] = make([]string, 0)
}
services[t[0]] = append(services[t[0]], t[2])

default:
return nil, fmt.Errorf("encountered malformed tag: %q", tag.Name)

}
if _, ok := services[t[0]]; !ok {
services[t[0]] = make([]string, 0)
}
services[t[0]] = append(services[t[0]], t[1])
}
}
return
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ var workarounds = []dataWorkaround{
// Model-specific workarounds
workaroundAccessPackageResourceRoleScope{},
workaroundApplication{},
workaroundConditionalAccessPolicy{},
workaroundOAuth2PermissionGrant{},
workaroundUnifiedRoleAssignment{},
}
Expand Down
Loading