webdav: add Client.FindPrincipal

This commit is contained in:
Simon Ser 2022-05-03 18:15:11 +02:00
parent 4cc86a1225
commit 8187cbf8c6

View File

@ -66,6 +66,41 @@ func (c *Client) FindCurrentUserPrincipal() (string, error) {
return prop.Href.Path, nil
}
func (c *Client) FindPrincipal(path string) (*Principal, error) {
propfind := internal.NewPropNamePropfind(
internal.ResourceTypeName,
internal.DisplayNameName,
principalURLName,
)
resp, err := c.ic.PropfindFlat(path, propfind)
if err != nil {
return nil, err
}
var resType internal.ResourceType
if err := resp.DecodeProp(&resType); err != nil {
return nil, err
}
if !resType.Is(principalName) {
return nil, fmt.Errorf("%q is not a principal resource", path)
}
var dispName internal.DisplayName
if err := resp.DecodeProp(&dispName); err != nil {
return nil, err
}
var principalURL principalURL
if err := resp.DecodeProp(&principalURL); err != nil {
return nil, err
}
return &Principal{
Path: principalURL.Href.Path,
Name: dispName.Name,
}, nil
}
var fileInfoPropfind = internal.NewPropNamePropfind(
internal.ResourceTypeName,
internal.GetContentLengthName,