Skip to content
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

Pass OCM test suite #2229

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
55a8f1e
Allow running ocm service at domain root
michielbdejong Aug 9, 2021
a75b180
Log Config Host
michielbdejong Aug 9, 2021
6982619
Work around https://github.com/cs3org/reva/issues/1962
michielbdejong Aug 9, 2021
064c774
Merge remote-tracking branch 'origin/master' into pass-ocm-test-suite
michielbdejong Oct 6, 2021
bb38d67
Fix #1752
michielbdejong Oct 6, 2021
68071c0
First attempt at parsing JSON body in createShare
michielbdejong Oct 6, 2021
7e886f9
remove debug statements
michielbdejong Oct 6, 2021
72b1181
Send OCM create share request as application/json
michielbdejong Oct 6, 2021
6b097c6
Treat ProviderId as opaque
michielbdejong Oct 6, 2021
4688ddb
TLS credentials in grpc
Oct 19, 2021
9c5b024
Log s.conf.CertFile / s.conf.KeyFile
Oct 20, 2021
f6988ab
Support json in /invites/accept
michielbdejong Oct 21, 2021
57e67c1
Support json in /invites/accept
michielbdejong Oct 21, 2021
e488235
invite map
michielbdejong Oct 22, 2021
1cc9652
.(string)
michielbdejong Oct 22, 2021
6ceff50
Fix #2201
michielbdejong Oct 25, 2021
2b7dbfa
Fix #2202
michielbdejong Oct 25, 2021
32a4621
Merge remote-tracking branch 'origin/master' into pass-ocm-test-suite
michielbdejong Oct 25, 2021
56a6ffd
Merge remote-tracking branch 'origin/master' into pass-ocm-test-suite
michielbdejong Nov 2, 2021
1e5f8c4
Revert internal/http/services/ocmd/invites.go to master
michielbdejong Nov 2, 2021
3224ecd
don't try to support tls in the rgrpc service
michielbdejong Nov 2, 2021
2a6ae90
avoid trailing slash if empty prefix
michielbdejong Nov 2, 2021
013caca
Merge remote-tracking branch 'origin/master' into pass-ocm-test-suite
michielbdejong Nov 8, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions internal/grpc/services/ocmcore/ocmcore.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"context"
"encoding/json"
"fmt"
"strings"

ocmcore "github.com/cs3org/go-cs3apis/cs3/ocm/core/v1beta1"
ocm "github.com/cs3org/go-cs3apis/cs3/sharing/ocm/v1beta1"
Expand Down Expand Up @@ -107,18 +106,11 @@ func (s *service) UnprotectedEndpoints() []string {
return []string{"/cs3.ocm.core.v1beta1.OcmCoreAPI/CreateOCMCoreShare"}
}

// CreateOCMCoreShare is called when an OCM request comes into this reva instance from
func (s *service) CreateOCMCoreShare(ctx context.Context, req *ocmcore.CreateOCMCoreShareRequest) (*ocmcore.CreateOCMCoreShareResponse, error) {
parts := strings.Split(req.ProviderId, ":")
if len(parts) < 2 {
err := errtypes.BadRequest("resource ID does not follow the layout storageid:opaqueid " + req.ProviderId)
return &ocmcore.CreateOCMCoreShareResponse{
Status: status.NewInternal(ctx, err, "error decoding resource ID"),
}, nil
}

resource := &provider.ResourceId{
StorageId: parts[0],
OpaqueId: parts[1],
StorageId: "remote",
OpaqueId: req.ProviderId,
}

var resourcePermissions *provider.ResourcePermissions
Expand Down
8 changes: 6 additions & 2 deletions internal/http/services/ocmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type configData struct {
Enabled bool `json:"enabled" xml:"enabled"`
APIVersion string `json:"apiVersion" xml:"apiVersion"`
Host string `json:"host" xml:"host"`
Endpoint string `json:"endpoint" xml:"endpoint"`
Endpoint string `json:"endPoint" xml:"endPoint"`
Provider string `json:"provider" xml:"provider"`
ResourceTypes []resourceTypes `json:"resourceTypes" xml:"resourceTypes"`
}
Expand Down Expand Up @@ -61,7 +61,11 @@ func (h *configHandler) init(c *Config) {
h.c.Provider = "cernbox"
}
h.c.Enabled = true
h.c.Endpoint = fmt.Sprintf("https://%s/%s", h.c.Host, c.Prefix)
if len(c.Prefix) > 0 {
h.c.Endpoint = fmt.Sprintf("https://%s/%s", h.c.Host, c.Prefix)
} else {
h.c.Endpoint = fmt.Sprintf("https://%s", h.c.Host)
}
h.c.ResourceTypes = []resourceTypes{{
Name: "file",
ShareTypes: []string{"user"},
Expand Down
10 changes: 6 additions & 4 deletions internal/http/services/ocmd/ocmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ type Config struct {
func (c *Config) init() {
c.GatewaySvc = sharedconf.GetGatewaySVC(c.GatewaySvc)

if c.Prefix == "" {
c.Prefix = "ocm"
}
// if c.Prefix == "" {
// c.Prefix = "ocm"
// }
}

type svc struct {
Expand Down Expand Up @@ -78,6 +78,8 @@ func New(m map[string]interface{}, log *zerolog.Logger) (global.Service, error)
s.InvitesHandler = new(invitesHandler)
s.SharesHandler.init(s.Conf)
s.NotificationsHandler.init(s.Conf)
log.Debug().Str("initializing ConfigHandler Host", s.Conf.Host)

s.ConfigHandler.init(s.Conf)
s.InvitesHandler.init(s.Conf)

Expand All @@ -94,7 +96,7 @@ func (s *svc) Prefix() string {
}

func (s *svc) Unprotected() []string {
return []string{"/invites/accept", "/shares", "/ocm-provider"}
return []string{"/invites/accept", "/shares", "/ocm-provider", "/notifications"}
}

func (s *svc) Handler() http.Handler {
Expand Down
22 changes: 19 additions & 3 deletions internal/http/services/ocmd/shares.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"mime"
"net/http"
"time"

Expand Down Expand Up @@ -59,9 +61,23 @@ func (h *sharesHandler) Handler() http.Handler {
func (h *sharesHandler) createShare(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
log := appctx.GetLogger(ctx)

shareWith, protocol, meshProvider := r.FormValue("shareWith"), r.FormValue("protocol"), r.FormValue("meshProvider")
resource, providerID, owner := r.FormValue("name"), r.FormValue("providerId"), r.FormValue("owner")
contentType, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
var shareWith, protocol, meshProvider, resource, providerID, owner string
if err == nil && contentType == "application/json" {
defer r.Body.Close()
reqBody, err := io.ReadAll(r.Body)
if err == nil {
reqMap := make(map[string]string)
err = json.Unmarshal(reqBody, &reqMap)
if err == nil {
shareWith, protocol, meshProvider = reqMap["shareWith"], reqMap["protocol"], reqMap["meshProvider"]
resource, providerID, owner = reqMap["name"], reqMap["providerId"], reqMap["owner"]
}
}
} else {
shareWith, protocol, meshProvider = r.FormValue("shareWith"), r.FormValue("protocol"), r.FormValue("meshProvider")
resource, providerID, owner = r.FormValue("name"), r.FormValue("providerId"), r.FormValue("owner")
}

if resource == "" || providerID == "" || owner == "" {
WriteError(w, r, APIErrorInvalidParameter, "missing details about resource to be shared", nil)
Expand Down
26 changes: 15 additions & 11 deletions pkg/ocm/share/manager/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,19 @@ func (m *mgr) Share(ctx context.Context, md *provider.ResourceId, g *ocm.ShareGr
}
}

requestBody := url.Values{
"shareWith": {g.Grantee.GetUserId().OpaqueId},
"name": {name},
"providerId": {fmt.Sprintf("%s:%s", md.StorageId, md.OpaqueId)},
"owner": {userID.OpaqueId},
"protocol": {string(protocol)},
"meshProvider": {userID.Idp},
requestBodyMap := map[string]string{
"shareWith": g.Grantee.GetUserId().OpaqueId,
"name": name,
"providerId": fmt.Sprintf("%s:%s", md.StorageId, md.OpaqueId),
"owner": userID.OpaqueId,
"protocol": string(protocol),
"meshProvider": userID.Idp,
}
requestBody, err := json.Marshal(requestBodyMap)
if err != nil {
err = errors.Wrap(err, "error marshalling request body")
return nil, err
}

ocmEndpoint, err := getOCMEndpoint(pi)
if err != nil {
return nil, err
Expand All @@ -325,11 +329,11 @@ func (m *mgr) Share(ctx context.Context, md *provider.ResourceId, g *ocm.ShareGr
u.Path = path.Join(u.Path, createOCMCoreShareEndpoint)
recipientURL := u.String()

req, err := http.NewRequest("POST", recipientURL, strings.NewReader(requestBody.Encode()))
req, err := http.NewRequest("POST", recipientURL, strings.NewReader(string(requestBody)))
if err != nil {
return nil, errors.Wrap(err, "json: error framing post request")
}
req.Header.Set("Content-Type", "application/x-www-form-urlencoded; param=value")
req.Header.Set("Content-Type", "application/json; param=value")

resp, err := m.client.Do(req)
if err != nil {
Expand All @@ -338,7 +342,7 @@ func (m *mgr) Share(ctx context.Context, md *provider.ResourceId, g *ocm.ShareGr
}

defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
if (resp.StatusCode != http.StatusCreated) && (resp.StatusCode != http.StatusOK) {
respBody, e := ioutil.ReadAll(resp.Body)
if e != nil {
e = errors.Wrap(e, "json: error reading request body")
Expand Down
11 changes: 9 additions & 2 deletions pkg/rhttp/rhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ type config struct {
Address string `mapstructure:"address"`
Services map[string]map[string]interface{} `mapstructure:"services"`
Middlewares map[string]map[string]interface{} `mapstructure:"middlewares"`
CertFile string `mapstructure:"certfile"`
KeyFile string `mapstructure:"keyfile"`
}

func (c *config) init() {
Expand Down Expand Up @@ -109,8 +111,13 @@ func (s *Server) Start(ln net.Listener) error {
s.httpServer.Handler = handler
s.listener = ln

s.log.Info().Msgf("http server listening at %s://%s", "http", s.conf.Address)
err = s.httpServer.Serve(s.listener)
if (s.conf.CertFile != "") && (s.conf.KeyFile != "") {
s.log.Info().Msgf("https server listening at https://%s '%s' '%s'", s.conf.Address, s.conf.CertFile, s.conf.KeyFile)
err = s.httpServer.ServeTLS(s.listener, s.conf.CertFile, s.conf.KeyFile)
} else {
s.log.Info().Msgf("http server listening at http://%s '%s' '%s'", s.conf.Address, s.conf.CertFile, s.conf.KeyFile)
err = s.httpServer.Serve(s.listener)
}
if err == nil || err == http.ErrServerClosed {
return nil
}
Expand Down