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

Read SMTP password from env if not set in config #953

Merged
merged 3 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 7 additions & 3 deletions internal/http/services/ocmd/invites.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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" +
Expand Down
28 changes: 18 additions & 10 deletions pkg/ocm/provider/authorizer/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"encoding/json"
"io/ioutil"
"net"
"net/url"
"strings"
"sync"

Expand Down Expand Up @@ -58,8 +59,9 @@ func New(m map[string]interface{}) (provider.Authorizer, error) {
}

return &authorizer{
providers: providers,
conf: c,
providers: providers,
providerIPs: sync.Map{},
conf: c,
}, nil
}

Expand All @@ -76,7 +78,7 @@ func (c *config) init() {

type authorizer struct {
providers []*ocmprovider.ProviderInfo
providerIPs *sync.Map
providerIPs sync.Map
conf *config
}

Expand Down Expand Up @@ -111,7 +113,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")
}
Expand Down Expand Up @@ -147,12 +149,18 @@ 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, err := url.Parse(s.Host)
if err != nil {
return "", errors.Wrap(err, "json: error parsing OCM host URL")
}
return ocmHost.Host, nil
}
}
}
}
return "", errtypes.NotFound("OCM Host")
Expand Down