From 6decf98fca849f945087a37cc90a6af855d6e66a Mon Sep 17 00:00:00 2001 From: Ishank Arora Date: Wed, 19 Aug 2020 14:31:24 +0200 Subject: [PATCH] Minor fixes in OCM shares, gateway uploads and smtpclient (#1082) --- Makefile | 3 +- changelog/unreleased/ocm-fixes.md | 3 + cmd/reva/configure.go | 47 ++++++++++++++ cmd/reva/executor.go | 11 ++++ cmd/reva/main.go | 10 +-- .../docs/config/packages/smtpclient/_index.md | 20 ++++-- examples/ocmd/ocmd-server-1.toml | 2 - examples/ocmd/ocmd-server-2.toml | 2 - examples/ocmd/users.demo.json | 64 +++++++++++++++++-- pkg/smtpclient/smtpclient.go | 6 +- 10 files changed, 144 insertions(+), 24 deletions(-) create mode 100644 changelog/unreleased/ocm-fixes.md create mode 100644 cmd/reva/configure.go diff --git a/Makefile b/Makefile index a23ea23c79..1c4a41517a 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/changelog/unreleased/ocm-fixes.md b/changelog/unreleased/ocm-fixes.md new file mode 100644 index 0000000000..b653a55470 --- /dev/null +++ b/changelog/unreleased/ocm-fixes.md @@ -0,0 +1,3 @@ +Bugfix: Minor fixes in OCM shares, gateway uploads and smtpclient + +https://github.com/cs3org/reva/pull/1082 diff --git a/cmd/reva/configure.go b/cmd/reva/configure.go new file mode 100644 index 0000000000..04b009299a --- /dev/null +++ b/cmd/reva/configure.go @@ -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 +} diff --git a/cmd/reva/executor.go b/cmd/reva/executor.go index 996cf8c5c9..0fab5e92a6 100644 --- a/cmd/reva/executor.go +++ b/cmd/reva/executor.go @@ -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 { diff --git a/cmd/reva/main.go b/cmd/reva/main.go index 25020aaf73..ae85318b09 100644 --- a/cmd/reva/main.go +++ b/cmd/reva/main.go @@ -39,6 +39,7 @@ var ( commands = []*command{ versionCommand(), + configureCommand(), loginCommand(), whoamiCommand(), importCommand(), @@ -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") diff --git a/docs/content/en/docs/config/packages/smtpclient/_index.md b/docs/content/en/docs/config/packages/smtpclient/_index.md index 31839cfdbc..6b1c40b59a 100644 --- a/docs/content/en/docs/config/packages/smtpclient/_index.md +++ b/docs/content/en/docs/config/packages/smtpclient/_index.md @@ -8,8 +8,16 @@ 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 = "" @@ -17,7 +25,7 @@ sender_mail = "" {{% /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 = "" @@ -25,7 +33,7 @@ sender_password = "" {{% /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 = "" @@ -33,7 +41,7 @@ smtp_server = "" {{% /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 @@ -41,7 +49,7 @@ smtp_port = 587 {{% /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 @@ -49,7 +57,7 @@ disable_auth = false {{% /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 = "" diff --git a/examples/ocmd/ocmd-server-1.toml b/examples/ocmd/ocmd-server-1.toml index 5de60fd4da..e3acf144ea 100644 --- a/examples/ocmd/ocmd-server-1.toml +++ b/examples/ocmd/ocmd-server-1.toml @@ -1,5 +1,4 @@ [shared] -jwt_secret = "Pive-Fumkiu4" gatewaysvc = "localhost:19000" [grpc] @@ -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] diff --git a/examples/ocmd/ocmd-server-2.toml b/examples/ocmd/ocmd-server-2.toml index 1b306b8152..6b7baeacda 100644 --- a/examples/ocmd/ocmd-server-2.toml +++ b/examples/ocmd/ocmd-server-2.toml @@ -1,5 +1,4 @@ [shared] -jwt_secret = "Pive-Fumkiu4" gatewaysvc = "localhost:17000" [grpc] @@ -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] diff --git a/examples/ocmd/users.demo.json b/examples/ocmd/users.demo.json index a32b9da7d0..21479c1ec7 100644 --- a/examples/ocmd/users.demo.json +++ b/examples/ocmd/users.demo.json @@ -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": { @@ -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": { @@ -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": { @@ -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" + } + } + } } ] diff --git a/pkg/smtpclient/smtpclient.go b/pkg/smtpclient/smtpclient.go index 6ca85170b4..4da59fe23e 100644 --- a/pkg/smtpclient/smtpclient.go +++ b/pkg/smtpclient/smtpclient.go @@ -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."` @@ -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 } @@ -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),