Skip to content

Commit

Permalink
Add Runstat.us (#58)
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre-Emmanuel Jacquier <[email protected]>
Signed-off-by: Yoan Blanc <[email protected]>
  • Loading branch information
pierre-emmanuelJ authored and greut committed Jan 11, 2019
1 parent 758496d commit e886eca
Show file tree
Hide file tree
Showing 35 changed files with 2,366 additions and 34 deletions.
41 changes: 25 additions & 16 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,20 @@ type config struct {
}

type account struct {
Name string
Account string
Endpoint string
ComputeEndpoint string // legacy config.
DNSEndpoint string
SosEndpoint string
Key string
Secret string
SecretCommand []string
DefaultZone string
DefaultSSHKey string
DefaultTemplate string
Name string
Account string
Endpoint string
ComputeEndpoint string // legacy config.
DNSEndpoint string
SosEndpoint string
RunstatusEndpoint string
Key string
Secret string
SecretCommand []string
DefaultZone string
DefaultSSHKey string
DefaultTemplate string
DefaultRunstatusPage string
}

func (a account) APISecret() string {
Expand All @@ -54,10 +56,11 @@ func (a account) APISecret() string {
}

const (
defaultConfigFileName = "exoscale"
defaultEndpoint = "https://api.exoscale.ch/compute"
defaultTemplate = "Linux Ubuntu 18.04 LTS 64-bit"
defaultSosEndpoint = "https://sos-{zone}.exo.io"
defaultConfigFileName = "exoscale"
defaultEndpoint = "https://api.exoscale.ch/compute"
defaultTemplate = "Linux Ubuntu 18.04 LTS 64-bit"
defaultSosEndpoint = "https://sos-{zone}.exo.io"
defaultRunstatusEndpoint = "https://api.runstatus.com"
)

// configCmd represents the config command
Expand Down Expand Up @@ -281,6 +284,9 @@ func addAccount(filePath string, newAccounts *config) error {
if acc.DefaultSSHKey != "" {
accounts[i]["defaultSSHKey"] = acc.DefaultSSHKey
}
if acc.DefaultRunstatusPage != "" {
accounts[i]["defaultRunstatusPage"] = acc.DefaultRunstatusPage
}
if acc.DefaultTemplate != "" {
accounts[i]["defaultTemplate"] = acc.DefaultTemplate
}
Expand Down Expand Up @@ -308,6 +314,9 @@ func addAccount(filePath string, newAccounts *config) error {
if acc.DefaultSSHKey != "" {
accounts[accountsSize+i]["defaultSSHKey"] = acc.DefaultSSHKey
}
if acc.DefaultRunstatusPage != "" {
accounts[accountsSize+i]["defaultRunstatusPage"] = acc.DefaultRunstatusPage
}
accounts[accountsSize+i]["account"] = acc.Account
conf.Accounts = append(conf.Accounts, acc)
}
Expand Down
7 changes: 7 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var gAllAccount *config
//egoscale client
var cs *egoscale.Client
var csDNS *egoscale.Client
var csRunstatus *egoscale.Client

//Aliases
var gListAlias = []string{"ls"}
Expand Down Expand Up @@ -110,6 +111,7 @@ func buildClient() {

csDNS = egoscale.NewClient(gCurrentAccount.DNSEndpoint, gCurrentAccount.Key, gCurrentAccount.APISecret())
cs = egoscale.NewClient(gCurrentAccount.Endpoint, gCurrentAccount.Key, gCurrentAccount.APISecret())
csRunstatus = egoscale.NewClient(gCurrentAccount.RunstatusEndpoint, gCurrentAccount.Key, gCurrentAccount.APISecret())
}

// initConfig reads in config file and ENV variables if set.
Expand Down Expand Up @@ -260,9 +262,14 @@ func initConfig() {
gCurrentAccount.SosEndpoint = defaultSosEndpoint
}

if gCurrentAccount.RunstatusEndpoint == "" {
gCurrentAccount.RunstatusEndpoint = defaultRunstatusEndpoint
}

gCurrentAccount.Endpoint = strings.TrimRight(gCurrentAccount.Endpoint, "/")
gCurrentAccount.DNSEndpoint = strings.TrimRight(gCurrentAccount.DNSEndpoint, "/")
gCurrentAccount.SosEndpoint = strings.TrimRight(gCurrentAccount.SosEndpoint, "/")
gCurrentAccount.RunstatusEndpoint = strings.TrimRight(gCurrentAccount.RunstatusEndpoint, "/")
}

func isNonCredentialCmd(cmds ...string) bool {
Expand Down
17 changes: 17 additions & 0 deletions cmd/runstatus.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cmd

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

// runstatusCmd represents the runstatus command
var runstatusCmd = &cobra.Command{
Use: "runstatus",
Short: "Manage your Runstat.us pages",
Long: `Focus on building your service,
knowing that when something does go wrong you can keep everyone informed using Runstatus.`,
}

func init() {
RootCmd.AddCommand(runstatusCmd)
}
44 changes: 44 additions & 0 deletions cmd/runstatus_create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package cmd

import (
"fmt"

"github.com/exoscale/egoscale"
"github.com/spf13/cobra"
)

// runstatusCreateCmd represents the create command
var runstatusCreateCmd = &cobra.Command{
Use: "create <page name>+",
Short: "Create Runstat.us page",
Aliases: gCreateAlias,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return cmd.Usage()
}

dark, err := cmd.Flags().GetBool("dark")
if err != nil {
return err
}

for _, arg := range args {
result, err := csRunstatus.CreateRunstatusPage(gContext, egoscale.RunstatusPage{
Name: arg,
Subdomain: arg,
DarkTheme: dark,
})
if err != nil {
return err
}
fmt.Printf("Runstat.us page %q created:\n - %s\n", result.Subdomain, result.PublicURL)
}

return nil
},
}

func init() {
runstatusCmd.AddCommand(runstatusCreateCmd)
runstatusCreateCmd.Flags().BoolP("dark", "d", false, "Enable status page dark mode")
}
42 changes: 42 additions & 0 deletions cmd/runstatus_delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package cmd

import (
"fmt"

"github.com/exoscale/egoscale"

"github.com/spf13/cobra"
)

// deleteCmd represents the delete command
var runstatusDeleteCmd = &cobra.Command{
Use: "delete <page name>+",
Short: "Delete runstat.us page(s)",
Aliases: gDeleteAlias,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return cmd.Usage()
}
for _, arg := range args {
if !askQuestion(fmt.Sprintf("sure you want to delete %q runstat.us page", arg)) {
continue
}

runstatusPage, err := csRunstatus.GetRunstatusPage(gContext, egoscale.RunstatusPage{Subdomain: arg})
if err != nil {
return err
}

if err := csRunstatus.DeleteRunstatusPage(gContext, *runstatusPage); err != nil {
return err
}
fmt.Printf("Page %q successfully deleted\n", arg)
}

return nil
},
}

func init() {
runstatusCmd.AddCommand(runstatusDeleteCmd)
}
34 changes: 34 additions & 0 deletions cmd/runstatus_incident.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package cmd

import (
"strconv"

"github.com/exoscale/egoscale"
"github.com/spf13/cobra"
)

// runstatusIncidentCmd represents the incident command
var runstatusIncidentCmd = &cobra.Command{
Use: "incident",
Short: "Incident management",
}

func getIncidentByNameOrID(page egoscale.RunstatusPage, name string) (*egoscale.RunstatusIncident, error) {

incidentID := -1

id, err := strconv.Atoi(name)
if err == nil {
incidentID = id
}

if incidentID > 0 {
return csRunstatus.GetRunstatusIncident(gContext, egoscale.RunstatusIncident{PageURL: page.URL, ID: incidentID})
}

return csRunstatus.GetRunstatusIncident(gContext, egoscale.RunstatusIncident{PageURL: page.URL, Title: name})
}

func init() {
runstatusCmd.AddCommand(runstatusIncidentCmd)
}
Loading

0 comments on commit e886eca

Please sign in to comment.