Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] CLI #16

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@

.git/
vendor/
statuspage
statuspage
4 changes: 2 additions & 2 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ pipeline:
commands:
- go get -u github.com/golang/dep/cmd/dep
- /go/bin/dep ensure
- go test . ./src/...
- go build
- go test . ./pkg/...
- go build
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
.glide/

vendor/
statuspage
statuspage
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ RUN set -e \
&& dep ensure \
&& go build

CMD ["./statuspage"]
CMD ["./statuspage", "server"]
94 changes: 92 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,18 @@ We use environment variables for configuration, this also includes the logo.
## Configuration

We use environment variables to configure the service. The table bellow contains
all variables you can use.
all variables you can use. It's also possible to configure the service using
flags, camelCase is used here. Run `./statuspage server --help for more
information`.

|Name |Description|
|-----------------|-----------|
|API_TOKEN |This is the token clients should use to access the API (AUTHORIZATION header)|
|LISTEN_ADDRESS |The address the server should listen on|
|TOKEN |This is the token clients should use to access the API (AUTHORIZATION header)|
|POSTGRES_ADDRESS |The address of the postgres instance|
|POSTGRES_USER |The postgres username for authorization|
|POSTGRES_PASSWORD|The postgres password for authorization|
|POSTGRES_DB |The postgres db name|
|POSTGRES_DATABASE|The postgres db name|
|SITE_OWNER |The owner of the side, visible in page title|
|SITE_COLOR |The background color applied on the header element|
|SITE_LOGO |Custom logo, served from another site or local path inside the static folder|
Expand All @@ -35,3 +38,11 @@ Create new incident
```bash
curl -H "Authorization: 123" -v -d '{"time": "2018-01-01T13:50:00-08:00", "status":"Identified", "message":"oh no! i am broken", "Title":"User API is down"}' -H "Content-Type: application/json" -X POST http://localhost/api/incidents
```

The token used is configured on the server using the token flag or env variable.

## CLI

The statuspage binary contains a CLI tool that can be used to access the API.
For more information run `./statuspage cli --help`. Every api endpoint is
available in this tool.
16 changes: 16 additions & 0 deletions cmd/cli/incident.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package cli

import (
"github.com/spf13/cobra"
)

func init() {
}

var IncidentCmd = &cobra.Command{
Use: "incident",
Short: "Manage incidents and updates",
Run: func(cmd *cobra.Command, args []string) {

},
}
65 changes: 65 additions & 0 deletions cmd/cli/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package cli

import (
"github.com/eirsyl/statuspage/pkg/api"
"github.com/spf13/cobra"
"github.com/spf13/viper"

log "github.com/sirupsen/logrus"
)

func init() {
ServiceCmd.AddCommand(listServiceCmd)
ServiceCmd.AddCommand(createServiceCmd)
ServiceCmd.AddCommand(updateServiceCmd)
ServiceCmd.AddCommand(deleteServiceCmd)
ServiceCmd.AddCommand(getServiceCmd)
}

var ServiceCmd = &cobra.Command{
Use: "service",
Short: "Manage services",
}

var listServiceCmd = &cobra.Command{
Use: "list",
Run: func(cmd *cobra.Command, args []string) {
apiUrl, token := viper.GetString("apiUrl"), viper.GetString("token")
api, err := api.NewAPI(apiUrl, token)
if err != nil {
log.Fatal(err)
}
services, err := api.ListServices()
log.Info(services, err)
},
}

var createServiceCmd = &cobra.Command{
Use: "create",
Run: func(cmd *cobra.Command, args []string) {

},
}

var updateServiceCmd = &cobra.Command{
Use: "update [id]",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {

},
}

var deleteServiceCmd = &cobra.Command{
Use: "delete [id]",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {

},
}

var getServiceCmd = &cobra.Command{
Use: "get [id]",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
},
}
25 changes: 25 additions & 0 deletions cmd/cli_root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cmd

import (
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/eirsyl/statuspage/cmd/cli"
)

func init() {
cliCmd.PersistentFlags().StringP("apiUrl", "a", "http://127.0.0.1:8080", "The URL used to access the API")
cliCmd.PersistentFlags().StringP("token", "t", "", "The token used for authorizing with the API")
viper.BindPFlag("apiUrl", cliCmd.PersistentFlags().Lookup("apiUrl"))
viper.BindPFlag("token", cliCmd.PersistentFlags().Lookup("token"))
viper.BindEnv("apiUrl", "API_URL")
viper.BindEnv("token", "TOKEN")
cliCmd.AddCommand(cli.IncidentCmd)
cliCmd.AddCommand(cli.ServiceCmd)
RootCmd.AddCommand(cliCmd)
}

var cliCmd = &cobra.Command{
Use: "cli",
Short: "Access the statuspage api from the command line",
}
15 changes: 15 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cmd

import (
"github.com/spf13/cobra"
)

func init() {

}

var RootCmd = &cobra.Command{
Use: "statuspage",
Short: "Statuspage platform written in golang with postgres as the backing datastore.",
Long: ``,
}
Loading