Removed enterprise CLI features

This commit is contained in:
Laszlo Fogas 2019-04-07 21:04:24 +02:00
parent d41001f761
commit 9bb3e8384d
13 changed files with 0 additions and 614 deletions

View file

@ -1,14 +0,0 @@
package autoscale
import "github.com/urfave/cli"
// Command exports the user command set.
var Command = cli.Command{
Name: "autoscale",
Usage: "manage autoscaling",
Subcommands: []cli.Command{
autoscalePauseCmd,
autoscaleResumeCmd,
autoscaleVersionCmd,
},
}

View file

@ -1,21 +0,0 @@
package autoscale
import (
"github.com/urfave/cli"
"github.com/laszlocph/drone-oss-08/cli/drone/internal"
)
var autoscalePauseCmd = cli.Command{
Name: "pause",
Usage: "pause the autoscaler",
Action: autoscalePause,
}
func autoscalePause(c *cli.Context) error {
client, err := internal.NewAutoscaleClient(c)
if err != nil {
return err
}
return client.AutoscalePause()
}

View file

@ -1,21 +0,0 @@
package autoscale
import (
"github.com/urfave/cli"
"github.com/laszlocph/drone-oss-08/cli/drone/internal"
)
var autoscaleResumeCmd = cli.Command{
Name: "resume",
Usage: "resume the autoscaler",
Action: autoscaleResume,
}
func autoscaleResume(c *cli.Context) error {
client, err := internal.NewAutoscaleClient(c)
if err != nil {
return err
}
return client.AutoscaleResume()
}

View file

@ -1,47 +0,0 @@
package autoscale
import (
"os"
"text/template"
"github.com/urfave/cli"
"github.com/laszlocph/drone-oss-08/cli/drone/internal"
)
var autoscaleVersionCmd = cli.Command{
Name: "version",
Usage: "server version",
Action: autoscaleVersion,
Flags: []cli.Flag{
cli.StringFlag{
Name: "format",
Usage: "format output",
Value: tmplAutoscaleVersion,
Hidden: true,
},
},
}
func autoscaleVersion(c *cli.Context) error {
client, err := internal.NewAutoscaleClient(c)
if err != nil {
return err
}
version, err := client.AutoscaleVersion()
if err != nil {
return err
}
tmpl, err := template.New("_").Parse(c.String("format") + "\n")
if err != nil {
return err
}
return tmpl.Execute(os.Stdout, version)
}
var tmplAutoscaleVersion = `Version: {{ .Version }}
Commit: {{ .Commit }}
Source: {{ .Source }}
`

View file

@ -71,22 +71,6 @@ func NewClient(c *cli.Context) (drone.Client, error) {
return drone.NewClient(server, auther), nil return drone.NewClient(server, auther), nil
} }
// NewAutoscaleClient returns a new client from the CLI context.
func NewAutoscaleClient(c *cli.Context) (drone.Client, error) {
client, err := NewClient(c)
if err != nil {
return nil, err
}
autoscaler := c.GlobalString("autoscaler")
if autoscaler == "" {
return nil, fmt.Errorf("Please provide the autoscaler address")
}
client.SetAddress(
strings.TrimSuffix(autoscaler, "/"),
)
return client, nil
}
// ParseRepo parses the repository owner and name from a string. // ParseRepo parses the repository owner and name from a string.
func ParseRepo(str string) (user, repo string, err error) { func ParseRepo(str string) (user, repo string, err error) {
var parts = strings.Split(str, "/") var parts = strings.Split(str, "/")

View file

@ -4,7 +4,6 @@ import (
"fmt" "fmt"
"os" "os"
"github.com/laszlocph/drone-oss-08/cli/drone/autoscale"
"github.com/laszlocph/drone-oss-08/cli/drone/build" "github.com/laszlocph/drone-oss-08/cli/drone/build"
"github.com/laszlocph/drone-oss-08/cli/drone/deploy" "github.com/laszlocph/drone-oss-08/cli/drone/deploy"
"github.com/laszlocph/drone-oss-08/cli/drone/exec" "github.com/laszlocph/drone-oss-08/cli/drone/exec"
@ -13,7 +12,6 @@ import (
"github.com/laszlocph/drone-oss-08/cli/drone/registry" "github.com/laszlocph/drone-oss-08/cli/drone/registry"
"github.com/laszlocph/drone-oss-08/cli/drone/repo" "github.com/laszlocph/drone-oss-08/cli/drone/repo"
"github.com/laszlocph/drone-oss-08/cli/drone/secret" "github.com/laszlocph/drone-oss-08/cli/drone/secret"
"github.com/laszlocph/drone-oss-08/cli/drone/server"
"github.com/laszlocph/drone-oss-08/cli/drone/user" "github.com/laszlocph/drone-oss-08/cli/drone/user"
_ "github.com/joho/godotenv/autoload" _ "github.com/joho/godotenv/autoload"
@ -41,11 +39,6 @@ func main() {
Usage: "server address", Usage: "server address",
EnvVar: "DRONE_SERVER", EnvVar: "DRONE_SERVER",
}, },
cli.StringFlag{
Name: "autoscaler",
Usage: "autoscaler address",
EnvVar: "DRONE_AUTOSCALER",
},
cli.BoolFlag{ cli.BoolFlag{
Name: "skip-verify", Name: "skip-verify",
Usage: "skip ssl verfification", Usage: "skip ssl verfification",
@ -75,8 +68,6 @@ func main() {
secret.Command, secret.Command,
repo.Command, repo.Command,
user.Command, user.Command,
server.Command,
autoscale.Command,
} }
if err := app.Run(os.Args); err != nil { if err := app.Run(os.Args); err != nil {

View file

@ -1,17 +0,0 @@
package server
import "github.com/urfave/cli"
// Command exports the user command set.
var Command = cli.Command{
Name: "server",
Usage: "manage servers",
Subcommands: []cli.Command{
serverListCmd,
serverInfoCmd,
serverOpenCmd,
serverCreateCmd,
serverDestroyCmd,
serverEnvCmd,
},
}

View file

@ -1,46 +0,0 @@
package server
import (
"os"
"text/template"
"github.com/urfave/cli"
"github.com/laszlocph/drone-oss-08/cli/drone/internal"
)
var serverCreateCmd = cli.Command{
Name: "create",
Usage: "crate a new server",
Action: serverCreate,
Flags: []cli.Flag{
cli.StringFlag{
Name: "format",
Usage: "format output",
Value: tmplServerCreate,
Hidden: true,
},
},
}
func serverCreate(c *cli.Context) error {
client, err := internal.NewAutoscaleClient(c)
if err != nil {
return err
}
server, err := client.ServerCreate()
if err != nil {
return err
}
tmpl, err := template.New("_").Parse(c.String("format") + "\n")
if err != nil {
return err
}
return tmpl.Execute(os.Stdout, server)
}
var tmplServerCreate = `Name: {{ .Name }}
State: {{ .State }}
`

View file

@ -1,61 +0,0 @@
package server
import (
"fmt"
"os"
"text/template"
"github.com/urfave/cli"
"github.com/laszlocph/drone-oss-08/cli/drone/internal"
)
var serverDestroyCmd = cli.Command{
Name: "destroy",
Usage: "destroy a server",
ArgsUsage: "<servername>",
Action: serverDestroy,
Flags: []cli.Flag{
cli.StringFlag{
Name: "format",
Usage: "format output",
Value: tmplServerDestroy,
Hidden: true,
},
},
}
func serverDestroy(c *cli.Context) error {
client, err := internal.NewAutoscaleClient(c)
if err != nil {
return err
}
name := c.Args().First()
if len(name) == 0 {
return fmt.Errorf("Missing or invalid server name")
}
err = client.ServerDelete(name)
if err != nil {
return err
}
server, err := client.Server(name)
if err != nil {
return err
}
tmpl, err := template.New("_").Parse(c.String("format") + "\n")
if err != nil {
return err
}
return tmpl.Execute(os.Stdout, server)
}
var tmplServerDestroy = `Name: {{ .Name }}
Address: {{ .Address }}
Region: {{ .Region }}
Size: {{.Size}}
State: {{ .State }}
`

View file

@ -1,143 +0,0 @@
package server
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"os/user"
"path"
"text/template"
"github.com/urfave/cli"
"github.com/laszlocph/drone-oss-08/cli/drone/internal"
"github.com/drone/drone-go/drone"
)
var serverEnvCmd = cli.Command{
Name: "env",
ArgsUsage: "<servername>",
Action: serverEnv,
Flags: []cli.Flag{
cli.StringFlag{
Name: "shell",
Usage: "shell [bash, fish, powershell]",
Value: "bash",
},
cli.BoolFlag{
Name: "no-proxy",
Usage: "configure the noproxy variable",
},
cli.BoolFlag{
Name: "clear",
Usage: "clear the certificate cache",
},
},
}
func serverEnv(c *cli.Context) error {
u, err := user.Current()
if err != nil {
return err
}
name := c.Args().First()
if len(name) == 0 {
return fmt.Errorf("Missing or invalid server name")
}
home := path.Join(u.HomeDir, ".drone", "certs")
base := path.Join(home, name)
if c.Bool("clean") {
os.RemoveAll(home)
}
server := new(drone.Server)
if _, err := os.Stat(base); err == nil {
data, err := ioutil.ReadFile(path.Join(base, "server.json"))
if err != nil {
return err
}
err = json.Unmarshal(data, server)
if err != nil {
return err
}
} else {
client, err := internal.NewAutoscaleClient(c)
if err != nil {
return err
}
server, err = client.Server(name)
if err != nil {
return err
}
data, err := json.Marshal(server)
if err != nil {
return err
}
err = os.MkdirAll(base, 0755)
if err != nil {
return err
}
err = ioutil.WriteFile(path.Join(base, "server.json"), data, 0644)
if err != nil {
return err
}
err = ioutil.WriteFile(path.Join(base, "ca.pem"), server.CACert, 0644)
if err != nil {
return err
}
err = ioutil.WriteFile(path.Join(base, "cert.pem"), server.TLSCert, 0644)
if err != nil {
return err
}
err = ioutil.WriteFile(path.Join(base, "key.pem"), server.TLSKey, 0644)
if err != nil {
return err
}
}
return shellT.Execute(os.Stdout, map[string]interface{}{
"Name": server.Name,
"Address": server.Address,
"Path": base,
"Shell": c.String("shell"),
"NoProxy": c.Bool("no-proxy"),
})
}
var shellT = template.Must(template.New("_").Parse(`
{{- if eq .Shell "fish" -}}
sex -x DOCKER_TLS "1";
set -x DOCKER_TLS_VERIFY "";
set -x DOCKER_CERT_PATH {{ printf "%q" .Path }};
set -x DOCKER_HOST "tcp://{{ .Address }}:2376";
{{ if .NoProxy -}}
set -x NO_PROXY {{ printf "%q" .Address }};
{{ end }}
# Run this command to configure your shell:
# eval "$(drone server env {{ .Name }} --shell=fish)"
{{- else if eq .Shell "powershell" -}}
$Env:DOCKER_TLS = "1"
$Env:DOCKER_TLS_VERIFY = ""
$Env:DOCKER_CERT_PATH = {{ printf "%q" .Path }}
$Env:DOCKER_HOST = "tcp://{{ .Address }}:2376"
{{ if .NoProxy -}}
$Env:NO_PROXY = {{ printf "%q" .Address }}
{{ end }}
# Run this command to configure your shell:
# drone server env {{ .Name }} --shell=powershell | Invoke-Expression
{{- else -}}
export DOCKER_TLS=1
export DOCKER_TLS_VERIFY=
export DOCKER_CERT_PATH={{ .Path }}
export DOCKER_HOST=tcp://{{ .Address }}:2376
{{ if .NoProxy -}}
export NO_PROXY={{ .Address }}
{{ end }}
# Run this command to configure your shell:
# eval "$(drone server env {{ .Name }})"
{{- end }}
`))

View file

@ -1,60 +0,0 @@
package server
import (
"fmt"
"os"
"text/template"
"github.com/urfave/cli"
"github.com/laszlocph/drone-oss-08/cli/drone/internal"
)
var serverInfoCmd = cli.Command{
Name: "info",
Usage: "show server details",
ArgsUsage: "<servername>",
Action: serverInfo,
Flags: []cli.Flag{
cli.StringFlag{
Name: "format",
Usage: "format output",
Value: tmplServerInfo,
Hidden: true,
},
},
}
func serverInfo(c *cli.Context) error {
client, err := internal.NewAutoscaleClient(c)
if err != nil {
return err
}
name := c.Args().First()
if len(name) == 0 {
return fmt.Errorf("Missing or invalid server name")
}
server, err := client.Server(name)
if err != nil {
return err
}
tmpl, err := template.New("_").Parse(c.String("format") + "\n")
if err != nil {
return err
}
return tmpl.Execute(os.Stdout, server)
}
// template for server information
var tmplServerInfo = `Name: {{ .Name }}
Address: {{ .Address }}
Region: {{ .Region }}
Size: {{.Size}}
State: {{ .State }}
{{ if .Error -}}
Error: {{ .Error }}
{{ end -}}
`

View file

@ -1,110 +0,0 @@
package server
import (
"fmt"
"os"
"text/tabwriter"
"text/template"
"time"
"github.com/docker/go-units"
"github.com/urfave/cli"
"github.com/laszlocph/drone-oss-08/cli/drone/internal"
"github.com/drone/drone-go/drone"
)
var serverListCmd = cli.Command{
Name: "ls",
Usage: "list all servers",
ArgsUsage: " ",
Action: serverList,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "a",
Usage: "include stopped servers",
},
cli.BoolFlag{
Name: "l",
Usage: "list in long format",
},
cli.BoolTFlag{
Name: "H",
Usage: "include columne headers",
},
cli.StringFlag{
Name: "format",
Usage: "format output",
Value: tmplServerList,
Hidden: true,
},
cli.BoolFlag{
Name: "la",
Hidden: true,
},
},
}
func serverList(c *cli.Context) error {
client, err := internal.NewAutoscaleClient(c)
if err != nil {
return err
}
a := c.Bool("a")
l := c.Bool("l")
h := c.BoolT("H")
if c.BoolT("la") {
l = true
a = true
}
servers, err := client.ServerList()
if err != nil || len(servers) == 0 {
return err
}
if l && h {
printLong(servers, a, h)
return nil
}
tmpl, err := template.New("_").Parse(c.String("format") + "\n")
if err != nil {
return err
}
for _, server := range servers {
if !a && server.State == "stopped" {
continue
}
tmpl.Execute(os.Stdout, server)
}
return nil
}
func printLong(servers []*drone.Server, a, h bool) {
w := tabwriter.NewWriter(os.Stdout, 0, 0, 4, ' ', 0)
if h {
fmt.Fprintln(w, "Name\tAddress\tState\tCreated")
}
for _, server := range servers {
if !a && server.State == "stopped" {
continue
}
fmt.Fprintf(w, "%s\t%s\t%s\t%s ago\n",
server.Name,
server.Address,
server.State,
units.HumanDuration(
time.Now().Sub(
time.Unix(server.Created, 0),
),
),
)
}
w.Flush()
}
// template for server list items
var tmplServerList = `{{ .Name }}`

View file

@ -1,49 +0,0 @@
package server
import (
"fmt"
"net/url"
"github.com/pkg/browser"
"github.com/urfave/cli"
"github.com/laszlocph/drone-oss-08/cli/drone/internal"
)
//
// support for cadvisor was temporarily disabled, so
// this command has been hidden from the --help menu
// until available.
//
var serverOpenCmd = cli.Command{
Name: "open",
Usage: "open server dashboard",
ArgsUsage: "<servername>",
Action: serverOpen,
Hidden: true,
}
func serverOpen(c *cli.Context) error {
client, err := internal.NewAutoscaleClient(c)
if err != nil {
return err
}
name := c.Args().First()
if len(name) == 0 {
return fmt.Errorf("Missing or invalid server name")
}
server, err := client.Server(name)
if err != nil {
return err
}
uri := new(url.URL)
uri.Scheme = "http"
uri.Host = server.Address + ":8080"
uri.User = url.UserPassword("admin", server.Secret)
return browser.OpenURL(uri.String())
}