Add parseOrganizationID method

pull/2142/head
Michael Desa 2017-11-01 12:34:00 -04:00
parent 6fbfde5060
commit dc63e8af8f
3 changed files with 9 additions and 7 deletions

View File

@ -4,7 +4,6 @@ import (
"context"
"fmt"
"net/http"
"strconv"
"github.com/influxdata/chronograf"
"github.com/influxdata/chronograf/oauth2"
@ -93,7 +92,7 @@ func AuthorizedUser(
}
// validate that the organization exists
orgID, err := strconv.ParseUint(p.Organization, 10, 64)
orgID, err := parseOrganizationID(p.Organization)
if err != nil {
log.Error("Failed to validate organization on context")
Error(w, http.StatusUnauthorized, "User is not authorized", logger)

View File

@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"net/http"
"strconv"
"golang.org/x/net/context"
@ -116,7 +115,7 @@ func (s *Service) MeOrganization(auth oauth2.Authenticator) func(http.ResponseWr
}
// validate that the organization exists
orgID, err := strconv.ParseUint(req.Organization, 10, 64)
orgID, err := parseOrganizationID(req.Organization)
if err != nil {
Error(w, http.StatusInternalServerError, err.Error(), s.Logger)
return

View File

@ -10,6 +10,10 @@ import (
"github.com/influxdata/chronograf"
)
func parseOrganizationID(id string) (uint64, error) {
return strconv.ParseUint(id, 10, 64)
}
type organizationRequest struct {
Name string `json:"name"`
}
@ -110,7 +114,7 @@ func (s *Service) OrganizationID(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
idStr := httprouter.GetParamFromContext(ctx, "id")
id, err := strconv.ParseUint(idStr, 10, 64)
id, err := parseOrganizationID(idStr)
if err != nil {
Error(w, http.StatusBadRequest, fmt.Sprintf("invalid organization id: %s", err.Error()), s.Logger)
return
@ -140,7 +144,7 @@ func (s *Service) UpdateOrganization(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
idStr := httprouter.GetParamFromContext(ctx, "id")
id, err := strconv.ParseUint(idStr, 10, 64)
id, err := parseOrganizationID(idStr)
if err != nil {
Error(w, http.StatusBadRequest, fmt.Sprintf("invalid organization id: %s", err.Error()), s.Logger)
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) {
ctx := r.Context()
idStr := httprouter.GetParamFromContext(ctx, "id")
id, err := strconv.ParseUint(idStr, 10, 64)
id, err := parseOrganizationID(idStr)
if err != nil {
Error(w, http.StatusBadRequest, fmt.Sprintf("invalid organization id: %s", err.Error()), s.Logger)
return