Beispiel #1
0
func (s *InstanceSuite) TestCreateServiceInstanceRestrictedService(c *gocheck.C) {
	var requests int32
	ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(http.StatusNoContent)
		atomic.AddInt32(&requests, 1)
	}))
	defer ts.Close()
	err := auth.CreateTeam("painkiller", s.user)
	c.Assert(err, gocheck.IsNil)
	defer s.conn.Teams().RemoveId("painkiller")
	srv := Service{
		Name:         "mongodb",
		Endpoint:     map[string]string{"production": ts.URL},
		IsRestricted: true,
		Teams:        []string{"painkiller"},
	}
	err = s.conn.Services().Insert(&srv)
	c.Assert(err, gocheck.IsNil)
	defer s.conn.Services().RemoveId(srv.Name)
	err = CreateServiceInstance("instance", &srv, nil, s.user)
	c.Assert(err, gocheck.IsNil)
	defer s.conn.ServiceInstances().Remove(bson.M{"name": "instance"})
	instance, err := GetServiceInstance("instance", s.user)
	c.Assert(err, gocheck.IsNil)
	c.Assert(instance.Teams, gocheck.DeepEquals, []string{"painkiller"})
}
Beispiel #2
0
func createTeam(w http.ResponseWriter, r *http.Request, t *auth.Token) error {
	var params map[string]string
	err := json.NewDecoder(r.Body).Decode(&params)
	if err != nil {
		return &errors.HTTP{Code: http.StatusBadRequest, Message: err.Error()}
	}
	name := params["name"]
	u, err := t.User()
	if err != nil {
		return err
	}
	rec.Log(u.Email, "create-team", name)
	err = auth.CreateTeam(name, u)
	switch err {
	case auth.ErrInvalidTeamName:
		return &errors.HTTP{Code: http.StatusBadRequest, Message: err.Error()}
	case auth.ErrTeamAlreadyExists:
		return &errors.HTTP{Code: http.StatusConflict, Message: err.Error()}
	}
	return nil
}