Skip to content

Commit

Permalink
add discovery endpoint in the ocm client
Browse files Browse the repository at this point in the history
  • Loading branch information
gmgigi96 committed May 10, 2023
1 parent ff0b0c2 commit 33679d8
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions pkg/ocm/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,50 @@ func (c *OCMClient) parseNewShareResponse(r *http.Response) (*NewShareResponse,
}
return nil, errtypes.InternalError(string(body))
}

// Capabilities contains a set of properties exposed by
// a remote cloud storage.
type Capabilities struct {
Enabled bool `json:"enabled"`
APIVersion string `json:"apiVersion"`
EndPoint string `json:"endPoint"`
Provider string `json:"provider"`
ResourceTypes []struct {
Name string `json:"name"`
ShareTypes []string `json:"shareTypes"`
Protocols struct {
Webdav *string `json:"webdav"`
Webapp *string `json:"webapp"`
Datatx *string `json:"datatx"`
} `json:"protocols"`
} `json:"resourceTypes"`
Capabilities []string `json:"capabilities"`
}

// Discovery returns a number of properties used to discover the capabilities offered by a remote cloud storage.
// https://cs3org.github.io/OCM-API/docs.html?branch=develop&repo=OCM-API&user=cs3org#/paths/~1ocm-provider/get
func (c *OCMClient) Discovery(ctx context.Context, endpoint string) (*Capabilities, error) {
url, err := url.JoinPath(endpoint, "shares")
if err != nil {
return nil, err
}

req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return nil, errors.Wrap(err, "error creating request")
}
req.Header.Set("Content-Type", "application/json")

resp, err := c.client.Do(req)
if err != nil {
return nil, errors.Wrap(err, "error doing request")
}
defer resp.Body.Close()

var cap Capabilities
if err := json.NewDecoder(resp.Body).Decode(&c); err != nil {
return nil, err
}

return &cap, nil
}

0 comments on commit 33679d8

Please sign in to comment.