From ff41ff256b1b956603cbef698937d380bbb6c5d8 Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Wed, 8 Jul 2020 12:27:09 +0200 Subject: [PATCH 1/3] Read SMTP password from env if not set in config --- internal/http/services/ocmd/invites.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/http/services/ocmd/invites.go b/internal/http/services/ocmd/invites.go index b25690da3f..2417a9c61b 100644 --- a/internal/http/services/ocmd/invites.go +++ b/internal/http/services/ocmd/invites.go @@ -23,6 +23,7 @@ import ( "errors" "fmt" "net/http" + "os" userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1" invitepb "github.com/cs3org/go-cs3apis/cs3/ocm/invite/v1beta1" @@ -44,6 +45,9 @@ type invitesHandler struct { func (h *invitesHandler) init(c *Config) { h.gatewayAddr = c.GatewaySvc h.smtpCredentials = c.SMTPCredentials + if h.smtpCredentials != nil && h.smtpCredentials.SenderPassword == "" { + h.smtpCredentials.SenderPassword = os.Getenv("REVA_OCMD_SMTP_SENDER_PASSWORD") + } } func (h *invitesHandler) Handler() http.Handler { @@ -83,13 +87,13 @@ func (h *invitesHandler) generateInviteToken(w http.ResponseWriter, r *http.Requ } if r.FormValue("recipient") != "" && h.smtpCredentials != nil { + usr := user.ContextMustGetUser(ctx) - username := usr.DisplayName // TODO: the message body needs to point to the meshdirectory service - subject := fmt.Sprintf("ScienceMesh: %s wants to collaborate with you", username) + subject := fmt.Sprintf("ScienceMesh: %s wants to collaborate with you", usr.DisplayName) body := "Hi,\n\n" + - username + " wants to start sharing OCM resources with you. " + + usr.DisplayName + " (" + usr.Mail + ") wants to start sharing OCM resources with you. " + "To accept the invite, please use the following details:\n" + "Token: " + token.InviteToken.Token + "\n" + "ProviderDomain: " + usr.Id.Idp + "\n\n" + From 5ce3709f5f71c27efa1fcf738d3aa97a5cca4db3 Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Wed, 8 Jul 2020 14:20:23 +0200 Subject: [PATCH 2/3] Fix bug in providerauthorizer --- pkg/ocm/provider/authorizer/json/json.go | 25 ++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/pkg/ocm/provider/authorizer/json/json.go b/pkg/ocm/provider/authorizer/json/json.go index d5887df536..9d5e21f1a6 100644 --- a/pkg/ocm/provider/authorizer/json/json.go +++ b/pkg/ocm/provider/authorizer/json/json.go @@ -58,8 +58,9 @@ func New(m map[string]interface{}) (provider.Authorizer, error) { } return &authorizer{ - providers: providers, - conf: c, + providers: providers, + providerIPs: sync.Map{}, + conf: c, }, nil } @@ -76,7 +77,7 @@ func (c *config) init() { type authorizer struct { providers []*ocmprovider.ProviderInfo - providerIPs *sync.Map + providerIPs sync.Map conf *config } @@ -111,7 +112,7 @@ func (a *authorizer) IsProviderAllowed(ctx context.Context, provider *ocmprovide return errtypes.NotSupported("No IP provided") } - ocmHost, err := getOCMHost(provider) + ocmHost, err := a.getOCMHost(provider.Domain) if err != nil { return errors.Wrap(err, "json: ocm host not specified for mesh provider") } @@ -147,12 +148,16 @@ func (a *authorizer) ListAllProviders(ctx context.Context) ([]*ocmprovider.Provi return a.providers, nil } -func getOCMHost(originProvider *ocmprovider.ProviderInfo) (string, error) { - for _, s := range originProvider.Services { - if s.Endpoint.Type.Name == "OCM" { - ocmHost := strings.TrimPrefix(s.Host, "https://") - ocmHost = strings.TrimPrefix(ocmHost, "http://") - return ocmHost, nil +func (a *authorizer) getOCMHost(providerDomain string) (string, error) { + for _, p := range a.providers { + if p.Domain == providerDomain { + for _, s := range p.Services { + if s.Endpoint.Type.Name == "OCM" { + ocmHost := strings.TrimPrefix(s.Host, "https://") + ocmHost = strings.TrimPrefix(ocmHost, "http://") + return ocmHost, nil + } + } } } return "", errtypes.NotFound("OCM Host") From 831657be00a556afe69f65678826372a39e1ed4a Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Wed, 8 Jul 2020 17:40:52 +0200 Subject: [PATCH 3/3] Use url.Parse to extract hostname --- pkg/ocm/provider/authorizer/json/json.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/ocm/provider/authorizer/json/json.go b/pkg/ocm/provider/authorizer/json/json.go index 9d5e21f1a6..29e85e4376 100644 --- a/pkg/ocm/provider/authorizer/json/json.go +++ b/pkg/ocm/provider/authorizer/json/json.go @@ -23,6 +23,7 @@ import ( "encoding/json" "io/ioutil" "net" + "net/url" "strings" "sync" @@ -153,9 +154,11 @@ func (a *authorizer) getOCMHost(providerDomain string) (string, error) { if p.Domain == providerDomain { for _, s := range p.Services { if s.Endpoint.Type.Name == "OCM" { - ocmHost := strings.TrimPrefix(s.Host, "https://") - ocmHost = strings.TrimPrefix(ocmHost, "http://") - return ocmHost, nil + ocmHost, err := url.Parse(s.Host) + if err != nil { + return "", errors.Wrap(err, "json: error parsing OCM host URL") + } + return ocmHost.Host, nil } } }