Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Serve = &cobra.Command{ Use: "serve", Short: "Serves the proxy", Run: func(cmd *cobra.Command, args []string) { config := MergeConfig() oauth := &clientcredentials.Config{ ClientID: config.clientID, ClientSecret: config.clientSecret, TokenURL: config.tokenURL, Scopes: config.scopes, } oauthContext := context.Background() tokenSource := oauth.TokenSource(oauthContext) director := func(req *http.Request) { host, scheme := ExtractHost( &req.Header, config, ) req.Host = host req.URL.Host = host req.URL.Scheme = scheme token, err := tokenSource.Token() if err != nil { log.Printf("OAuth error: %s\n", err) return } req.Header.Set( "Authorization", fmt.Sprintf("Bearer %s", token.AccessToken), ) log.Printf("Forwarding request to %s://%s\n", scheme, host) } proxy := &httputil.ReverseProxy{ Director: director, Transport: &http.Transport{ TLSClientConfig: &tls.Config{ InsecureSkipVerify: config.skipTlsVerify, }, }, } fmt.Printf("Listening on 0.0.0.0:%d\n", config.listenPort) log.Fatal(http.ListenAndServe( ":"+strconv.Itoa(config.listenPort), proxy, )) }, }
Functions ¶
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
func MergeConfig ¶
func MergeConfig() Config
Click to show internal directories.
Click to hide internal directories.