Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds secure field to url list table ouput and json output. #2817

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions pkg/odo/cli/url/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make this more readable? just top of my head maybe extract url.GetURLString(url.GetProtocol(routev1.Route{}, u), "", u.Spec.Rules[0].Host) into a helper?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

url.GetURLString(url.GetProtocol(routev1.Route{}, u), "", u.Spec.Rules[0].Host)

But url.GetURLString() is already a helper function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am ok if you feel we cannot make this more clean.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried certain things but it was making things a bit complicated and weird for me.

present = true
}
}
Expand Down Expand Up @@ -116,12 +116,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"`
}

// 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: 17 additions & 1 deletion tests/integration/cmd_url_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ 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"})

helper.CmdShouldPass("odo", "delete", "-f", "--context", context)
})
})
Expand Down Expand Up @@ -128,7 +131,20 @@ var _ = Describe("odo url command tests", func() {
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":"http","port":8080},"status":{"state": "Pushed"}}]}`, pathNoHTTP)
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,"secure":false},"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))
})
})
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