Skip to content

Commit

Permalink
[xds_fed_name_parsing] c1
Browse files Browse the repository at this point in the history
  • Loading branch information
menghanl committed Dec 6, 2021
1 parent 780cb7c commit c6450ad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
23 changes: 17 additions & 6 deletions xds/internal/xdsclient/xdsresource/name.go
Expand Up @@ -26,13 +26,22 @@ import (
)

// Name contains the parsed component of an xDS resource name.
//
// An xDS resource name is in the format of
// xdstp://[{authority}]/{resource type}/{id/*}?{context parameters}{#processing directive,*}
//
// See
// https://github.com/cncf/xds/blob/main/proposals/TP1-xds-transport-next.md#uri-based-xds-resource-names
// for details, and examples.
type Name struct {
Scheme string
Authority string
Type string
ID string

ContextParams map[string]string

processingDirective string
}

// ParseName splits the name and returns a struct representation of the Name.
Expand Down Expand Up @@ -76,8 +85,9 @@ func ParseName(name string) *Name {
}
}
// TODO: processing directive (the part comes after "#" in the URL, stored
// in parsed.RawFragment) is not processed. Add support for that when it's
// needed.
// in parsed.RawFragment) is kept but not processed. Add support for that
// when it's needed.
ret.processingDirective = parsed.RawFragment
return ret
}

Expand Down Expand Up @@ -106,10 +116,11 @@ func (n *Name) String() string {
}

tempURL := &url.URL{
Scheme: n.Scheme,
Host: n.Authority,
Path: path,
RawQuery: rawQuery,
Scheme: n.Scheme,
Host: n.Authority,
Path: path,
RawQuery: rawQuery,
RawFragment: n.processingDirective,
}
return tempURL.String()
}
2 changes: 1 addition & 1 deletion xds/internal/xdsclient/xdsresource/name_test.go
Expand Up @@ -101,6 +101,6 @@ func TestNameStringCtxParamsOrder(t *testing.T) {
bParsed := ParseName(b).String()

if aParsed != bParsed {
t.Fatalf("aParsed.String() = %q, bParsed.String() =%q, want them to be the same", aParsed, bParsed)
t.Fatalf("aParsed.String() = %q, bParsed.String() = %q, want them to be the same", aParsed, bParsed)
}
}

0 comments on commit c6450ad

Please sign in to comment.