WIP Parse custom links from CLI
parent
cbab4402b5
commit
a251071254
|
@ -29,6 +29,7 @@ type MuxOpts struct {
|
|||
Auth oauth2.Authenticator // Auth is used to authenticate and authorize
|
||||
ProviderFuncs []func(func(oauth2.Provider, oauth2.Mux))
|
||||
StatusFeedURL string // JSON Feed URL for the client Status page News Feed
|
||||
CustomLinks []CustomLink
|
||||
}
|
||||
|
||||
// NewMux attaches all the route handlers; handler returned servers chronograf.
|
||||
|
|
|
@ -40,17 +40,24 @@ type getRoutesResponse struct {
|
|||
}
|
||||
|
||||
type getExternalLinksResponse struct {
|
||||
StatusFeed *string `json:"statusFeed,omitempty"` // Location of the a JSON Feed for client's Status page News Feed
|
||||
StatusFeed *string `json:"statusFeed,omitempty"` // Location of the a JSON Feed for client's Status page News Feed
|
||||
CustomLinks []CustomLink `json:"custom,omitempty"` // Any custom external links for client's User menu
|
||||
}
|
||||
|
||||
type CustomLink struct {
|
||||
Name *string
|
||||
Url *string
|
||||
}
|
||||
|
||||
// AllRoutes is a handler that returns all links to resources in Chronograf server, as well as
|
||||
// external links for the client to know about, such as for JSON feeds or custom side nav buttons.
|
||||
// Optionally, routes for authentication can be returned.
|
||||
type AllRoutes struct {
|
||||
AuthRoutes []AuthRoute // Location of all auth routes. If no auth, this can be empty.
|
||||
LogoutLink string // Location of the logout route for all auth routes. If no auth, this can be empty.
|
||||
StatusFeed string // External link to the JSON Feed for the News Feed on the client's Status Page
|
||||
Logger chronograf.Logger
|
||||
AuthRoutes []AuthRoute // Location of all auth routes. If no auth, this can be empty.
|
||||
LogoutLink string // Location of the logout route for all auth routes. If no auth, this can be empty.
|
||||
StatusFeed string // External link to the JSON Feed for the News Feed on the client's Status Page
|
||||
CustomLinks []CustomLink // Any custom external links for client's User menu
|
||||
Logger chronograf.Logger
|
||||
}
|
||||
|
||||
// ServeHTTP returns all top level routes within chronograf
|
||||
|
@ -63,7 +70,8 @@ func (a *AllRoutes) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
Dashboards: "/chronograf/v1/dashboards",
|
||||
Auth: make([]AuthRoute, len(a.AuthRoutes)), // We want to return at least an empty array, rather than null
|
||||
ExternalLinks: getExternalLinksResponse{
|
||||
StatusFeed: &a.StatusFeed,
|
||||
StatusFeed: &a.StatusFeed,
|
||||
CustomLinks: a.CustomLinks,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package server
|
|||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net"
|
||||
|
@ -80,6 +81,8 @@ type Server struct {
|
|||
|
||||
StatusFeedURL string `long:"status-feed-url" description:"URL of a JSON Feed to display as a News Feed on the client Status page." default:"https://www.influxdata.com/feed/json" env:"STATUS_FEED_URL"`
|
||||
|
||||
CustomLinks []string `long:"custom-links" description:"Custom links to be added to the client User menu" default:"foo:foo.com" default:"bar:bar.com" env:"CUSTOM_LINKS" env-delim:","`
|
||||
|
||||
Auth0Domain string `long:"auth0-domain" description:"Subdomain of auth0.com used for Auth0 OAuth2 authentication" env:"AUTH0_DOMAIN"`
|
||||
Auth0ClientID string `long:"auth0-client-id" description:"Auth0 Client ID for OAuth2 support" env:"AUTH0_CLIENT_ID"`
|
||||
Auth0ClientSecret string `long:"auth0-client-secret" description:"Auth0 Client Secret for OAuth2 support" env:"AUTH0_CLIENT_SECRET"`
|
||||
|
@ -94,6 +97,51 @@ type Server struct {
|
|||
handler http.Handler
|
||||
}
|
||||
|
||||
type CustomLinkOption struct {
|
||||
CustomLink map[string]string
|
||||
}
|
||||
|
||||
type x struct {
|
||||
CustomLink string
|
||||
}
|
||||
|
||||
type CustomLinksOptions struct {
|
||||
CustomLinks []CustomLinkOption
|
||||
}
|
||||
|
||||
func parseCustomLinks(options []string) []CustomLink {
|
||||
var customLinkOption CustomLinkOption
|
||||
for i, customLink := range options {
|
||||
customLinkOption.CustomLink = customLink
|
||||
parser := flags.NewParser(&customLinkOption, flags.Default)
|
||||
parser.Parse()
|
||||
// customLinkOption := CustomLinkOption{}
|
||||
fmt.Println(i, customLink)
|
||||
// // var customLinks CustomLinks
|
||||
//
|
||||
// // // CustomLink{
|
||||
// // // Name: "foo",
|
||||
// // // Url: "foo.com",
|
||||
// // // }
|
||||
}
|
||||
fmt.Printf("%#+v", options)
|
||||
// customLink := CustomLink{
|
||||
// Name: "foo",
|
||||
// Url: "foo.com",
|
||||
// }
|
||||
// foo := "foo"
|
||||
// foocom := "foo.com"
|
||||
var customLinks []CustomLink
|
||||
// customLinks[0] = CustomLink
|
||||
// {
|
||||
// Name: &foo,
|
||||
// Url: &foocom,
|
||||
// }
|
||||
|
||||
return customLinks
|
||||
|
||||
}
|
||||
|
||||
func provide(p oauth2.Provider, m oauth2.Mux, ok func() bool) func(func(oauth2.Provider, oauth2.Mux)) {
|
||||
return func(configure func(oauth2.Provider, oauth2.Mux)) {
|
||||
if ok() {
|
||||
|
@ -304,6 +352,8 @@ func (s *Server) Serve(ctx context.Context) error {
|
|||
providerFuncs = append(providerFuncs, provide(s.genericOAuth(logger, auth)))
|
||||
providerFuncs = append(providerFuncs, provide(s.auth0OAuth(logger, auth)))
|
||||
|
||||
customLinks := parseCustomLinks(s.CustomLinks)
|
||||
|
||||
s.handler = NewMux(MuxOpts{
|
||||
Develop: s.Develop,
|
||||
Auth: auth,
|
||||
|
@ -313,6 +363,7 @@ func (s *Server) Serve(ctx context.Context) error {
|
|||
Basepath: basepath,
|
||||
PrefixRoutes: s.PrefixRoutes,
|
||||
StatusFeedURL: s.StatusFeedURL,
|
||||
CustomLinks: customLinks,
|
||||
}, service)
|
||||
|
||||
// Add chronograf's version header to all requests
|
||||
|
|
Loading…
Reference in New Issue