From 5c813493ea1a4ee959023a6c928654aa73ab39aa Mon Sep 17 00:00:00 2001 From: Jared Scheib Date: Wed, 13 Dec 2017 13:54:23 -0800 Subject: [PATCH] Add config.self & config.auth routes, update client routes & make PATCH a PUT --- server/links.go | 5 +++++ server/routes.go | 9 ++++++--- server/routes_test.go | 6 +++--- ui/src/admin/containers/OrganizationsPage.js | 8 +++++--- ui/src/shared/apis/config.js | 2 +- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/server/links.go b/server/links.go index 9f4f6e38a..3a3b3fd41 100644 --- a/server/links.go +++ b/server/links.go @@ -5,6 +5,11 @@ import ( "net/url" ) +type getConfigLinksResponse struct { + Self string `json:"self"` // Location of the whole global application configuration + Auth string `json:"auth"` // Location of the auth section of the global application configuration +} + type getExternalLinksResponse struct { 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 diff --git a/server/routes.go b/server/routes.go index 98e4c0a46..497ed21e1 100644 --- a/server/routes.go +++ b/server/routes.go @@ -36,7 +36,7 @@ type getRoutesResponse struct { Sources string `json:"sources"` // Location of the sources endpoint Me string `json:"me"` // Location of the me endpoint Dashboards string `json:"dashboards"` // Location of the dashboards endpoint - Config string `json:"config"` // Location of the config endpoint + Config getConfigLinksResponse `json:"config"` // Location of the config endpoint and its various sections Auth []AuthRoute `json:"auth"` // Location of all auth routes. Logout *string `json:"logout,omitempty"` // Location of the logout route for all auth routes ExternalLinks getExternalLinksResponse `json:"external"` // All external links for the client to use @@ -69,8 +69,11 @@ func (a *AllRoutes) ServeHTTP(w http.ResponseWriter, r *http.Request) { Me: "/chronograf/v1/me", Mappings: "/chronograf/v1/mappings", Dashboards: "/chronograf/v1/dashboards", - Config: "/chronograf/v1/config", - Auth: make([]AuthRoute, len(a.AuthRoutes)), // We want to return at least an empty array, rather than null + Config: getConfigLinksResponse{ + Self: "/chronograf/v1/config", + Auth: "/chronograf/v1/config/auth", + }, + Auth: make([]AuthRoute, len(a.AuthRoutes)), // We want to return at least an empty array, rather than null ExternalLinks: getExternalLinksResponse{ StatusFeed: &a.StatusFeed, CustomLinks: customLinks, diff --git a/server/routes_test.go b/server/routes_test.go index ed5d80d92..bb4203f75 100644 --- a/server/routes_test.go +++ b/server/routes_test.go @@ -29,7 +29,7 @@ func TestAllRoutes(t *testing.T) { if err := json.Unmarshal(body, &routes); err != nil { t.Error("TestAllRoutes not able to unmarshal JSON response") } - want := `{"layouts":"/chronograf/v1/layouts","users":"/chronograf/v1/users","organizations":"/chronograf/v1/organizations","mappings":"/chronograf/v1/mappings","sources":"/chronograf/v1/sources","me":"/chronograf/v1/me","dashboards":"/chronograf/v1/dashboards","config":"/chronograf/v1/config","auth":[],"external":{"statusFeed":""}} + want := `{"layouts":"/chronograf/v1/layouts","users":"/chronograf/v1/users","organizations":"/chronograf/v1/organizations","mappings":"/chronograf/v1/mappings","sources":"/chronograf/v1/sources","me":"/chronograf/v1/me","dashboards":"/chronograf/v1/dashboards","config":{"self":"/chronograf/v1/config","auth":"/chronograf/v1/config/auth"},"auth":[],"external":{"statusFeed":""}} ` if want != string(body) { t.Errorf("TestAllRoutes\nwanted\n*%s*\ngot\n*%s*", want, string(body)) @@ -67,7 +67,7 @@ func TestAllRoutesWithAuth(t *testing.T) { if err := json.Unmarshal(body, &routes); err != nil { t.Error("TestAllRoutesWithAuth not able to unmarshal JSON response") } - want := `{"layouts":"/chronograf/v1/layouts","users":"/chronograf/v1/users","organizations":"/chronograf/v1/organizations","mappings":"/chronograf/v1/mappings","sources":"/chronograf/v1/sources","me":"/chronograf/v1/me","dashboards":"/chronograf/v1/dashboards","config":"/chronograf/v1/config","auth":[{"name":"github","label":"GitHub","login":"/oauth/github/login","logout":"/oauth/github/logout","callback":"/oauth/github/callback"}],"logout":"/oauth/logout","external":{"statusFeed":""}} + want := `{"layouts":"/chronograf/v1/layouts","users":"/chronograf/v1/users","organizations":"/chronograf/v1/organizations","mappings":"/chronograf/v1/mappings","sources":"/chronograf/v1/sources","me":"/chronograf/v1/me","dashboards":"/chronograf/v1/dashboards","config":{"self":"/chronograf/v1/config","auth":"/chronograf/v1/config/auth"},"auth":[{"name":"github","label":"GitHub","login":"/oauth/github/login","logout":"/oauth/github/logout","callback":"/oauth/github/callback"}],"logout":"/oauth/logout","external":{"statusFeed":""}} ` if want != string(body) { t.Errorf("TestAllRoutesWithAuth\nwanted\n*%s*\ngot\n*%s*", want, string(body)) @@ -100,7 +100,7 @@ func TestAllRoutesWithExternalLinks(t *testing.T) { if err := json.Unmarshal(body, &routes); err != nil { t.Error("TestAllRoutesWithExternalLinks not able to unmarshal JSON response") } - want := `{"layouts":"/chronograf/v1/layouts","users":"/chronograf/v1/users","organizations":"/chronograf/v1/organizations","mappings":"/chronograf/v1/mappings","sources":"/chronograf/v1/sources","me":"/chronograf/v1/me","dashboards":"/chronograf/v1/dashboards","config":"/chronograf/v1/config","auth":[],"external":{"statusFeed":"http://pineapple.life/feed.json","custom":[{"name":"cubeapple","url":"https://cube.apple"}]}} + want := `{"layouts":"/chronograf/v1/layouts","users":"/chronograf/v1/users","organizations":"/chronograf/v1/organizations","mappings":"/chronograf/v1/mappings","sources":"/chronograf/v1/sources","me":"/chronograf/v1/me","dashboards":"/chronograf/v1/dashboards","config":{"self":"/chronograf/v1/config","auth":"/chronograf/v1/config/auth"},"auth":[],"external":{"statusFeed":"http://pineapple.life/feed.json","custom":[{"name":"cubeapple","url":"https://cube.apple"}]}} ` if want != string(body) { t.Errorf("TestAllRoutesWithExternalLinks\nwanted\n*%s*\ngot\n*%s*", want, string(body)) diff --git a/ui/src/admin/containers/OrganizationsPage.js b/ui/src/admin/containers/OrganizationsPage.js index 7679a991f..6a24e9015 100644 --- a/ui/src/admin/containers/OrganizationsPage.js +++ b/ui/src/admin/containers/OrganizationsPage.js @@ -16,7 +16,7 @@ class OrganizationsPage extends Component { actionsConfig: {getAuthConfigAsync}, } = this.props loadOrganizationsAsync(links.organizations) - getAuthConfigAsync(links.config) + getAuthConfigAsync(links.config.auth) } handleCreateOrganization = async organization => { @@ -63,7 +63,7 @@ class OrganizationsPage extends Component { authConfig, links, } = this.props - updateAuthConfigAsync(links.config, authConfig, updatedAuthConfig) + updateAuthConfigAsync(links.config.auth, authConfig, updatedAuthConfig) } render() { @@ -90,7 +90,9 @@ const {arrayOf, bool, func, shape, string} = PropTypes OrganizationsPage.propTypes = { links: shape({ organizations: string.isRequired, - config: string.isRequired, + config: shape({ + auth: string.isRequired, + }).isRequired, }), organizations: arrayOf( shape({ diff --git a/ui/src/shared/apis/config.js b/ui/src/shared/apis/config.js index 5d745cef3..134178408 100644 --- a/ui/src/shared/apis/config.js +++ b/ui/src/shared/apis/config.js @@ -15,7 +15,7 @@ export const getAuthConfig = async url => { export const updateAuthConfig = async (url, authConfig) => { try { return await AJAX({ - method: 'PATCH', + method: 'PUT', url, data: authConfig, })