forked from openshift/console
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request openshift#1507 from squat/federation_list_clusters
server: list federation clusters
- Loading branch information
Showing
4 changed files
with
91 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package server | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"net/http" | ||
"net/url" | ||
) | ||
|
||
type contextKey int | ||
|
||
const federationConfigKey = contextKey(0) | ||
|
||
// federationConfigFromContext returns the federation configuration from a given context. | ||
func federationConfigFromContext(ctx context.Context) (*federationConfig, error) { | ||
f, ok := ctx.Value(federationConfigKey).(*federationConfig) | ||
if !ok { | ||
return nil, errors.New("the given context has no federation config value") | ||
} | ||
return f, nil | ||
} | ||
|
||
// withFederationConfig returns a copy of the given context with the federation configuration added. | ||
func withFederationConfig(ctx context.Context, r *http.Request) (context.Context, error) { | ||
urlString := r.Header.Get("X-Tectonic-Federation-Url") | ||
if urlString == "" { | ||
return nil, errors.New("request must include a url") | ||
} | ||
|
||
u, err := url.Parse(urlString) | ||
if err != nil { | ||
return nil, errors.New("failed to parse federation apiserver url") | ||
} | ||
|
||
token := r.Header.Get("X-Tectonic-Federation-Token") | ||
if token == "" { | ||
return nil, errors.New("request must include a token") | ||
} | ||
f := federationConfig{ | ||
token: token, | ||
url: u, | ||
} | ||
return context.WithValue(ctx, federationConfigKey, &f), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package server | ||
|
||
import ( | ||
"crypto/tls" | ||
"fmt" | ||
"net/http" | ||
"net/url" | ||
|
||
"github.com/coreos-inc/bridge/pkg/proxy" | ||
) | ||
|
||
// federationConfig holds the configuration values needed to proxy requests to | ||
// a federation API server. | ||
type federationConfig struct { | ||
token string | ||
url *url.URL | ||
} | ||
|
||
var federationProxyConfig = &proxy.Config{ | ||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, | ||
Director: func(r *http.Request) { | ||
f, err := federationConfigFromContext(r.Context()) | ||
if err != nil { | ||
plog.Errorf("failed to get federation config from context: %v", err) | ||
return | ||
} | ||
r.Host = f.url.Host | ||
r.URL.Host = f.url.Host | ||
r.URL.Path = proxy.SingleJoiningSlash(f.url.Path, r.URL.Path) | ||
r.URL.Scheme = f.url.Scheme | ||
r.Header.Add("Authorization", fmt.Sprintf("bearer %s", f.token)) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters