Skip to content

Commit

Permalink
Minor fixes in OCM shares, gateway uploads and smtpclient
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 committed Aug 12, 2020
1 parent 2f9d60a commit 4a9b7d7
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 16 deletions.
3 changes: 3 additions & 0 deletions changelog/unreleased/ocm-fixes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Bugfix: Minor fixes in OCM shares, gateway uploads and smtpclient

https://github.com/cs3org/reva/pull/1082
2 changes: 0 additions & 2 deletions examples/ocmd/ocmd-server-1.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[shared]
jwt_secret = "Pive-Fumkiu4"
gatewaysvc = "localhost:19000"

[grpc]
Expand All @@ -20,7 +19,6 @@ ocminvitemanagersvc = "localhost:19000"
ocmproviderauthorizersvc = "localhost:19000"
commit_share_to_storage_grant = false
datagateway = "http://localhost:19001/data"
transfer_shared_secret = "replace-me-with-a-transfer-secret" # for direct uploads
transfer_expires = 6 # give it a moment

[grpc.services.authregistry]
Expand Down
2 changes: 0 additions & 2 deletions examples/ocmd/ocmd-server-2.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[shared]
jwt_secret = "Pive-Fumkiu4"
gatewaysvc = "localhost:17000"

[grpc]
Expand All @@ -18,7 +17,6 @@ ocminvitemanagersvc = "localhost:17000"
ocmproviderauthorizersvc = "localhost:17000"
commit_share_to_storage_grant = false
datagateway = "http://localhost:17001/data"
transfer_shared_secret = "replace-me-with-a-transfer-secret" # for direct uploads
transfer_expires = 6 # give it a moment

[grpc.services.authregistry]
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/cheggaaa/pb v1.0.28
github.com/coreos/go-oidc v2.2.1+incompatible
github.com/cs3org/cato v0.0.0-20200626150132-28a40e643719
github.com/cs3org/go-cs3apis v0.0.0-20200730121022-c4f3d4f7ddfd
github.com/cs3org/go-cs3apis v0.0.0-20200810113633-b00aca449666
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/eventials/go-tus v0.0.0-20200718001131-45c7ec8f5d59
github.com/go-ldap/ldap/v3 v3.2.3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ github.com/cs3org/go-cs3apis v0.0.0-20200728114537-4efa23660dbe h1:CQ/Grq7oVFqwi
github.com/cs3org/go-cs3apis v0.0.0-20200728114537-4efa23660dbe/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cs3org/go-cs3apis v0.0.0-20200730121022-c4f3d4f7ddfd h1:uMaudkC7znaiIKT9rxIhoRYzrhTg1Nc78X7XEqhmjSk=
github.com/cs3org/go-cs3apis v0.0.0-20200730121022-c4f3d4f7ddfd/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/cs3org/go-cs3apis v0.0.0-20200810113633-b00aca449666 h1:E7VsSSN/2YZLSwrDMJJdAWU11lP7W1qkcXbrslb0PM0=
github.com/cs3org/go-cs3apis v0.0.0-20200810113633-b00aca449666/go.mod h1:UXha4TguuB52H14EMoSsCqDj7k8a/t7g4gVP+bgY5LY=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
8 changes: 1 addition & 7 deletions internal/grpc/services/gateway/ocmshareprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,18 +308,12 @@ func (s *svc) createWebdavReference(ctx context.Context, share *ocm.Share) (*rpc
return status.NewInternal(ctx, err, "error updating received share"), nil
}

parts := strings.Split(share.Id.OpaqueId, ":")
if len(parts) < 2 {
err := errors.New("resource ID does not follow the layout id:name ")
return status.NewInternal(ctx, err, "error decoding resource ID"), nil
}

// reference path is the home path + some name on the corresponding
// mesh provider (webdav:/home/MyShares/x@webdav_endpoint)
// It is the responsibility of the gateway to resolve these references and merge the response back
// from the main request.
// TODO(labkode): the name of the share should be the filename it points to by default.
refPath := path.Join(homeRes.Path, s.c.ShareFolder, path.Base(parts[1]))
refPath := path.Join(homeRes.Path, s.c.ShareFolder, share.Name)
log.Info().Msg("mount path will be:" + refPath)

createRefReq := &provider.CreateReferenceRequest{
Expand Down
4 changes: 3 additions & 1 deletion internal/http/services/dataprovider/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ func (s *svc) doTusPut(w http.ResponseWriter, r *http.Request) {

fp := r.Header.Get("File-Path")
if fp == "" {
log.Error().Msg("File-Path header not present")
w.WriteHeader(http.StatusBadRequest)
return
}

length, err := strconv.ParseInt(r.Header.Get("Content-Length"), 10, 64)
length, err := strconv.ParseInt(r.Header.Get("File-Size"), 10, 64)
if err != nil {
log.Error().Msg("File-Size header not present")
w.WriteHeader(http.StatusBadRequest)
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ocm/share/manager/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ func (m *mgr) Share(ctx context.Context, md *provider.ResourceId, g *ocm.ShareGr
return nil, errors.New("json: owner of resource not provided")
}
userID = owner
id += ":" + name
} else {
userID = user.ContextMustGetUser(ctx).GetId()
}
Expand Down Expand Up @@ -244,6 +243,7 @@ func (m *mgr) Share(ctx context.Context, md *provider.ResourceId, g *ocm.ShareGr
Id: &ocm.ShareId{
OpaqueId: id,
},
Name: name,
ResourceId: md,
Permissions: g.Permissions,
Grantee: g.Grantee,
Expand Down
2 changes: 1 addition & 1 deletion pkg/ocm/share/manager/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ func (m *mgr) Share(ctx context.Context, md *provider.ResourceId, g *ocm.ShareGr
return nil, errors.New("json: owner of resource not provided")
}
userID = owner
id += ":" + name
} else {
userID = user.ContextMustGetUser(ctx).GetId()
}
Expand Down Expand Up @@ -153,6 +152,7 @@ func (m *mgr) Share(ctx context.Context, md *provider.ResourceId, g *ocm.ShareGr
Id: &ocm.ShareId{
OpaqueId: id,
},
Name: name,
ResourceId: md,
Permissions: g.Permissions,
Grantee: g.Grantee,
Expand Down
6 changes: 5 additions & 1 deletion pkg/smtpclient/smtpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (

// SMTPCredentials stores the credentials required to connect to an SMTP server.
type SMTPCredentials struct {
SenderLogin string `mapstructure:"sender_login" docs:";The login to be used by sender."`
SenderMail string `mapstructure:"sender_mail" docs:";The email to be used to send mails."`
SenderPassword string `mapstructure:"sender_password" docs:";The sender's password."`
SMTPServer string `mapstructure:"smtp_server" docs:";The hostname of the SMTP server."`
Expand All @@ -55,6 +56,9 @@ func NewSMTPCredentials(c *SMTPCredentials) *SMTPCredentials {
tokens := strings.Split(creds.SenderMail, "@")
creds.LocalName = tokens[len(tokens)-1]
}
if creds.SenderLogin == "" {
creds.SenderLogin = creds.SenderMail
}
return creds
}

Expand Down Expand Up @@ -86,7 +90,7 @@ func (creds *SMTPCredentials) SendMail(recipient, subject, body string) error {

func (creds *SMTPCredentials) sendMailAuthSMTP(recipient, subject, message string) error {

auth := smtp.PlainAuth("", creds.SenderMail, creds.SenderPassword, creds.SMTPServer)
auth := smtp.PlainAuth("", creds.SenderLogin, creds.SenderPassword, creds.SMTPServer)

err := smtp.SendMail(
fmt.Sprintf("%s:%d", creds.SMTPServer, creds.SMTPPort),
Expand Down

0 comments on commit 4a9b7d7

Please sign in to comment.