Exemplo n.º 1
0
func (h listHandler) filteredUsers(query string) *domain.Users {
	switch {
	case strings.Contains(query, "space_guid:"):
		spaceGUID := strings.TrimPrefix(query, "space_guid:")
		space, ok := h.spaces.Get(spaceGUID)
		if !ok {
			return domain.NewUsers()
		}

		return space.Developers
	default:
		return h.users
	}
}
Exemplo n.º 2
0
func NewCloudController() *CloudController {
	cc := &CloudController{
		Organizations:    domain.NewOrganizations(),
		Spaces:           domain.NewSpaces(),
		Users:            domain.NewUsers(),
		ServiceInstances: domain.NewServiceInstances(),
		Applications:     domain.NewApplications(),
	}

	router := mux.NewRouter()
	router.Handle("/v2/organizations{anything:.*}", organizations.NewRouter(cc.Organizations, cc.Users))
	router.Handle("/v2/spaces{anything:.*}", spaces.NewRouter(cc.Organizations, cc.Spaces, cc.Users))
	router.Handle("/v2/users{anything:.*}", users.NewRouter(cc.Users, cc.Spaces))
	router.Handle("/v2/service_instances{anything:.*}", serviceinstances.NewRouter(cc.ServiceInstances))
	router.Handle("/v2/apps{anything:.*}", applications.NewRouter(cc.Applications))

	handler := cc.requireToken(router)
	cc.server = httptest.NewUnstartedServer(handler)

	return cc
}
Exemplo n.º 3
0
	Describe("HasPrevPage", func() {
		It("indicates whether or not there is a previous page of results", func() {
			list.PrevURL = "/v2/users?page=1"
			Expect(list.HasPrevPage()).To(BeTrue())

			list.PrevURL = ""
			Expect(list.HasPrevPage()).To(BeFalse())
		})
	})

	Describe("Associate", func() {
		It("associates a user with the listed resource", func() {
			spaceGUID := "space-abc"
			fakeCloudController.Spaces.Add(domain.Space{
				GUID:       spaceGUID,
				Developers: domain.NewUsers(),
			})

			user, err := list.Create(rainmaker.User{GUID: "user-abc"}, token)
			Expect(err).NotTo(HaveOccurred())

			list = rainmaker.NewUsersList(config, rainmaker.NewRequestPlan("/v2/spaces/"+spaceGUID+"/developers", url.Values{}))
			err = list.Associate(user.GUID, token)
			Expect(err).NotTo(HaveOccurred())

			err = list.Fetch(token)
			Expect(err).NotTo(HaveOccurred())
			Expect(list.Users).To(HaveLen(1))
			Expect(list.Users[0].GUID).To(Equal(user.GUID))
		})
	})