Add config.self & config.auth routes, update client routes & make PATCH a PUT
parent
da67f958ae
commit
5c813493ea
|
@ -5,6 +5,11 @@ import (
|
||||||
"net/url"
|
"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 {
|
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
|
CustomLinks []CustomLink `json:"custom,omitempty"` // Any custom external links for client's User menu
|
||||||
|
|
|
@ -36,7 +36,7 @@ type getRoutesResponse struct {
|
||||||
Sources string `json:"sources"` // Location of the sources endpoint
|
Sources string `json:"sources"` // Location of the sources endpoint
|
||||||
Me string `json:"me"` // Location of the me endpoint
|
Me string `json:"me"` // Location of the me endpoint
|
||||||
Dashboards string `json:"dashboards"` // Location of the dashboards 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.
|
Auth []AuthRoute `json:"auth"` // Location of all auth routes.
|
||||||
Logout *string `json:"logout,omitempty"` // Location of the logout route for 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
|
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",
|
Me: "/chronograf/v1/me",
|
||||||
Mappings: "/chronograf/v1/mappings",
|
Mappings: "/chronograf/v1/mappings",
|
||||||
Dashboards: "/chronograf/v1/dashboards",
|
Dashboards: "/chronograf/v1/dashboards",
|
||||||
Config: "/chronograf/v1/config",
|
Config: getConfigLinksResponse{
|
||||||
Auth: make([]AuthRoute, len(a.AuthRoutes)), // We want to return at least an empty array, rather than null
|
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{
|
ExternalLinks: getExternalLinksResponse{
|
||||||
StatusFeed: &a.StatusFeed,
|
StatusFeed: &a.StatusFeed,
|
||||||
CustomLinks: customLinks,
|
CustomLinks: customLinks,
|
||||||
|
|
|
@ -29,7 +29,7 @@ func TestAllRoutes(t *testing.T) {
|
||||||
if err := json.Unmarshal(body, &routes); err != nil {
|
if err := json.Unmarshal(body, &routes); err != nil {
|
||||||
t.Error("TestAllRoutes not able to unmarshal JSON response")
|
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) {
|
if want != string(body) {
|
||||||
t.Errorf("TestAllRoutes\nwanted\n*%s*\ngot\n*%s*", 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 {
|
if err := json.Unmarshal(body, &routes); err != nil {
|
||||||
t.Error("TestAllRoutesWithAuth not able to unmarshal JSON response")
|
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) {
|
if want != string(body) {
|
||||||
t.Errorf("TestAllRoutesWithAuth\nwanted\n*%s*\ngot\n*%s*", 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 {
|
if err := json.Unmarshal(body, &routes); err != nil {
|
||||||
t.Error("TestAllRoutesWithExternalLinks not able to unmarshal JSON response")
|
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) {
|
if want != string(body) {
|
||||||
t.Errorf("TestAllRoutesWithExternalLinks\nwanted\n*%s*\ngot\n*%s*", want, string(body))
|
t.Errorf("TestAllRoutesWithExternalLinks\nwanted\n*%s*\ngot\n*%s*", want, string(body))
|
||||||
|
|
|
@ -16,7 +16,7 @@ class OrganizationsPage extends Component {
|
||||||
actionsConfig: {getAuthConfigAsync},
|
actionsConfig: {getAuthConfigAsync},
|
||||||
} = this.props
|
} = this.props
|
||||||
loadOrganizationsAsync(links.organizations)
|
loadOrganizationsAsync(links.organizations)
|
||||||
getAuthConfigAsync(links.config)
|
getAuthConfigAsync(links.config.auth)
|
||||||
}
|
}
|
||||||
|
|
||||||
handleCreateOrganization = async organization => {
|
handleCreateOrganization = async organization => {
|
||||||
|
@ -63,7 +63,7 @@ class OrganizationsPage extends Component {
|
||||||
authConfig,
|
authConfig,
|
||||||
links,
|
links,
|
||||||
} = this.props
|
} = this.props
|
||||||
updateAuthConfigAsync(links.config, authConfig, updatedAuthConfig)
|
updateAuthConfigAsync(links.config.auth, authConfig, updatedAuthConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -90,7 +90,9 @@ const {arrayOf, bool, func, shape, string} = PropTypes
|
||||||
OrganizationsPage.propTypes = {
|
OrganizationsPage.propTypes = {
|
||||||
links: shape({
|
links: shape({
|
||||||
organizations: string.isRequired,
|
organizations: string.isRequired,
|
||||||
config: string.isRequired,
|
config: shape({
|
||||||
|
auth: string.isRequired,
|
||||||
|
}).isRequired,
|
||||||
}),
|
}),
|
||||||
organizations: arrayOf(
|
organizations: arrayOf(
|
||||||
shape({
|
shape({
|
||||||
|
|
|
@ -15,7 +15,7 @@ export const getAuthConfig = async url => {
|
||||||
export const updateAuthConfig = async (url, authConfig) => {
|
export const updateAuthConfig = async (url, authConfig) => {
|
||||||
try {
|
try {
|
||||||
return await AJAX({
|
return await AJAX({
|
||||||
method: 'PATCH',
|
method: 'PUT',
|
||||||
url,
|
url,
|
||||||
data: authConfig,
|
data: authConfig,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue