Skip to content

Commit 51a2103

Browse files
author
Matthew Fisher
authored
Merge pull request #156 from bacongobbler/routable-flag
feat(cmd): add deis routing
2 parents 6745e75 + 7b4c48d commit 51a2103

5 files changed

Lines changed: 202 additions & 10 deletions

File tree

cmd/routing.go

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/deis/controller-sdk-go/api"
7+
"github.com/deis/controller-sdk-go/config"
8+
)
9+
10+
func RoutingInfo(appID string) error {
11+
s, appID, err := load(appID)
12+
13+
if err != nil {
14+
return err
15+
}
16+
17+
config, err := config.List(s.Client, appID)
18+
if checkAPICompatibility(s.Client, err) != nil {
19+
return err
20+
}
21+
22+
if config.Routable {
23+
fmt.Println("Routing is enabled.")
24+
} else {
25+
fmt.Println("Routing is disabled.")
26+
}
27+
return nil
28+
}
29+
30+
// RoutingEnable enables an app from being exposed by the router.
31+
func RoutingEnable(appID string) error {
32+
s, appID, err := load(appID)
33+
34+
if err != nil {
35+
return err
36+
}
37+
38+
fmt.Printf("Enabling routing for %s... ", appID)
39+
40+
quit := progress()
41+
_, err = config.Set(s.Client, appID, api.Config{Routable: true})
42+
43+
quit <- true
44+
<-quit
45+
46+
if err != nil {
47+
return err
48+
}
49+
50+
fmt.Print("done\n\n")
51+
return nil
52+
}
53+
54+
// RoutingDisable disables an app from being exposed by the router.
55+
func RoutingDisable(appID string) error {
56+
s, appID, err := load(appID)
57+
58+
if err != nil {
59+
return err
60+
}
61+
62+
fmt.Printf("Disabling routing for %s... ", appID)
63+
64+
quit := progress()
65+
_, err = config.Set(s.Client, appID, api.Config{Routable: false})
66+
67+
quit <- true
68+
<-quit
69+
70+
if err != nil {
71+
return err
72+
}
73+
74+
fmt.Print("done\n\n")
75+
return nil
76+
}

deis.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Subcommands, use 'deis help [subcommand]' to learn more::
5151
ps manage processes inside an app container
5252
registry manage private registry information for your application
5353
releases manage releases of an application
54+
routing manage routability of an application
5455
tags manage tags for application containers
5556
users manage users
5657
version display client version
@@ -117,6 +118,8 @@ Use 'git push deis master' to deploy to an application.
117118
err = parser.Registry(argv)
118119
case "releases":
119120
err = parser.Releases(argv)
121+
case "routing":
122+
err = parser.Routing(argv)
120123
case "shortcuts":
121124
err = parser.Shortcuts(argv)
122125
case "tags":

glide.lock

Lines changed: 22 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

glide.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ import:
1616
- package: github.com/olekukonko/tablewriter
1717
- package: github.com/arschles/assert
1818
- package: github.com/deis/controller-sdk-go
19-
version: 09f8465bf5598f84987734082d22f4201632a320
19+
version: cd0f563b127736127e0e9debeddcbcb014621b04

parser/routing.go

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package parser
2+
3+
import (
4+
"github.com/deis/workflow-cli/cmd"
5+
docopt "github.com/docopt/docopt-go"
6+
)
7+
8+
// Routing displays all relevant commands for `deis routing`.
9+
func Routing(argv []string) error {
10+
usage := `
11+
Valid commands for routing:
12+
13+
routing:info view routability of an application
14+
routing:enable enable routing for an app
15+
routing:disable disable routing for an app
16+
17+
Use 'deis help [command]' to learn more.
18+
`
19+
20+
switch argv[0] {
21+
case "routing:info":
22+
return routingInfo(argv)
23+
case "routing:enable":
24+
return routingEnable(argv)
25+
case "routing:disable":
26+
return routingDisable(argv)
27+
default:
28+
if printHelp(argv, usage) {
29+
return nil
30+
}
31+
32+
if argv[0] == "routing" {
33+
argv[0] = "routing:info"
34+
return routingInfo(argv)
35+
}
36+
37+
PrintUsage()
38+
return nil
39+
}
40+
}
41+
42+
func routingInfo(argv []string) error {
43+
usage := `
44+
Prints info about the current application's routability.
45+
46+
Usage: deis routing:info [options]
47+
48+
Options:
49+
-a --app=<app>
50+
the uniquely identifiable name for the application.
51+
`
52+
53+
args, err := docopt.Parse(usage, argv, true, "", false, true)
54+
55+
if err != nil {
56+
return err
57+
}
58+
59+
return cmd.RoutingInfo(safeGetValue(args, "--app"))
60+
}
61+
62+
func routingEnable(argv []string) error {
63+
usage := `
64+
Enables routability for an app.
65+
66+
Usage: deis routing:enable [options]
67+
68+
Options:
69+
-a --app=<app>
70+
the uniquely identifiable name of the application.
71+
`
72+
73+
args, err := docopt.Parse(usage, argv, true, "", false, true)
74+
75+
if err != nil {
76+
return err
77+
}
78+
79+
return cmd.RoutingEnable(safeGetValue(args, "--app"))
80+
}
81+
82+
func routingDisable(argv []string) error {
83+
usage := `
84+
Disables routability for an app.
85+
86+
Usage: deis routing:disable [options]
87+
88+
Options:
89+
-a --app=<app>
90+
the uniquely identifiable name of the application.
91+
`
92+
93+
args, err := docopt.Parse(usage, argv, true, "", false, true)
94+
95+
if err != nil {
96+
return err
97+
}
98+
99+
return cmd.RoutingDisable(safeGetValue(args, "--app"))
100+
}

0 commit comments

Comments
 (0)