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

add localhost:9000 as a redirect URL #10895

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions pkg/bootstrap/docker/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/golang/glog"
"github.com/spf13/cobra"

kerrors "k8s.io/kubernetes/pkg/api/errors"
kclient "k8s.io/kubernetes/pkg/client/unversioned"
kclientcmd "k8s.io/kubernetes/pkg/client/unversioned/clientcmd"
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
Expand All @@ -29,6 +30,7 @@ import (
osclientcmd "github.com/openshift/origin/pkg/cmd/util/clientcmd"
dockerutil "github.com/openshift/origin/pkg/cmd/util/docker"
"github.com/openshift/origin/pkg/cmd/util/variable"
"k8s.io/kubernetes/pkg/util/sets"
)

const (
Expand All @@ -45,6 +47,9 @@ const (
initialProjectDisplay = "My Project"
initialProjectDesc = "Initial developer project"

defaultRedirectClient = "openshift-web-console"
developmentRedirectURI = "https://localhost:9000"

defaultImages = "openshift/origin-${component}:${version}"
defaultOpenShiftImage = "openshift/origin:${version}"

Expand Down Expand Up @@ -258,6 +263,9 @@ func (c *ClientStartConfig) Complete(f *osclientcmd.Factory, cmd *cobra.Command)
// Create an OpenShift configuration and start a container that uses it.
c.addTask("Starting OpenShift container", c.StartOpenShift)

// Add default redirect URI to config
c.addTask("Adding default OAuthClient redirect URIs", c.EnsureDefaultRedirectURIs)

// Install a registry
c.addTask("Installing registry", c.InstallRegistry)

Expand Down Expand Up @@ -511,6 +519,47 @@ func (c *ClientStartConfig) EnsureHostDirectories(io.Writer) error {
return c.HostHelper().EnsureVolumeShare()
}

// EnsureDefaultRedirectURIs merges a default URL to an auth client's RedirectURIs array
func (c *ClientStartConfig) EnsureDefaultRedirectURIs(out io.Writer) error {
oc, _, err := c.Clients()
if err != nil {
return nil
}

webConsoleOAuth, err := oc.OAuthClients().Get(defaultRedirectClient)
Copy link
Contributor

Choose a reason for hiding this comment

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

if the web console OAuth client doesn't exist, I would exit early, rather than error

Copy link
Contributor

Choose a reason for hiding this comment

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

if NotFound, return nil, otherwise, return err

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@liggitt Thanks for clarifying! Updated to check if err is kerrors.IsNotFound

if err != nil {
if kerrors.IsNotFound(err) {
fmt.Fprintf(out, "Unable to find OAuthClient %q\n", defaultRedirectClient)
return nil
}

// announce fetch error without interrupting remaining tasks
suggestedCmd := fmt.Sprintf("oc patch %s/%s -p '{%q:[%q]}'", "oauthclient", defaultRedirectClient, "redirectURIs", developmentRedirectURI)
errMsg := fmt.Sprintf("Unable to fetch OAuthClient %q.\nTo manually add a development redirect URI, run %q\n", defaultRedirectClient, suggestedCmd)
fmt.Fprintf(out, "%s\n", errMsg)
return nil
}

// ensure the default redirect URI is not already present
redirects := sets.NewString(webConsoleOAuth.RedirectURIs...)
if redirects.Has(developmentRedirectURI) {
return nil
}

webConsoleOAuth.RedirectURIs = append(webConsoleOAuth.RedirectURIs, developmentRedirectURI)

_, err = oc.OAuthClients().Update(webConsoleOAuth)
if err != nil {
// announce error without interrupting remaining tasks
suggestedCmd := fmt.Sprintf("oc patch %s/%s -p '{%q:[%q]}'", "oauthclient", defaultRedirectClient, "redirectURIs", developmentRedirectURI)
errMsg := fmt.Sprintf("Unable to add development redirect URI to the %q OAuthClient.\nTo manually add it, run %q\n", defaultRedirectClient, suggestedCmd)
fmt.Fprintf(out, "%s\n", errMsg)
return nil
}

return nil
}

// CheckAvailablePorts ensures that ports used by OpenShift are available on the Docker host
func (c *ClientStartConfig) CheckAvailablePorts(out io.Writer) error {
err := c.OpenShiftHelper().TestPorts(openshift.DefaultPorts)
Expand Down
7 changes: 7 additions & 0 deletions pkg/client/oauthclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type OAuthClientInterface interface {
Get(name string) (*oauthapi.OAuthClient, error)
Delete(name string) error
Watch(opts kapi.ListOptions) (watch.Interface, error)
Update(client *oauthapi.OAuthClient) (*oauthapi.OAuthClient, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

need to update fake_oauthclient.go to implement this as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will do, thanks!

}

type oauthClients struct {
Expand Down Expand Up @@ -55,3 +56,9 @@ func (c *oauthClients) Delete(name string) (err error) {
func (c *oauthClients) Watch(opts kapi.ListOptions) (watch.Interface, error) {
return c.r.Get().Prefix("watch").Resource("oAuthClients").VersionedParams(&opts, kapi.ParameterCodec).Watch()
}

func (c *oauthClients) Update(client *oauthapi.OAuthClient) (result *oauthapi.OAuthClient, err error) {
result = &oauthapi.OAuthClient{}
err = c.r.Put().Resource("oAuthClients").Name(client.Name).Body(client).Do().Into(result)
return
}
9 changes: 9 additions & 0 deletions pkg/client/testclient/fake_oauthclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,12 @@ func (c *FakeOAuthClient) Delete(name string) error {
func (c *FakeOAuthClient) Watch(opts kapi.ListOptions) (watch.Interface, error) {
return c.Fake.InvokesWatch(ktestclient.NewRootWatchAction("oauthclients", opts))
}

func (c *FakeOAuthClient) Update(client *oauthapi.OAuthClient) (*oauthapi.OAuthClient, error) {
obj, err := c.Fake.Invokes(ktestclient.NewRootUpdateAction("oauthclients", client), &oauthapi.OAuthClient{})
if obj == nil {
return nil, err
}

return obj.(*oauthapi.OAuthClient), err
}