Skip to content

Commit

Permalink
Read SMTP password from env if not set in config (#953)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 authored Jul 9, 2020
1 parent 64d6830 commit ad19c29
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
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

0 comments on commit ad19c29

Please sign in to comment.