2020-01-14 17:51:17 +00:00
|
|
|
package webdav
|
|
|
|
|
|
|
|
import (
|
2020-01-14 19:00:54 +00:00
|
|
|
"encoding/xml"
|
2020-01-14 17:51:17 +00:00
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/emersion/go-webdav/internal"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Client struct {
|
|
|
|
c *internal.Client
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewClient(c *http.Client, endpoint string) (*Client, error) {
|
|
|
|
ic, err := internal.NewClient(c, endpoint)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &Client{ic}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) FindCurrentUserPrincipal() (string, error) {
|
2020-01-14 19:00:54 +00:00
|
|
|
name := xml.Name{"DAV:", "current-user-principal"}
|
|
|
|
propfind := internal.NewPropPropfind(name)
|
|
|
|
|
2020-01-14 20:43:09 +00:00
|
|
|
resp, err := c.c.PropfindFlat("/", propfind)
|
2020-01-14 20:29:54 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
2020-01-14 17:51:17 +00:00
|
|
|
}
|
|
|
|
|
2020-01-14 21:19:54 +00:00
|
|
|
var prop currentUserPrincipal
|
2020-01-14 20:29:54 +00:00
|
|
|
if err := resp.DecodeProp(name, &prop); err != nil {
|
2020-01-14 17:51:17 +00:00
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
|
|
|
|
return prop.Href, nil
|
|
|
|
}
|