-
Notifications
You must be signed in to change notification settings - Fork 43
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
commonids: add composite resource id #208
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @catriona-m
Thanks for this PR - apologies for the delayed review here.
Taking a look through on the whole this is looking pretty good, if we can fix up the comments then this should otherwise be good to go 👍
Thanks!
return nil, fmt.Errorf("parsing first id of CompositeResourceID: %v", err) | ||
} | ||
err = output.First.FromParseResult(*firstParseResult) | ||
if err != nil { | ||
return nil, fmt.Errorf("populating first id of CompositeResourceID: %v", err) | ||
} | ||
|
||
// Parse the second of the two Resource IDs from the components | ||
secondParser := resourceids.NewParserFromResourceIdType(output.Second) | ||
secondParseResult, err := secondParser.Parse(components[1], insensitively) | ||
if err != nil { | ||
return nil, fmt.Errorf("parsing second id of CompositeResourceID: %v", err) | ||
} | ||
err = output.Second.FromParseResult(*secondParseResult) | ||
if err != nil { | ||
return nil, fmt.Errorf("populating second id of CompositeResourceID: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we output the parsed id part as a part of the error to make this clearer?
return nil, fmt.Errorf("parsing first id of CompositeResourceID: %v", err) | |
} | |
err = output.First.FromParseResult(*firstParseResult) | |
if err != nil { | |
return nil, fmt.Errorf("populating first id of CompositeResourceID: %v", err) | |
} | |
// Parse the second of the two Resource IDs from the components | |
secondParser := resourceids.NewParserFromResourceIdType(output.Second) | |
secondParseResult, err := secondParser.Parse(components[1], insensitively) | |
if err != nil { | |
return nil, fmt.Errorf("parsing second id of CompositeResourceID: %v", err) | |
} | |
err = output.Second.FromParseResult(*secondParseResult) | |
if err != nil { | |
return nil, fmt.Errorf("populating second id of CompositeResourceID: %v", err) | |
return nil, fmt.Errorf("parsing first id part %q of CompositeResourceID: %v", components[0], err) | |
} | |
err = output.First.FromParseResult(*firstParseResult) | |
if err != nil { | |
return nil, fmt.Errorf("populating first id part %q of CompositeResourceID: %v", components[0], err) | |
} | |
// Parse the second of the two Resource IDs from the components | |
secondParser := resourceids.NewParserFromResourceIdType(output.Second) | |
secondParseResult, err := secondParser.Parse(components[1], insensitively) | |
if err != nil { | |
return nil, fmt.Errorf("parsing second id part %q of CompositeResourceID: %v", components[1], err) | |
} | |
err = output.Second.FromParseResult(*secondParseResult) | |
if err != nil { | |
return nil, fmt.Errorf("populating second id part %q of CompositeResourceID: %v", components[1], err) |
return Parse(input, first, second, true) | ||
} | ||
|
||
func Parse[T1 resourceids.ResourceId, T2 resourceids.ResourceId](input string, first T1, second T2, insensitively bool) (*CompositeResourceID[T1, T2], error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given we're providing wrapper functions above, does this method need to be public?
type CompositeResourceID[T1 resourceids.ResourceId, T2 resourceids.ResourceId] struct { | ||
First T1 | ||
Second T2 | ||
} | ||
|
||
func (id CompositeResourceID[T1, T2]) ID() string { | ||
fmtString := "%s|%s" | ||
return fmt.Sprintf(fmtString, id.First.ID(), id.Second.ID()) | ||
} | ||
|
||
func (id CompositeResourceID[T1, T2]) String() string { | ||
fmtString := "%s\n%s" | ||
return fmt.Sprintf(fmtString, id.First.String(), id.Second.String()) | ||
} | ||
|
||
func ParseCompositeResourceID[T1 resourceids.ResourceId, T2 resourceids.ResourceId](input string, first T1, second T2) (*CompositeResourceID[T1, T2], error) { | ||
return Parse(input, first, second, false) | ||
} | ||
|
||
func ParseCompositeResourceIDInsensitively[T1 resourceids.ResourceId, T2 resourceids.ResourceId](input string, first T1, second T2) (*CompositeResourceID[T1, T2], error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we document this struct/the functions to explain how this is intended to be used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few minor comments inline but otherwise 👍
// String returns a human-readable description of this Composite Resource Id | ||
func (id CompositeResourceID[T1, T2]) String() string { | ||
fmtString := "%s\n%s" | ||
return fmt.Sprintf(fmtString, id.First.String(), id.Second.String()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we call out that this is a Composite Resource ID:
// String returns a human-readable description of this Composite Resource Id | |
func (id CompositeResourceID[T1, T2]) String() string { | |
fmtString := "%s\n%s" | |
return fmt.Sprintf(fmtString, id.First.String(), id.Second.String()) | |
} | |
// String returns a human-readable description of this Composite Resource Id | |
func (id CompositeResourceID[T1, T2]) String() string { | |
fmtString := "Composite Resource ID (%s | %s)" | |
return fmt.Sprintf(fmtString, id.First.String(), id.Second.String()) | |
} |
return parse(input, first, second, false) | ||
} | ||
|
||
// ParseCompositeResourceIDInsensitively parses 'input' and two ResourceIds (first,second) case-insensitively into a CompositeResourceID | ||
// note: this method should only be used for API response data and not user input | ||
func ParseCompositeResourceIDInsensitively[T1 resourceids.ResourceId, T2 resourceids.ResourceId](input string, first T1, second T2) (*CompositeResourceID[T1, T2], error) { | ||
return parse(input, first, second, true) | ||
} | ||
|
||
func parse[T1 resourceids.ResourceId, T2 resourceids.ResourceId](input string, first T1, second T2, insensitively bool) (*CompositeResourceID[T1, T2], error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor but could we update parse
to be parseCompositeResourceID
so that this isn't used unintentionally?
return parse(input, first, second, false) | |
} | |
// ParseCompositeResourceIDInsensitively parses 'input' and two ResourceIds (first,second) case-insensitively into a CompositeResourceID | |
// note: this method should only be used for API response data and not user input | |
func ParseCompositeResourceIDInsensitively[T1 resourceids.ResourceId, T2 resourceids.ResourceId](input string, first T1, second T2) (*CompositeResourceID[T1, T2], error) { | |
return parse(input, first, second, true) | |
} | |
func parse[T1 resourceids.ResourceId, T2 resourceids.ResourceId](input string, first T1, second T2, insensitively bool) (*CompositeResourceID[T1, T2], error) { | |
return parseCompositeResourceID(input, first, second, false) | |
} | |
// ParseCompositeResourceIDInsensitively parses 'input' and two ResourceIds (first,second) case-insensitively into a CompositeResourceID | |
// note: this method should only be used for API response data and not user input | |
func ParseCompositeResourceIDInsensitively[T1 resourceids.ResourceId, T2 resourceids.ResourceId](input string, first T1, second T2) (*CompositeResourceID[T1, T2], error) { | |
return parseCompositeResourceID(input, first, second, true) | |
} | |
func parseCompositeResourceID[T1 resourceids.ResourceId, T2 resourceids.ResourceId](input string, first T1, second T2, insensitively bool) (*CompositeResourceID[T1, T2], error) { |
First T1 | ||
Second T2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
minor but could we document these fields so that it's clearer what these are?
First T1 | |
Second T2 | |
// First specifies the first component of this Resource ID. | |
// This is in the format `{first}|{second}`. | |
First T1 | |
// Second specifies the second component of this Resource ID | |
// This is in the format `{first}|{second}`. | |
Second T2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One really minor nit for readability purposes but this otherwise LGTM 👍
Co-authored-by: Tom Harvey <tombuildsstuff@users.noreply.github.com>
Is there a plan to release this PR and update it in the AzureRM dependency? |
No description provided.