forked from toolshed/abra
refactor: NewClientWithContext -> New, and use server only
This commit is contained in:
@ -76,8 +76,8 @@ var appCpCommand = &cli.Command{
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
host := appFiles[appName].Server
|
||||
cl, err := client.NewClientWithContext(host)
|
||||
server := appFiles[appName].Server
|
||||
cl, err := client.New(server)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
@ -31,8 +31,8 @@ var appDeployCommand = &cli.Command{
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
host := appFiles[appName].Server
|
||||
cl, err := client.NewClientWithContext(host)
|
||||
server := appFiles[appName].Server
|
||||
cl, err := client.New(server)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
@ -79,8 +79,8 @@ var appLogsCommand = &cli.Command{
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
host := appFiles[appName].Server
|
||||
cl, err := client.NewClientWithContext(host)
|
||||
server := appFiles[appName].Server
|
||||
cl, err := client.New(server)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
@ -29,9 +29,9 @@ var appPsCommand = &cli.Command{
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
host := appFiles[appName].Server
|
||||
server := appFiles[appName].Server
|
||||
ctx := context.Background()
|
||||
cl, err := client.NewClientWithContext(host)
|
||||
cl, err := client.New(server)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
@ -59,9 +59,9 @@ var appRemoveCommand = &cli.Command{
|
||||
}
|
||||
|
||||
appPath := appFiles[appName].Path
|
||||
host := appFiles[appName].Server
|
||||
server := appFiles[appName].Server
|
||||
ctx := context.Background()
|
||||
cl, err := client.NewClientWithContext(host)
|
||||
cl, err := client.New(server)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
@ -53,9 +53,9 @@ var appRunCommand = &cli.Command{
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
host := appFiles[appName].Server
|
||||
server := appFiles[appName].Server
|
||||
ctx := context.Background()
|
||||
cl, err := client.NewClientWithContext(host)
|
||||
cl, err := client.New(server)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ var appSecretGenerateCommand = &cli.Command{
|
||||
}
|
||||
|
||||
secretsToCreate := make(map[string]string)
|
||||
host := appFiles[appName].Server
|
||||
server := appFiles[appName].Server
|
||||
secretEnvVars := secret.ReadSecretEnvVars(appEnv.Env)
|
||||
if allSecrets {
|
||||
secretsToCreate = secretEnvVars
|
||||
@ -66,14 +66,14 @@ var appSecretGenerateCommand = &cli.Command{
|
||||
}
|
||||
}
|
||||
|
||||
secretVals, err := secret.GenerateSecrets(secretsToCreate, appEnv.StackName(), host)
|
||||
secretVals, err := secret.GenerateSecrets(secretsToCreate, appEnv.StackName(), server)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
if internal.Pass {
|
||||
for name, data := range secretVals {
|
||||
if err := secret.PassInsertSecret(data, name, appEnv.StackName(), host); err != nil {
|
||||
if err := secret.PassInsertSecret(data, name, appEnv.StackName(), server); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
||||
@ -112,14 +112,14 @@ var appSecretInsertCommand = &cli.Command{
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
host := appFiles[appName].Server
|
||||
server := appFiles[appName].Server
|
||||
secretName := fmt.Sprintf("%s_%s_%s", appEnv.StackName(), name, version)
|
||||
if err := client.StoreSecret(secretName, data, host); err != nil {
|
||||
if err := client.StoreSecret(secretName, data, server); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
if internal.Pass {
|
||||
if err := secret.PassInsertSecret(data, name, appEnv.StackName(), host); err != nil {
|
||||
if err := secret.PassInsertSecret(data, name, appEnv.StackName(), server); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
||||
@ -158,9 +158,9 @@ var appSecretRmCommand = &cli.Command{
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
host := appFiles[appName].Server
|
||||
server := appFiles[appName].Server
|
||||
ctx := context.Background()
|
||||
cl, err := client.NewClientWithContext(host)
|
||||
cl, err := client.New(server)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
@ -181,7 +181,7 @@ var appSecretRmCommand = &cli.Command{
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
if internal.Pass {
|
||||
if err := secret.PassRmSecret(parsed, appEnv.StackName(), host); err != nil {
|
||||
if err := secret.PassRmSecret(parsed, appEnv.StackName(), server); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
||||
@ -191,7 +191,7 @@ var appSecretRmCommand = &cli.Command{
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
if internal.Pass {
|
||||
if err := secret.PassRmSecret(parsed, appEnv.StackName(), host); err != nil {
|
||||
if err := secret.PassRmSecret(parsed, appEnv.StackName(), server); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
||||
@ -227,9 +227,9 @@ var appSecretLsCommand = &cli.Command{
|
||||
tableCol := []string{"Name", "Version", "Generated Name", "Created On Server"}
|
||||
table := abraFormatter.CreateTable(tableCol)
|
||||
|
||||
host := appFiles[appName].Server
|
||||
server := appFiles[appName].Server
|
||||
ctx := context.Background()
|
||||
cl, err := client.NewClientWithContext(host)
|
||||
cl, err := client.New(server)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ var appUndeployCommand = &cli.Command{
|
||||
|
||||
ctx := context.Background()
|
||||
host := appFiles[appName].Server
|
||||
cl, err := client.NewClientWithContext(host)
|
||||
cl, err := client.New(host)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
@ -13,19 +13,20 @@ import (
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func getAppsHost(appName string) string {
|
||||
// getAppServer retrieves the server of an app.
|
||||
func getAppServer(appName string) string {
|
||||
appFiles, err := config.LoadAppFiles("")
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
var host string
|
||||
var server string
|
||||
if app, ok := appFiles[appName]; ok {
|
||||
host = app.Server
|
||||
server = app.Server
|
||||
} else {
|
||||
logrus.Fatalf(`app "%s" does not exist`, appName)
|
||||
}
|
||||
return host
|
||||
return server
|
||||
}
|
||||
|
||||
var appVolumeListCommand = &cli.Command{
|
||||
@ -37,10 +38,10 @@ var appVolumeListCommand = &cli.Command{
|
||||
if appName == "" {
|
||||
internal.ShowSubcommandHelpAndError(c, errors.New("no app name provided!"))
|
||||
}
|
||||
host := getAppsHost(appName)
|
||||
|
||||
ctx := context.Background()
|
||||
volumeList, err := client.GetVolumes(ctx, host, appName)
|
||||
server := getAppServer(appName)
|
||||
volumeList, err := client.GetVolumes(ctx, server, appName)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
@ -71,9 +72,9 @@ var appVolumeRemoveCommand = &cli.Command{
|
||||
if appName == "" {
|
||||
internal.ShowSubcommandHelpAndError(c, errors.New("no app name provided!"))
|
||||
}
|
||||
host := getAppsHost(appName)
|
||||
server := getAppServer(appName)
|
||||
ctx := context.Background()
|
||||
volumeList, err := client.GetVolumes(ctx, host, appName)
|
||||
volumeList, err := client.GetVolumes(ctx, server, appName)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
@ -93,7 +94,7 @@ var appVolumeRemoveCommand = &cli.Command{
|
||||
volumesToRemove = volumeNames
|
||||
}
|
||||
|
||||
err = client.RemoveVolumes(ctx, host, volumesToRemove, internal.Force)
|
||||
err = client.RemoveVolumes(ctx, server, volumesToRemove, internal.Force)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
@ -19,21 +19,21 @@ var serverInitCommand = &cli.Command{
|
||||
Name: "init",
|
||||
Usage: "Initialise server for deploying apps",
|
||||
HideHelp: true,
|
||||
ArgsUsage: "<host>",
|
||||
ArgsUsage: "<server>",
|
||||
Description: `
|
||||
Initialise swarm mode on the target <host>.
|
||||
Initialise swarm mode on the target <server>.
|
||||
|
||||
This initialisation explicitly chooses the "single host swarm" mode which uses
|
||||
the default IPv4 address as the advertising address. This can be re-configured
|
||||
later for more advanced use cases.
|
||||
`,
|
||||
Action: func(c *cli.Context) error {
|
||||
host := c.Args().First()
|
||||
if host == "" {
|
||||
internal.ShowSubcommandHelpAndError(c, errors.New("no host provided"))
|
||||
server := c.Args().First()
|
||||
if server == "" {
|
||||
internal.ShowSubcommandHelpAndError(c, errors.New("no server provided"))
|
||||
}
|
||||
|
||||
cl, err := client.NewClientWithContext(host)
|
||||
cl, err := client.New(server)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -50,13 +50,13 @@ later for more advanced use cases.
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
ips, err := resolver.LookupIPAddr(ctx, host)
|
||||
ips, err := resolver.LookupIPAddr(ctx, server)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
if len(ips) == 0 {
|
||||
return fmt.Errorf("unable to retrieve ipv4 address for %s", host)
|
||||
return fmt.Errorf("unable to retrieve ipv4 address for %s", server)
|
||||
}
|
||||
ipv4 := ips[0].IP.To4().String()
|
||||
|
||||
|
Reference in New Issue
Block a user