Skip to content

Commit

Permalink
Adds secure field to url list table ouput and json output.
Browse files Browse the repository at this point in the history
  • Loading branch information
mik-dass committed Apr 6, 2020
1 parent fb3fa51 commit 583ee1a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
8 changes: 4 additions & 4 deletions pkg/odo/cli/url/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ func (o *URLListOptions) Run() (err error) {

log.Infof("Found the following URLs for component %v", componentName)
tabWriterURL := tabwriter.NewWriter(os.Stdout, 5, 2, 3, ' ', tabwriter.TabIndent)
fmt.Fprintln(tabWriterURL, "NAME", "\t", "URL", "\t", "PORT")
fmt.Fprintln(tabWriterURL, "NAME", "\t", "URL", "\t", "PORT", "\t", "SECURE")

// are there changes between local and cluster states?
outOfSync := false
for _, i := range localUrls {
var present bool
for _, u := range urls.Items {
if i.Name == u.Name {
fmt.Fprintln(tabWriterURL, u.Name, "\t", url.GetURLString(url.GetProtocol(routev1.Route{}, u), "", u.Spec.Rules[0].Host), "\t", u.Spec.Rules[0].IngressRuleValue.HTTP.Paths[0].Backend.ServicePort.IntVal)
fmt.Fprintln(tabWriterURL, u.Name, "\t", url.GetURLString(url.GetProtocol(routev1.Route{}, u), "", u.Spec.Rules[0].Host), "\t", u.Spec.Rules[0].IngressRuleValue.HTTP.Paths[0].Backend.ServicePort.IntVal, "\t", u.Spec.TLS != nil)
present = true
}
}
Expand Down Expand Up @@ -112,12 +112,12 @@ func (o *URLListOptions) Run() (err error) {

log.Infof("Found the following URLs for component %v in application %v:", o.Component(), o.Application)
tabWriterURL := tabwriter.NewWriter(os.Stdout, 5, 2, 3, ' ', tabwriter.TabIndent)
fmt.Fprintln(tabWriterURL, "NAME", "\t", "STATE", "\t", "URL", "\t", "PORT")
fmt.Fprintln(tabWriterURL, "NAME", "\t", "STATE", "\t", "URL", "\t", "PORT", "\t", "SECURE")

// are there changes between local and cluster states?
outOfSync := false
for _, u := range urls.Items {
fmt.Fprintln(tabWriterURL, u.Name, "\t", u.Status.State, "\t", url.GetURLString(u.Spec.Protocol, u.Spec.Host, ""), "\t", u.Spec.Port)
fmt.Fprintln(tabWriterURL, u.Name, "\t", u.Status.State, "\t", url.GetURLString(u.Spec.Protocol, u.Spec.Host, ""), "\t", u.Spec.Port, "\t", u.Spec.Secure)
if u.Status.State != url.StateTypePushed {
outOfSync = true
}
Expand Down
1 change: 1 addition & 0 deletions pkg/url/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type URLSpec struct {
Host string `json:"host,omitempty"`
Protocol string `json:"protocol,omitempty"`
Port int `json:"port,omitempty"`
Secure bool `json:"secure,omitempty"`
}

// AppList is a list of applications
Expand Down
2 changes: 1 addition & 1 deletion pkg/url/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ func getMachineReadableFormat(r routev1.Route) URL {
return URL{
TypeMeta: metav1.TypeMeta{Kind: "url", APIVersion: "odo.openshift.io/v1alpha1"},
ObjectMeta: metav1.ObjectMeta{Name: r.Labels[urlLabels.URLLabel]},
Spec: URLSpec{Host: r.Spec.Host, Port: r.Spec.Port.TargetPort.IntValue(), Protocol: GetProtocol(r, iextensionsv1.Ingress{})},
Spec: URLSpec{Host: r.Spec.Host, Port: r.Spec.Port.TargetPort.IntValue(), Protocol: GetProtocol(r, iextensionsv1.Ingress{}), Secure: r.Spec.TLS != nil},
}

}
Expand Down
18 changes: 18 additions & 0 deletions tests/integration/cmd_url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ var _ = Describe("odo url command tests", func() {
Expect(secureURL).To(ContainSubstring("https:"))
helper.HttpWaitFor(secureURL, "Hello world from node.js!", 20, 1)

stdout := helper.CmdShouldPass("odo", "url", "list", "--context", context)
helper.MatchAllInOutput(stdout, []string{secureURL, "Pushed", "true"})

stdout = helper.CmdShouldPass("odo", "url", "list", "--context", context, "-o", "json")

helper.CmdShouldPass("odo", "delete", "-f", "--context", context)
})
})
Expand Down Expand Up @@ -131,6 +136,19 @@ var _ = Describe("odo url command tests", func() {
desiredURLListJSON := fmt.Sprintf(`{"kind":"List","apiVersion":"odo.openshift.io/v1alpha1","metadata":{},"items":[{"kind":"url","apiVersion":"odo.openshift.io/v1alpha1","metadata":{"name":"myurl","creationTimestamp":null},"spec":{"host":"%s","protocol":"http","port":8080},"status":{"state": "Pushed"}}]}`, pathNoHTTP)
Expect(desiredURLListJSON).Should(MatchJSON(actualURLListJSON))
})

It("should be able to list url in machine readable json format for a secure url", func() {
helper.CmdShouldPass("odo", "create", "nodejs", "nodejs", "--app", "myapp", "--project", project, "--git", "https://github.com/openshift/nodejs-ex")
helper.CmdShouldPass("odo", "url", "create", "myurl", "--secure")
helper.CmdShouldPass("odo", "push")

// odo url list -o json
actualURLListJSON := helper.CmdShouldPass("odo", "url", "list", "-o", "json")
fullURLPath := helper.DetermineRouteURL("")
pathNoHTTP := strings.Split(fullURLPath, "//")[1]
desiredURLListJSON := fmt.Sprintf(`{"kind":"List","apiVersion":"odo.openshift.io/v1alpha1","metadata":{},"items":[{"kind":"url","apiVersion":"odo.openshift.io/v1alpha1","metadata":{"name":"myurl","creationTimestamp":null},"spec":{"host":"%s","protocol":"https","port":8080,"secure":true},"status":{"state": "Pushed"}}]}`, pathNoHTTP)
Expect(desiredURLListJSON).Should(MatchJSON(actualURLListJSON))
})
})

Context("when using --now flag with url create / delete", func() {
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/devfile/cmd_devfile_url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ var _ = Describe("odo devfile url command tests", func() {
helper.CmdShouldPass("odo", "url", "create", url1, "--port", "9090", "--host", host, "--secure")
stdout = helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--namespace", namespace)
helper.MatchAllInOutput(stdout, []string{"https:", url1 + "." + host})
stdout = helper.CmdShouldPass("odo", "url", "list")
helper.MatchAllInOutput(stdout, []string{"https:", url1 + "." + host, "true"})
helper.CmdShouldPass("odo", "url", "delete", url1, "-f")
helper.CmdShouldPass("odo", "push", "--devfile", "devfile.yaml", "--namespace", namespace)
stdout = helper.CmdShouldFail("odo", "url", "list")
Expand Down

0 comments on commit 583ee1a

Please sign in to comment.