Skip to content

Commit

Permalink
Merge pull request #10895 from juanvallejo/jvallejo_add-localhost-900…
Browse files Browse the repository at this point in the history
…0-as-default-redirect-oc-cluster

Merged by openshift-bot
  • Loading branch information
OpenShift Bot authored Sep 27, 2016
2 parents 129c66c + b183604 commit 53d71cb
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
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)
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)
}

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
}

0 comments on commit 53d71cb

Please sign in to comment.