Add parseOrganizationID method
parent
6fbfde5060
commit
dc63e8af8f
|
@ -4,7 +4,6 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/influxdata/chronograf"
|
"github.com/influxdata/chronograf"
|
||||||
"github.com/influxdata/chronograf/oauth2"
|
"github.com/influxdata/chronograf/oauth2"
|
||||||
|
@ -93,7 +92,7 @@ func AuthorizedUser(
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate that the organization exists
|
// validate that the organization exists
|
||||||
orgID, err := strconv.ParseUint(p.Organization, 10, 64)
|
orgID, err := parseOrganizationID(p.Organization)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Failed to validate organization on context")
|
log.Error("Failed to validate organization on context")
|
||||||
Error(w, http.StatusUnauthorized, "User is not authorized", logger)
|
Error(w, http.StatusUnauthorized, "User is not authorized", logger)
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
|
||||||
|
@ -116,7 +115,7 @@ func (s *Service) MeOrganization(auth oauth2.Authenticator) func(http.ResponseWr
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate that the organization exists
|
// validate that the organization exists
|
||||||
orgID, err := strconv.ParseUint(req.Organization, 10, 64)
|
orgID, err := parseOrganizationID(req.Organization)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Error(w, http.StatusInternalServerError, err.Error(), s.Logger)
|
Error(w, http.StatusInternalServerError, err.Error(), s.Logger)
|
||||||
return
|
return
|
||||||
|
|
|
@ -10,6 +10,10 @@ import (
|
||||||
"github.com/influxdata/chronograf"
|
"github.com/influxdata/chronograf"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func parseOrganizationID(id string) (uint64, error) {
|
||||||
|
return strconv.ParseUint(id, 10, 64)
|
||||||
|
}
|
||||||
|
|
||||||
type organizationRequest struct {
|
type organizationRequest struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
|
@ -110,7 +114,7 @@ func (s *Service) OrganizationID(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
|
|
||||||
idStr := httprouter.GetParamFromContext(ctx, "id")
|
idStr := httprouter.GetParamFromContext(ctx, "id")
|
||||||
id, err := strconv.ParseUint(idStr, 10, 64)
|
id, err := parseOrganizationID(idStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Error(w, http.StatusBadRequest, fmt.Sprintf("invalid organization id: %s", err.Error()), s.Logger)
|
Error(w, http.StatusBadRequest, fmt.Sprintf("invalid organization id: %s", err.Error()), s.Logger)
|
||||||
return
|
return
|
||||||
|
@ -140,7 +144,7 @@ func (s *Service) UpdateOrganization(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
idStr := httprouter.GetParamFromContext(ctx, "id")
|
idStr := httprouter.GetParamFromContext(ctx, "id")
|
||||||
id, err := strconv.ParseUint(idStr, 10, 64)
|
id, err := parseOrganizationID(idStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Error(w, http.StatusBadRequest, fmt.Sprintf("invalid organization id: %s", err.Error()), s.Logger)
|
Error(w, http.StatusBadRequest, fmt.Sprintf("invalid organization id: %s", err.Error()), s.Logger)
|
||||||
return
|
return
|
||||||
|
@ -170,7 +174,7 @@ func (s *Service) UpdateOrganization(w http.ResponseWriter, r *http.Request) {
|
||||||
func (s *Service) RemoveOrganization(w http.ResponseWriter, r *http.Request) {
|
func (s *Service) RemoveOrganization(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
idStr := httprouter.GetParamFromContext(ctx, "id")
|
idStr := httprouter.GetParamFromContext(ctx, "id")
|
||||||
id, err := strconv.ParseUint(idStr, 10, 64)
|
id, err := parseOrganizationID(idStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Error(w, http.StatusBadRequest, fmt.Sprintf("invalid organization id: %s", err.Error()), s.Logger)
|
Error(w, http.StatusBadRequest, fmt.Sprintf("invalid organization id: %s", err.Error()), s.Logger)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue