Skip to content

Commit

Permalink
Minor fixes in OCM shares, gateway uploads and smtpclient (#1082)
Browse files Browse the repository at this point in the history
  • Loading branch information
ishank011 authored Aug 19, 2020
1 parent 46e2c09 commit 6decf98
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 24 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ lint-ci:
gen-doc:
go run tools/generate-documentation/main.go

check-changelog:
check-changelog: release-deps
`go env GOPATH`/bin/calens > /dev/null
go run tools/check-changelog/main.go

check-changelog-drone:
Expand Down
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
47 changes: 47 additions & 0 deletions cmd/reva/configure.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2018-2020 CERN
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// In applying this license, CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.

package main

import (
"bufio"
"fmt"
"io"
"os"
)

var configureCommand = func() *command {
cmd := newCommand("configure")
cmd.Description = func() string { return "configure the reva client" }
cmd.Action = func(w ...io.Writer) error {
reader := bufio.NewReader(os.Stdin)
fmt.Print("host: ")
text, err := read(reader)
if err != nil {
return err
}

c := &config{Host: text}
if err := writeConfig(c); err != nil {
return err
}
fmt.Println("config saved at ", getConfigFile())
return nil
}
return cmd
}
11 changes: 11 additions & 0 deletions cmd/reva/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ func (e *Executor) Execute(s string) {

args := strings.Split(s, " ")

// Verify that the configuration is set, either in memory or in a file.
if conf.Host == "" {
c, err := readConfig()
if err != nil && args[0] != "configure" {
fmt.Println("reva is not configured, please run the configure command")
return
} else if args[0] != "configure" {
conf = c
}
}

action := args[0]
for _, v := range commands {
if v.Name == action {
Expand Down
10 changes: 2 additions & 8 deletions cmd/reva/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var (

commands = []*command{
versionCommand(),
configureCommand(),
loginCommand(),
whoamiCommand(),
importCommand(),
Expand Down Expand Up @@ -82,14 +83,7 @@ func init() {

func main() {

if host == "" {
c, err := readConfig()
if err != nil {
fmt.Println("reva is not configured, please pass the \"-host\" flag")
os.Exit(1)
}
conf = c
} else {
if host != "" {
conf = &config{host}
if err := writeConfig(conf); err != nil {
fmt.Println("error writing to config file")
Expand Down
20 changes: 14 additions & 6 deletions docs/content/en/docs/config/packages/smtpclient/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,56 @@ description: >

# _struct: SMTPCredentials_

{{% dir name="sender_login" type="string" default="" %}}
The login to be used by sender. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/smtpclient/smtpclient.go#L36)
{{< highlight toml >}}
[smtpclient]
sender_login = ""
{{< /highlight >}}
{{% /dir %}}

{{% dir name="sender_mail" type="string" default="" %}}
The email to be used to send mails. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/smtpclient/smtpclient.go#L36)
The email to be used to send mails. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/smtpclient/smtpclient.go#L37)
{{< highlight toml >}}
[smtpclient]
sender_mail = ""
{{< /highlight >}}
{{% /dir %}}

{{% dir name="sender_password" type="string" default="" %}}
The sender's password. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/smtpclient/smtpclient.go#L37)
The sender's password. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/smtpclient/smtpclient.go#L38)
{{< highlight toml >}}
[smtpclient]
sender_password = ""
{{< /highlight >}}
{{% /dir %}}

{{% dir name="smtp_server" type="string" default="" %}}
The hostname of the SMTP server. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/smtpclient/smtpclient.go#L38)
The hostname of the SMTP server. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/smtpclient/smtpclient.go#L39)
{{< highlight toml >}}
[smtpclient]
smtp_server = ""
{{< /highlight >}}
{{% /dir %}}

{{% dir name="smtp_port" type="int" default=587 %}}
The port on which the SMTP daemon is running. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/smtpclient/smtpclient.go#L39)
The port on which the SMTP daemon is running. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/smtpclient/smtpclient.go#L40)
{{< highlight toml >}}
[smtpclient]
smtp_port = 587
{{< /highlight >}}
{{% /dir %}}

{{% dir name="disable_auth" type="bool" default=false %}}
Whether to disable SMTP auth. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/smtpclient/smtpclient.go#L40)
Whether to disable SMTP auth. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/smtpclient/smtpclient.go#L41)
{{< highlight toml >}}
[smtpclient]
disable_auth = false
{{< /highlight >}}
{{% /dir %}}

{{% dir name="local_name" type="string" default="" %}}
The host name to be used for unauthenticated SMTP. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/smtpclient/smtpclient.go#L41)
The host name to be used for unauthenticated SMTP. [[Ref]](https://github.com/cs3org/reva/tree/master/pkg/smtpclient/smtpclient.go#L42)
{{< highlight toml >}}
[smtpclient]
local_name = ""
Expand Down
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
64 changes: 60 additions & 4 deletions examples/ocmd/users.demo.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,21 @@
"secret": "relativity",
"mail": "einstein@cern.ch",
"display_name": "Albert Einstein",
"groups": ["sailing-lovers", "violin-haters", "physics-lovers"]
"groups": ["sailing-lovers", "violin-haters", "physics-lovers"],
"opaque": {
"map": {
"gid": {
"_comment": "decodes to 987",
"decoder":"plain",
"value":"OTg3"
},
"uid":{
"_comment": "decodes to 123",
"decoder":"plain",
"value":"MTIz"
}
}
}
},
{
"id": {
Expand All @@ -19,7 +33,21 @@
"secret": "radioactivity",
"mail": "marie@cesnet.cz",
"display_name": "Marie Curie",
"groups": ["radium-lovers", "polonium-lovers", "physics-lovers"]
"groups": ["radium-lovers", "polonium-lovers", "physics-lovers"],
"opaque": {
"map": {
"gid": {
"_comment": "decodes to 987",
"decoder":"plain",
"value":"OTg3"
},
"uid":{
"_comment": "decodes to 456",
"decoder":"plain",
"value":"NDU2"
}
}
}
},
{
"id": {
Expand All @@ -30,7 +58,21 @@
"secret": "superfluidity",
"mail": "richard@example.org",
"display_name": "Richard Feynman",
"groups": ["quantum-lovers", "philosophy-haters", "physics-lovers"]
"groups": ["quantum-lovers", "philosophy-haters", "physics-lovers"],
"opaque": {
"map": {
"gid": {
"_comment": "decodes to 135",
"decoder":"plain",
"value":"MTM1"
},
"uid":{
"_comment": "decodes to 246",
"decoder":"plain",
"value":"MjQ2"
}
}
}
},
{
"id": {
Expand All @@ -41,6 +83,20 @@
"secret": "test",
"mail": "test@example.com",
"display_name": "Test Testman",
"groups": ["quantum-lovers", "philosophy-haters", "physics-lovers"]
"groups": ["quantum-lovers", "philosophy-haters", "physics-lovers"],
"opaque": {
"map": {
"gid": {
"_comment": "decodes to 135",
"decoder":"plain",
"value":"MTM1"
},
"uid":{
"_comment": "decodes to 468",
"decoder":"plain",
"value":"NDY4"
}
}
}
}
]
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 6decf98

Please sign in to comment.