-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cmd): command line options for services mangement.
Implementation for Service functionality
- Loading branch information
Showing
5 changed files
with
207 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/deis/pkg/prettyprint" | ||
|
||
"github.com/workato/deis-controller-sdk-go/services" | ||
) | ||
|
||
// ServicesList lists extra services for the app | ||
func (d *DeisCmd) ServicesList(appID string) error { | ||
s, appID, err := load(d.ConfigFile, appID) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
services, err := services.List(s.Client, appID) | ||
if d.checkAPICompatibility(s.Client, err) != nil { | ||
return err | ||
} | ||
|
||
d.Printf("=== %s Services\n", appID) | ||
servicesMap := make(map[string]string) | ||
if len(services) > 0 { | ||
for _, service := range services { | ||
servicesMap[service.ProcfileType] = fmt.Sprintf("%v", service.PathPattern) | ||
} | ||
d.Print(prettyprint.PrettyTabs(servicesMap, 5)) | ||
} | ||
return nil | ||
} | ||
|
||
// ServicesAdd adds a service to an app. | ||
func (d *DeisCmd) ServicesAdd(appID, procfileType string, pathPattern string) error { | ||
s, appID, err := load(d.ConfigFile, appID) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
d.Printf("Adding %s (%s) to %s... ", procfileType, pathPattern, appID) | ||
|
||
quit := progress(d.WOut) | ||
_, err = services.New(s.Client, appID, procfileType, pathPattern) | ||
quit <- true | ||
<-quit | ||
if d.checkAPICompatibility(s.Client, err) != nil { | ||
return err | ||
} | ||
|
||
d.Println("done") | ||
return nil | ||
} | ||
|
||
// ServicesRemove removes a service for procfileType registered with an app. | ||
func (d *DeisCmd) ServicesRemove(appID, procfileType string) error { | ||
s, appID, err := load(d.ConfigFile, appID) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
d.Printf("Removing %s from %s... ", procfileType, appID) | ||
|
||
quit := progress(d.WOut) | ||
err = services.Delete(s.Client, appID, procfileType) | ||
quit <- true | ||
<-quit | ||
if d.checkAPICompatibility(s.Client, err) != nil { | ||
return err | ||
} | ||
|
||
d.Println("done") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package parser | ||
|
||
import ( | ||
"github.com/workato/deis-workflow-cli/cmd" | ||
docopt "github.com/docopt/docopt-go" | ||
) | ||
|
||
// Services routes service commands to their specific function. | ||
func Services(argv []string, cmdr cmd.Commander) error { | ||
usage := ` | ||
Valid commands for services: | ||
services:add create service for an application | ||
services:list list application services | ||
services:remove remove service from an application | ||
Use 'deis help [command]' to learn more. | ||
` | ||
|
||
switch argv[0] { | ||
case "services:add": | ||
return servicesAdd(argv, cmdr) | ||
case "services:list": | ||
return servicesList(argv, cmdr) | ||
case "services:remove": | ||
return servicesRemove(argv, cmdr) | ||
default: | ||
if printHelp(argv, usage) { | ||
return nil | ||
} | ||
|
||
if argv[0] == "services" { | ||
argv[0] = "services:list" | ||
return servicesList(argv, cmdr) | ||
} | ||
|
||
PrintUsage(cmdr) | ||
return nil | ||
} | ||
} | ||
|
||
func servicesAdd(argv []string, cmdr cmd.Commander) error { | ||
usage := ` | ||
Creates extra service for an application and binds it to specific route of the main app domain | ||
Usage: deis services:add --type <procfile_type> --route <path_pattern> [options] | ||
Arguments: | ||
<procfile_type> | ||
Procfile type which should handle the request, e.g. webhooks (should be bind to the port PORT). | ||
Only single extra service per Porcfile type could be created | ||
<path_pattern> | ||
Nginx locations where route requests, one or many via comma, | ||
e.g. /webhooks/notify | ||
OR "/webhooks/notify,~ ^/users/[0-9]+/.*/webhooks/notify,/webhooks/rest" | ||
Options: | ||
-a --app=<app> | ||
the uniquely identifiable name for the application. | ||
` | ||
|
||
args, err := docopt.Parse(usage, argv, true, "", false, true) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
app := safeGetValue(args, "--app") | ||
procfileType := safeGetValue(args, "<procfile_type>") | ||
pathPattern := safeGetValue(args, "<path_pattern>") | ||
|
||
return cmdr.ServicesAdd(app, procfileType, pathPattern) | ||
} | ||
|
||
func servicesList(argv []string, cmdr cmd.Commander) error { | ||
usage := ` | ||
Lists extra services for an application | ||
Usage: deis services:list [options] | ||
Options: | ||
-a --app=<app> | ||
the uniquely identifiable name for the application. | ||
` | ||
|
||
args, err := docopt.Parse(usage, argv, true, "", false, true) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
app := safeGetValue(args, "--app") | ||
|
||
return cmdr.ServicesList(app) | ||
} | ||
|
||
func servicesRemove(argv []string, cmdr cmd.Commander) error { | ||
usage := ` | ||
Deletes specific extra service for application | ||
Usage: deis services:remove <procfile_type> [options] | ||
Arguments: | ||
<procfile_type> | ||
extra service for procfile type that should be removed | ||
Options: | ||
-a --app=<app> | ||
the uniquely identifiable name for the application. | ||
` | ||
|
||
args, err := docopt.Parse(usage, argv, true, "", false, true) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
app := safeGetValue(args, "--app") | ||
procfileType := safeGetValue(args, "<procfile_type>") | ||
|
||
return cmdr.ServicesRemove(app, procfileType) | ||
} |