From 303b450ada8abe1ce9c9385f6631f6582aae8196 Mon Sep 17 00:00:00 2001 From: zepatrik <11patti1@gmx.de> Date: Tue, 30 Jan 2018 18:35:59 +0100 Subject: [PATCH 1/5] add newsletter sign up when running hydra connect and in logs when running hydra host --- cmd/connect.go | 34 ++++++++++++++++++++++++++++++++++ cmd/server/handler.go | 2 ++ config/config.go | 7 ++++--- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/cmd/connect.go b/cmd/connect.go index 1997964f93b..8c5e63362dd 100644 --- a/cmd/connect.go +++ b/cmd/connect.go @@ -22,6 +22,8 @@ import ( "strings" "github.com/spf13/cobra" + "net/url" + "net/http" ) // connectCmd represents the connect command @@ -54,6 +56,38 @@ var connectCmd = &cobra.Command{ } else if u := input("Client Secret [" + secret + "]: "); u != "" { c.ClientSecret = u } + + if !c.SignedUpForNewsletter { + u := "https://ory.us10.list-manage.com/subscribe/post?u=ffb1a878e4ec6c0ed312a3480&id=f605a41b53" + fmt.Println("Enter your email address here to sign up for our newsletter so you never miss important security information and updates") + m := input("[enter email here]:") + + v := url.Values{} + v.Add("EMAIL", m) + + req, err := http.NewRequest("POST", u, strings.NewReader(v.Encode())) + req.Header.Add("Content-Type", "application/x-www-form-urlencoded") + + if m == "" { + c.SignedUpForNewsletter = true + } else { + if err != nil { + fmt.Printf("there was some error: %v\n", err) + } else { + resp, err := http.DefaultClient.Do(req) + + if err != nil { + fmt.Printf("there was some error: %v\n", err) + } else { + defer resp.Body.Close() + + fmt.Println("To complete the subscription process, please click the link in the email we just sent you.") + c.SignedUpForNewsletter = true + } + } + } + } + if err := c.Persist(); err != nil { log.Fatalf("Unable to save config file because %s.", err) } diff --git a/cmd/server/handler.go b/cmd/server/handler.go index 795eff8909b..8cda3ce28de 100644 --- a/cmd/server/handler.go +++ b/cmd/server/handler.go @@ -71,6 +71,8 @@ func RunHost(c *config.Config) func(cmd *cobra.Command, args []string) { serverHandler.registerRoutes(router) c.ForceHTTP, _ = cmd.Flags().GetBool("dangerous-force-http") + logger.Infoln("Have you already signed up for our newsletter to never miss any important security information and updates? If not, visit https://ory.sh now!") + if !c.ForceHTTP { if c.Issuer == "" { logger.Fatalln("Issuer must be explicitly specified unless --dangerous-force-http is passed. To find out more, use `hydra help host`.") diff --git a/config/config.go b/config/config.go index 8166a05b8e3..b410f5d6c82 100644 --- a/config/config.go +++ b/config/config.go @@ -48,9 +48,10 @@ import ( type Config struct { // These are used by client commands - ClusterURL string `mapstructure:"CLUSTER_URL" yaml:"cluster_url"` - ClientID string `mapstructure:"CLIENT_ID" yaml:"client_id,omitempty"` - ClientSecret string `mapstructure:"CLIENT_SECRET" yaml:"client_secret,omitempty"` + ClusterURL string `mapstructure:"CLUSTER_URL" yaml:"cluster_url"` + ClientID string `mapstructure:"CLIENT_ID" yaml:"client_id,omitempty"` + ClientSecret string `mapstructure:"CLIENT_SECRET" yaml:"client_secret,omitempty"` + SignedUpForNewsletter bool `yaml:"signed_up_for_newsletter,omitempty"` // These are used by the host command BindPort int `mapstructure:"PORT" yaml:"-"` From db04af3f3e97baa12783d925ea8b3bc01c5d23e8 Mon Sep 17 00:00:00 2001 From: zepatrik <11patti1@gmx.de> Date: Tue, 30 Jan 2018 18:57:30 +0100 Subject: [PATCH 2/5] add ascii logo --- cmd/server/handler.go | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/cmd/server/handler.go b/cmd/server/handler.go index a01c4d2db09..a051444df8b 100644 --- a/cmd/server/handler.go +++ b/cmd/server/handler.go @@ -62,6 +62,43 @@ func parseCorsOptions() cors.Options { func RunHost(c *config.Config) func(cmd *cobra.Command, args []string) { return func(cmd *cobra.Command, args []string) { + fmt.Println(` + //// + //////////// + //////////////////// + //////////////////////////// +/////////////// //////////////// +///////////, //////////// +/////// //////// +/// //// + + &////////////// &&&&&&&&&&&&&&@ &&&&&&&&&&&&&&&&&&&&& &&&&&&& &&&&&&&& + ////////////////////// @&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& @&&&&&&& + ////////////////////////// &&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& @&&&&&&& + //////////// //////////// &&&&&&&&&&&& &&&&&&&&&&&& &&&&&&&& &&&&&&&&& &&&&&&&& &&&&&&&& + ///////// ///////// &&&&&&&&& &&&&&&&&& &&&&&&&& &&&&&&& &&&&&&&& &&&&&&&& + //////// //////// &&&&&&&& &&&&&&&& &&&&&&&&@ &&&&&&& &&&&&&&&&&&&&& +//////// //////// &&&&&&&& @&&&&&&& &&&&&&&&& &&&&&&& &&&&&&&&&&&& +/////// /////// &&&&&&& &&&&&&& &&&&&&&& &&&&&&&&& &&&&&&&&&& +/////// /////// &&&&&&& &&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& +/////// /////// &&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& +/////// /////// &&&&&&& &&&&&&& &&&&&&&&&&&&&&&&&&&& &&&&&&&& +//////// //////// &&&&&&& &&&&&&&& &&&&&&& &&&&&&&& &&&&&&&& + //////// //////// &&&&&&&& &&&&&&&& &&&&&&& &&&&&&&& &&&&&&&& + ///////// ///////// &&&&&&&&& &&&&&&&&& &&&&&&& &&&&&&&& &&&&&&&& + ////////////% (//////////// &&&&&&&&&&&& @&&&&&&&&&&&& &&&&&&& &&&&&&&&& &&&&&&&& + ////////////////////////// &&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&& &&&&&&&& &&&&&&&& + ///////////////////// &&&&&&&&&&&&&&&&&&&&& &&&&&&& &&&&&&&& &&&&&&&& + ////////////// &&&&&&&&&&&&&& &&&&&&& &&&&&&&& &&&&&&&& + +//// //// +//////// //////// Have you already signed up for our newsletter to never miss any important +//////////// //////////// security information and updates? If not, visit https://ory.sh now! +//////////////// //////////////// + //////////////////////////// + //////////////////// + //////////// `) + router := httprouter.New() logger := c.GetLogger() serverHandler := &Handler{ @@ -71,8 +108,6 @@ func RunHost(c *config.Config) func(cmd *cobra.Command, args []string) { serverHandler.registerRoutes(router) c.ForceHTTP, _ = cmd.Flags().GetBool("dangerous-force-http") - logger.Infoln("Have you already signed up for our newsletter to never miss any important security information and updates? If not, visit https://ory.sh now!") - if !c.ForceHTTP { if c.Issuer == "" { logger.Fatalln("Issuer must be explicitly specified unless --dangerous-force-http is passed. To find out more, use `hydra help host`.") From fa77cf8b52bc61298376292a0c646c9c26678d75 Mon Sep 17 00:00:00 2001 From: arekkas Date: Sun, 4 Feb 2018 21:26:37 +0100 Subject: [PATCH 3/5] unstaged --- cmd/connect.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/connect.go b/cmd/connect.go index 8c5e63362dd..acfec5d9afa 100644 --- a/cmd/connect.go +++ b/cmd/connect.go @@ -21,9 +21,10 @@ import ( "os" "strings" - "github.com/spf13/cobra" - "net/url" "net/http" + "net/url" + + "github.com/spf13/cobra" ) // connectCmd represents the connect command From dd2e138957a0164f201d139ac594a3c754e6d129 Mon Sep 17 00:00:00 2001 From: arekkas Date: Mon, 5 Feb 2018 10:58:15 +0100 Subject: [PATCH 4/5] unstaged --- cmd/connect.go | 4 ++-- cmd/server/banner.go | 38 ++++++++++++++++++++++++++++++++++++++ cmd/server/handler.go | 37 +------------------------------------ 3 files changed, 41 insertions(+), 38 deletions(-) create mode 100644 cmd/server/banner.go diff --git a/cmd/connect.go b/cmd/connect.go index acfec5d9afa..aa523a69960 100644 --- a/cmd/connect.go +++ b/cmd/connect.go @@ -60,8 +60,8 @@ var connectCmd = &cobra.Command{ if !c.SignedUpForNewsletter { u := "https://ory.us10.list-manage.com/subscribe/post?u=ffb1a878e4ec6c0ed312a3480&id=f605a41b53" - fmt.Println("Enter your email address here to sign up for our newsletter so you never miss important security information and updates") - m := input("[enter email here]:") + fmt.Println("Never miss any security patches! Enter your email address here to sign up for our newsletter.") + m := input("Email Address:") v := url.Values{} v.Add("EMAIL", m) diff --git a/cmd/server/banner.go b/cmd/server/banner.go new file mode 100644 index 00000000000..fb1a04f9bd9 --- /dev/null +++ b/cmd/server/banner.go @@ -0,0 +1,38 @@ +package server + +var banner = ` + //// + //////////// + //////////////////// + //////////////////////////// +/////////////// //////////////// +///////////, //////////// +/////// //////// +/// //// + + &////////////// &&&&&&&&&&&&&&@ &&&&&&&&&&&&&&&&&&&&& &&&&&&& &&&&&&&& + ////////////////////// @&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& @&&&&&&& + ////////////////////////// &&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& @&&&&&&& + //////////// //////////// &&&&&&&&&&&& &&&&&&&&&&&& &&&&&&&& &&&&&&&&& &&&&&&&& &&&&&&&& + ///////// ///////// &&&&&&&&& &&&&&&&&& &&&&&&&& &&&&&&& &&&&&&&& &&&&&&&& + //////// //////// &&&&&&&& &&&&&&&& &&&&&&&&@ &&&&&&& &&&&&&&&&&&&&& +//////// //////// &&&&&&&& @&&&&&&& &&&&&&&&& &&&&&&& &&&&&&&&&&&& +/////// /////// &&&&&&& &&&&&&& &&&&&&&& &&&&&&&&& &&&&&&&&&& +/////// /////// &&&&&&& &&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& +/////// /////// &&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& +/////// /////// &&&&&&& &&&&&&& &&&&&&&&&&&&&&&&&&&& &&&&&&&& +//////// //////// &&&&&&& &&&&&&&& &&&&&&& &&&&&&&& &&&&&&&& + //////// //////// &&&&&&&& &&&&&&&& &&&&&&& &&&&&&&& &&&&&&&& + ///////// ///////// &&&&&&&&& &&&&&&&&& &&&&&&& &&&&&&&& &&&&&&&& + ////////////% (//////////// &&&&&&&&&&&& @&&&&&&&&&&&& &&&&&&& &&&&&&&&& &&&&&&&& + ////////////////////////// &&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&& &&&&&&&& &&&&&&&& + ///////////////////// &&&&&&&&&&&&&&&&&&&&& &&&&&&& &&&&&&&& &&&&&&&& + ////////////// &&&&&&&&&&&&&& &&&&&&& &&&&&&&& &&&&&&&& + +//// //// +//////// //////// Take security seriously and subscribe to the ORY newsletter. Stay on top of new patches and security +//////////// //////////// insights. +//////////////// //////////////// + //////////////////////////// >> Subscribe now: http://eepurl.com/di390P << + //////////////////// + //////////// ` diff --git a/cmd/server/handler.go b/cmd/server/handler.go index a051444df8b..83937296556 100644 --- a/cmd/server/handler.go +++ b/cmd/server/handler.go @@ -62,42 +62,7 @@ func parseCorsOptions() cors.Options { func RunHost(c *config.Config) func(cmd *cobra.Command, args []string) { return func(cmd *cobra.Command, args []string) { - fmt.Println(` - //// - //////////// - //////////////////// - //////////////////////////// -/////////////// //////////////// -///////////, //////////// -/////// //////// -/// //// - - &////////////// &&&&&&&&&&&&&&@ &&&&&&&&&&&&&&&&&&&&& &&&&&&& &&&&&&&& - ////////////////////// @&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& @&&&&&&& - ////////////////////////// &&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& @&&&&&&& - //////////// //////////// &&&&&&&&&&&& &&&&&&&&&&&& &&&&&&&& &&&&&&&&& &&&&&&&& &&&&&&&& - ///////// ///////// &&&&&&&&& &&&&&&&&& &&&&&&&& &&&&&&& &&&&&&&& &&&&&&&& - //////// //////// &&&&&&&& &&&&&&&& &&&&&&&&@ &&&&&&& &&&&&&&&&&&&&& -//////// //////// &&&&&&&& @&&&&&&& &&&&&&&&& &&&&&&& &&&&&&&&&&&& -/////// /////// &&&&&&& &&&&&&& &&&&&&&& &&&&&&&&& &&&&&&&&&& -/////// /////// &&&&&&& &&&&&&& &&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& -/////// /////// &&&&&&& &&&&&&&& &&&&&&&&&&&&&&&&&&&&&&& &&&&&&&& -/////// /////// &&&&&&& &&&&&&& &&&&&&&&&&&&&&&&&&&& &&&&&&&& -//////// //////// &&&&&&& &&&&&&&& &&&&&&& &&&&&&&& &&&&&&&& - //////// //////// &&&&&&&& &&&&&&&& &&&&&&& &&&&&&&& &&&&&&&& - ///////// ///////// &&&&&&&&& &&&&&&&&& &&&&&&& &&&&&&&& &&&&&&&& - ////////////% (//////////// &&&&&&&&&&&& @&&&&&&&&&&&& &&&&&&& &&&&&&&&& &&&&&&&& - ////////////////////////// &&&&&&&&&&&&&&&&&&&&&&&&&& &&&&&&& &&&&&&&& &&&&&&&& - ///////////////////// &&&&&&&&&&&&&&&&&&&&& &&&&&&& &&&&&&&& &&&&&&&& - ////////////// &&&&&&&&&&&&&& &&&&&&& &&&&&&&& &&&&&&&& - -//// //// -//////// //////// Have you already signed up for our newsletter to never miss any important -//////////// //////////// security information and updates? If not, visit https://ory.sh now! -//////////////// //////////////// - //////////////////////////// - //////////////////// - //////////// `) + fmt.Println(banner) router := httprouter.New() logger := c.GetLogger() From 30fd1b8def97355ad13fe0a780c877d3bb5481f4 Mon Sep 17 00:00:00 2001 From: arekkas Date: Mon, 5 Feb 2018 15:26:34 +0100 Subject: [PATCH 5/5] unstaged --- cmd/connect.go | 10 +++++----- cmd/root_test.go | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cmd/connect.go b/cmd/connect.go index aa523a69960..9f22e6150d5 100644 --- a/cmd/connect.go +++ b/cmd/connect.go @@ -58,7 +58,7 @@ var connectCmd = &cobra.Command{ c.ClientSecret = u } - if !c.SignedUpForNewsletter { + if skipNewsletter, _ := cmd.Flags().GetBool("skip-newsletter"); !c.SignedUpForNewsletter && !skipNewsletter { u := "https://ory.us10.list-manage.com/subscribe/post?u=ffb1a878e4ec6c0ed312a3480&id=f605a41b53" fmt.Println("Never miss any security patches! Enter your email address here to sign up for our newsletter.") m := input("Email Address:") @@ -70,19 +70,18 @@ var connectCmd = &cobra.Command{ req.Header.Add("Content-Type", "application/x-www-form-urlencoded") if m == "" { - c.SignedUpForNewsletter = true } else { if err != nil { - fmt.Printf("there was some error: %v\n", err) + fmt.Printf("There was some error: %s\n", err.Error()) } else { resp, err := http.DefaultClient.Do(req) if err != nil { - fmt.Printf("there was some error: %v\n", err) + fmt.Printf("There was some error: %s\n", err.Error()) } else { defer resp.Body.Close() - fmt.Println("To complete the subscription process, please click the link in the email we just sent you.") + fmt.Println("To complete the subscription process, please click the link in the email you just received.") c.SignedUpForNewsletter = true } } @@ -111,4 +110,5 @@ func init() { connectCmd.Flags().String("url", "", "The cluster URL") connectCmd.Flags().String("id", "", "The client id") connectCmd.Flags().String("secret", "", "The client secret") + connectCmd.Flags().Bool("skip-newsletter", false, "Skip the newsletter sign up question") } diff --git a/cmd/root_test.go b/cmd/root_test.go index 9ac4422e742..3bd202287fc 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -54,7 +54,7 @@ func TestExecute(t *testing.T) { return err != nil }, }, - {args: []string{"connect", "--id", "admin", "--secret", "pw", "--url", "https://127.0.0.1:4444"}}, + {args: []string{"connect", "--skip-newsletter", "--id", "admin", "--secret", "pw", "--url", "https://127.0.0.1:4444"}}, {args: []string{"clients", "create", "--id", "foobarbaz"}}, {args: []string{"clients", "get", "foobarbaz"}}, {args: []string{"clients", "create", "--id", "public-foo", "--is-public"}},