diff options
Diffstat (limited to 'cmd/ponzu')
-rw-r--r-- | cmd/ponzu/main.go | 162 | ||||
-rw-r--r-- | cmd/ponzu/options.go | 15 | ||||
-rw-r--r-- | cmd/ponzu/usage.go | 129 | ||||
-rw-r--r-- | cmd/ponzu/vendor/golang.org/x/net/context/context_test.go | 40 |
4 files changed, 191 insertions, 155 deletions
diff --git a/cmd/ponzu/main.go b/cmd/ponzu/main.go index d2e8b97..440ce70 100644 --- a/cmd/ponzu/main.go +++ b/cmd/ponzu/main.go @@ -8,7 +8,6 @@ import ( "os" "os/exec" "strings" - "time" "github.com/ponzu-cms/ponzu/system/admin" "github.com/ponzu-cms/ponzu/system/api" @@ -20,150 +19,29 @@ import ( _ "github.com/ponzu-cms/ponzu/content" ) -var year = fmt.Sprintf("%d", time.Now().Year()) - -var usageHeader = ` -$ ponzu [flags] command <params> - -Ponzu is a powerful and efficient open-source "Content-as-a-Service" system -framework and CMS. It provides automatic, free, and secure HTTP/2 over TLS -(certificates obtained via Let's Encrypt - https://letsencrypt.org), a useful -CMS and scaffolding to generate content editors, and a fast HTTP API on which -to build modern applications. - -Ponzu is released under the BSD-3-Clause license (see LICENSE). -(c) ` + year + ` Boss Sauce Creative, LLC - -COMMANDS - -` - -var usageHelp = ` -help, h (command): - - Help command will print the usage for Ponzu, or if a command is entered, it - will show only the usage for that specific command. - - Example: - $ ponzu help generate - - -` - -var usageNew = ` -new <directory>: - - Creates a 'ponzu' directory, or one by the name supplied as a parameter - immediately following the 'new' option in the $GOPATH/src directory. Note: - 'new' depends on the program 'git' and possibly a network connection. If - there is no local repository to clone from at the local machine's $GOPATH, - 'new' will attempt to clone the 'github.com/ponzu-cms/ponzu' package from - over the network. - - Example: - $ ponzu new myProject - > New ponzu project created at $GOPATH/src/myProject - - Errors will be reported, but successful commands retrun nothing. - - -` - -var usageGenerate = ` -generate, gen, g <type (,...fields)>: - - Generate a content type file with boilerplate code to implement - the editor.Editable interface. Must be given one (1) parameter of - the name of the type for the new content. The fields following a - type determine the field names and types of the content struct to - be generated. These must be in the following format: - fieldName:"T" - - Example: - $ ponzu gen review title:"string" body:"string" rating:"int" tags:"[]string" - - The command above will generate a file 'content/review.go' with boilerplate - methods, as well as struct definition, and cooresponding field tags like: - - type Review struct { - Title string ` + "`json:" + `"title"` + "`" + ` - Body string ` + "`json:" + `"body"` + "`" + ` - Rating int ` + "`json:" + `"rating"` + "`" + ` - Tags []string ` + "`json:" + `"tags"` + "`" + ` - } - - The generate command will intelligently parse more sophisticated field names - such as 'field_name' and convert it to 'FieldName' and vice versa, only where - appropriate as per common Go idioms. Errors will be reported, but successful - generate commands retrun nothing. - - -` - -var usageBuild = ` -build - - From within your Ponzu project directory, running build will copy and move - the necessary files from your workspace into the vendored directory, and - will build/compile the project to then be run. - - Example: - $ ponzu build - - Errors will be reported, but successful build commands return nothing. - -` - -var usageRun = ` -[[--port=8080] [--https]] run <service(,service)>: - - Starts the 'ponzu' HTTP server for the JSON API, Admin System, or both. - The segments, separated by a comma, describe which services to start, either - 'admin' (Admin System / CMS backend) or 'api' (JSON API), and, optionally, - if the server should utilize TLS encryption - served over HTTPS, which is - automatically managed using Let's Encrypt (https://letsencrypt.org) - - Example: - $ ponzu run - (or) - $ ponzu --port=8080 --https run admin,api - (or) - $ ponzu run admin - (or) - $ ponzu --port=8888 run api - - Defaults to '--port=8080 run admin,api' (running Admin & API on port 8080, without TLS) - - Note: - Admin and API cannot run on separate processes unless you use a copy of the - database, since the first process to open it receives a lock. If you intend - to run the Admin and API on separate processes, you must call them with the - 'ponzu' command independently. - - -` - var ( - usage = usageHeader + usageNew + usageGenerate + usageBuild + usageRun - port int - https bool + usage = usageHeader + usageNew + usageGenerate + usageBuild + usageRun + port int + https bool + devhttps bool // for ponzu internal / core development - dev bool - fork string + dev bool + fork string + gocmd string ) -func init() { +func main() { flag.Usage = func() { fmt.Println(usage) } -} -func main() { flag.IntVar(&port, "port", 8080, "port for ponzu to bind its listener") flag.BoolVar(&https, "https", false, "enable automatic TLS/SSL certificate management") + flag.BoolVar(&devhttps, "devhttps", false, "[dev environment] enable automatic TLS/SSL certificate management") flag.BoolVar(&dev, "dev", false, "modify environment for Ponzu core development") flag.StringVar(&fork, "fork", "", "modify repo source for Ponzu core development") + flag.StringVar(&gocmd, "gocmd", "go", "custom go command if using beta or new release of Go") flag.Parse() args := flag.Args() @@ -238,6 +116,10 @@ func main() { addTLS = "--https=false" } + if devhttps { + addTLS = "--devhttps" + } + var services string if len(args) > 1 { services = args[1] @@ -289,9 +171,21 @@ func main() { } } - if https { + // cannot run production HTTPS and development HTTPS together + if devhttps { + fmt.Println("Enabling self-signed HTTPS... [DEV]") + + go tls.EnableDev() + fmt.Println("Server listening on https://localhost:10443 for requests... [DEV]") + fmt.Println("----") + fmt.Println("If your browser rejects HTTPS requests, try allowing insecure connections on localhost.") + fmt.Println("on Chrome, visit chrome://flags/#allow-insecure-localhost") + + } else if https { fmt.Println("Enabling HTTPS...") - tls.Enable() + + go tls.Enable() + fmt.Println("Server listening on :443 for HTTPS requests...") } // save the port the system is listening on so internal system can make diff --git a/cmd/ponzu/options.go b/cmd/ponzu/options.go index 7e37255..1316a67 100644 --- a/cmd/ponzu/options.go +++ b/cmd/ponzu/options.go @@ -271,10 +271,17 @@ func buildPonzuServer(args []string) error { } // execute go build -o ponzu-cms cmd/ponzu/*.go - mainPath := filepath.Join(pwd, "cmd", "ponzu", "main.go") - optsPath := filepath.Join(pwd, "cmd", "ponzu", "options.go") - genPath := filepath.Join(pwd, "cmd", "ponzu", "generate.go") - build := exec.Command("go", "build", "-o", "ponzu-server", mainPath, optsPath, genPath) + buildOptions := []string{"build", "-o", "ponzu-server"} + cmdBuildFiles := []string{"main.go", "options.go", "generate.go", "usage.go"} + var cmdBuildFilePaths []string + for _, file := range cmdBuildFiles { + p := filepath.Join(pwd, "cmd", "ponzu", file) + cmdBuildFilePaths = append(cmdBuildFilePaths, p) + } + // mainPath := filepath.Join(pwd, "cmd", "ponzu", "main.go") + // optsPath := filepath.Join(pwd, "cmd", "ponzu", "options.go") + // genPath := filepath.Join(pwd, "cmd", "ponzu", "generate.go") + build := exec.Command(gocmd, append(buildOptions, cmdBuildFilePaths...)...) build.Stderr = os.Stderr build.Stdout = os.Stdout diff --git a/cmd/ponzu/usage.go b/cmd/ponzu/usage.go new file mode 100644 index 0000000..2dca46d --- /dev/null +++ b/cmd/ponzu/usage.go @@ -0,0 +1,129 @@ +package main + +import ( + "fmt" + "time" +) + +var year = fmt.Sprintf("%d", time.Now().Year()) + +var usageHeader = ` +$ ponzu [flags] command <params> + +Ponzu is a powerful and efficient open-source "Content-as-a-Service" system +framework and CMS. It provides automatic, free, and secure HTTP/2 over TLS +(certificates obtained via Let's Encrypt - https://letsencrypt.org), a useful +CMS and scaffolding to generate content editors, and a fast HTTP API on which +to build modern applications. + +Ponzu is released under the BSD-3-Clause license (see LICENSE). +(c) ` + year + ` Boss Sauce Creative, LLC + +COMMANDS + +` + +var usageHelp = ` +help, h (command): + + Help command will print the usage for Ponzu, or if a command is entered, it + will show only the usage for that specific command. + + Example: + $ ponzu help generate + + +` + +var usageNew = ` +new <directory>: + + Creates a 'ponzu' directory, or one by the name supplied as a parameter + immediately following the 'new' option in the $GOPATH/src directory. Note: + 'new' depends on the program 'git' and possibly a network connection. If + there is no local repository to clone from at the local machine's $GOPATH, + 'new' will attempt to clone the 'github.com/ponzu-cms/ponzu' package from + over the network. + + Example: + $ ponzu new myProject + > New ponzu project created at $GOPATH/src/myProject + + Errors will be reported, but successful commands retrun nothing. + + +` + +var usageGenerate = ` +generate, gen, g <type (,...fields)>: + + Generate a content type file with boilerplate code to implement + the editor.Editable interface. Must be given one (1) parameter of + the name of the type for the new content. The fields following a + type determine the field names and types of the content struct to + be generated. These must be in the following format: + fieldName:"T" + + Example: + $ ponzu gen review title:"string" body:"string" rating:"int" tags:"[]string" + + The command above will generate a file 'content/review.go' with boilerplate + methods, as well as struct definition, and cooresponding field tags like: + + type Review struct { + Title string ` + "`json:" + `"title"` + "`" + ` + Body string ` + "`json:" + `"body"` + "`" + ` + Rating int ` + "`json:" + `"rating"` + "`" + ` + Tags []string ` + "`json:" + `"tags"` + "`" + ` + } + + The generate command will intelligently parse more sophisticated field names + such as 'field_name' and convert it to 'FieldName' and vice versa, only where + appropriate as per common Go idioms. Errors will be reported, but successful + generate commands retrun nothing. + + +` + +var usageBuild = ` +build + + From within your Ponzu project directory, running build will copy and move + the necessary files from your workspace into the vendored directory, and + will build/compile the project to then be run. + + Example: + $ ponzu build + + Errors will be reported, but successful build commands return nothing. + +` + +var usageRun = ` +[[--port=8080] [--https]] run <service(,service)>: + + Starts the 'ponzu' HTTP server for the JSON API, Admin System, or both. + The segments, separated by a comma, describe which services to start, either + 'admin' (Admin System / CMS backend) or 'api' (JSON API), and, optionally, + if the server should utilize TLS encryption - served over HTTPS, which is + automatically managed using Let's Encrypt (https://letsencrypt.org) + + Example: + $ ponzu run + (or) + $ ponzu --port=8080 --https run admin,api + (or) + $ ponzu run admin + (or) + $ ponzu --port=8888 run api + + Defaults to '--port=8080 run admin,api' (running Admin & API on port 8080, without TLS) + + Note: + Admin and API cannot run on separate processes unless you use a copy of the + database, since the first process to open it receives a lock. If you intend + to run the Admin and API on separate processes, you must call them with the + 'ponzu' command independently. + + +` diff --git a/cmd/ponzu/vendor/golang.org/x/net/context/context_test.go b/cmd/ponzu/vendor/golang.org/x/net/context/context_test.go index 9554dcf..6284413 100644 --- a/cmd/ponzu/vendor/golang.org/x/net/context/context_test.go +++ b/cmd/ponzu/vendor/golang.org/x/net/context/context_test.go @@ -243,45 +243,51 @@ func testDeadline(c Context, wait time.Duration, t *testing.T) { } func TestDeadline(t *testing.T) { - c, _ := WithDeadline(Background(), time.Now().Add(100*time.Millisecond)) + t.Parallel() + const timeUnit = 500 * time.Millisecond + c, _ := WithDeadline(Background(), time.Now().Add(1*timeUnit)) if got, prefix := fmt.Sprint(c), "context.Background.WithDeadline("; !strings.HasPrefix(got, prefix) { t.Errorf("c.String() = %q want prefix %q", got, prefix) } - testDeadline(c, 200*time.Millisecond, t) + testDeadline(c, 2*timeUnit, t) - c, _ = WithDeadline(Background(), time.Now().Add(100*time.Millisecond)) + c, _ = WithDeadline(Background(), time.Now().Add(1*timeUnit)) o := otherContext{c} - testDeadline(o, 200*time.Millisecond, t) + testDeadline(o, 2*timeUnit, t) - c, _ = WithDeadline(Background(), time.Now().Add(100*time.Millisecond)) + c, _ = WithDeadline(Background(), time.Now().Add(1*timeUnit)) o = otherContext{c} - c, _ = WithDeadline(o, time.Now().Add(300*time.Millisecond)) - testDeadline(c, 200*time.Millisecond, t) + c, _ = WithDeadline(o, time.Now().Add(3*timeUnit)) + testDeadline(c, 2*timeUnit, t) } func TestTimeout(t *testing.T) { - c, _ := WithTimeout(Background(), 100*time.Millisecond) + t.Parallel() + const timeUnit = 500 * time.Millisecond + c, _ := WithTimeout(Background(), 1*timeUnit) if got, prefix := fmt.Sprint(c), "context.Background.WithDeadline("; !strings.HasPrefix(got, prefix) { t.Errorf("c.String() = %q want prefix %q", got, prefix) } - testDeadline(c, 200*time.Millisecond, t) + testDeadline(c, 2*timeUnit, t) - c, _ = WithTimeout(Background(), 100*time.Millisecond) + c, _ = WithTimeout(Background(), 1*timeUnit) o := otherContext{c} - testDeadline(o, 200*time.Millisecond, t) + testDeadline(o, 2*timeUnit, t) - c, _ = WithTimeout(Background(), 100*time.Millisecond) + c, _ = WithTimeout(Background(), 1*timeUnit) o = otherContext{c} - c, _ = WithTimeout(o, 300*time.Millisecond) - testDeadline(c, 200*time.Millisecond, t) + c, _ = WithTimeout(o, 3*timeUnit) + testDeadline(c, 2*timeUnit, t) } func TestCanceledTimeout(t *testing.T) { - c, _ := WithTimeout(Background(), 200*time.Millisecond) + t.Parallel() + const timeUnit = 500 * time.Millisecond + c, _ := WithTimeout(Background(), 2*timeUnit) o := otherContext{c} - c, cancel := WithTimeout(o, 400*time.Millisecond) + c, cancel := WithTimeout(o, 4*timeUnit) cancel() - time.Sleep(100 * time.Millisecond) // let cancelation propagate + time.Sleep(1 * timeUnit) // let cancelation propagate select { case <-c.Done(): default: |