Skip to content

Commit

Permalink
cmd: Adds newsletter sign up capabilities to CLI commands (#759)
Browse files Browse the repository at this point in the history
  • Loading branch information
arekkas authored Feb 5, 2018
1 parent 1b76f4b commit 049f581
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 4 deletions.
35 changes: 35 additions & 0 deletions cmd/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
"os"
"strings"

"net/http"
"net/url"

"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -54,6 +57,37 @@ var connectCmd = &cobra.Command{
} else if u := input("Client Secret [" + secret + "]: "); u != "" {
c.ClientSecret = u
}

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:")

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 == "" {
} else {
if err != nil {
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: %s\n", err.Error())
} else {
defer resp.Body.Close()

fmt.Println("To complete the subscription process, please click the link in the email you just received.")
c.SignedUpForNewsletter = true
}
}
}
}

if err := c.Persist(); err != nil {
log.Fatalf("Unable to save config file because %s.", err)
}
Expand All @@ -76,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")
}
2 changes: 1 addition & 1 deletion cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}},
Expand Down
38 changes: 38 additions & 0 deletions cmd/server/banner.go
Original file line number Diff line number Diff line change
@@ -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 <<
////////////////////
//////////// `
2 changes: 2 additions & 0 deletions cmd/server/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ func parseCorsOptions() cors.Options {

func RunHost(c *config.Config) func(cmd *cobra.Command, args []string) {
return func(cmd *cobra.Command, args []string) {
fmt.Println(banner)

router := httprouter.New()
logger := c.GetLogger()
serverHandler := &Handler{
Expand Down
7 changes: 4 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:"-"`
Expand Down

0 comments on commit 049f581

Please sign in to comment.