Skip to content

Commit 2462ad9

Browse files
4246 stub org quotas (#4267)
fixes #4246
1 parent 770049f commit 2462ad9

File tree

9 files changed

+156
-27
lines changed

9 files changed

+156
-27
lines changed

api/handlers/isolation_segment.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package handlers
2+
3+
import (
4+
"net/http"
5+
"net/url"
6+
7+
"code.cloudfoundry.org/korifi/api/presenter"
8+
"code.cloudfoundry.org/korifi/api/repositories"
9+
"code.cloudfoundry.org/korifi/api/routing"
10+
)
11+
12+
const (
13+
IsolationSegmentsPath = "/v3/isolation_segments"
14+
)
15+
16+
type IsolationSegment struct {
17+
apiBaseURL url.URL
18+
}
19+
20+
func NewIsolationSegment(apiBaseURL url.URL) *IsolationSegment {
21+
return &IsolationSegment{
22+
apiBaseURL: apiBaseURL,
23+
}
24+
}
25+
26+
func (h *IsolationSegment) list(r *http.Request) (*routing.Response, error) {
27+
return routing.NewResponse(http.StatusOK).WithBody(presenter.ForList(presenter.Empty, repositories.ListResult[any]{}, h.apiBaseURL, *r.URL)), nil
28+
}
29+
30+
func (h *IsolationSegment) AuthenticatedRoutes() []routing.Route {
31+
return []routing.Route{
32+
{Method: "GET", Pattern: IsolationSegmentsPath, Handler: h.list},
33+
}
34+
}
35+
36+
func (h *IsolationSegment) UnauthenticatedRoutes() []routing.Route {
37+
return nil
38+
}

api/handlers/org.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ import (
2121
)
2222

2323
const (
24-
OrgsPath = "/v3/organizations"
25-
OrgPath = "/v3/organizations/{guid}"
26-
OrgDomainsPath = "/v3/organizations/{guid}/domains"
27-
OrgDefaultDomainPath = "/v3/organizations/{guid}/domains/default"
28-
OrgIsolationSegmentsPath = "/v3/organizations/{guid}/relationships/default_isolation_segment"
24+
OrgsPath = "/v3/organizations"
25+
OrgPath = "/v3/organizations/{guid}"
26+
OrgDomainsPath = "/v3/organizations/{guid}/domains"
27+
OrgDefaultDomainPath = "/v3/organizations/{guid}/domains/default"
28+
OrgDefaultIsolationSegmentPath = "/v3/organizations/{guid}/relationships/default_isolation_segment"
2929
)
3030

3131
//counterfeiter:generate -o fake -fake-name CFOrgRepository . CFOrgRepository
@@ -208,8 +208,8 @@ func (h *Org) UnauthenticatedRoutes() []routing.Route {
208208
return nil
209209
}
210210

211-
func (h *Org) getIsolationSegments(r *http.Request) (*routing.Response, error) {
212-
return routing.NewResponse(http.StatusOK).WithBody(presenter.ForIsolationSegment(h.apiBaseURL)), nil
211+
func (h *Org) getDefaultIsolationSegment(r *http.Request) (*routing.Response, error) {
212+
return routing.NewResponse(http.StatusOK).WithBody(struct{}{}), nil
213213
}
214214

215215
func (h *Org) AuthenticatedRoutes() []routing.Route {
@@ -221,7 +221,7 @@ func (h *Org) AuthenticatedRoutes() []routing.Route {
221221
{Method: "GET", Pattern: OrgDomainsPath, Handler: h.listDomains},
222222
{Method: "GET", Pattern: OrgDefaultDomainPath, Handler: h.defaultDomain},
223223
{Method: "GET", Pattern: OrgPath, Handler: h.get},
224-
{Method: "GET", Pattern: OrgIsolationSegmentsPath, Handler: h.getIsolationSegments},
224+
{Method: "GET", Pattern: OrgDefaultIsolationSegmentPath, Handler: h.getDefaultIsolationSegment},
225225
}
226226
}
227227

api/handlers/org_quota.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package handlers
2+
3+
import (
4+
"net/http"
5+
"net/url"
6+
7+
"code.cloudfoundry.org/korifi/api/presenter"
8+
"code.cloudfoundry.org/korifi/api/repositories"
9+
"code.cloudfoundry.org/korifi/api/routing"
10+
)
11+
12+
const (
13+
OrgQuotasPath = "/v3/organization_quotas"
14+
)
15+
16+
type OrgQuota struct {
17+
apiBaseURL url.URL
18+
}
19+
20+
func NewOrgQuota(apiBaseURL url.URL) *OrgQuota {
21+
return &OrgQuota{
22+
apiBaseURL: apiBaseURL,
23+
}
24+
}
25+
26+
func (h *OrgQuota) list(r *http.Request) (*routing.Response, error) {
27+
return routing.NewResponse(http.StatusOK).WithBody(presenter.ForList(presenter.Empty, repositories.ListResult[any]{}, h.apiBaseURL, *r.URL)), nil
28+
}
29+
30+
func (h *OrgQuota) AuthenticatedRoutes() []routing.Route {
31+
return []routing.Route{
32+
{Method: "GET", Pattern: OrgQuotasPath, Handler: h.list},
33+
}
34+
}
35+
36+
func (h *OrgQuota) UnauthenticatedRoutes() []routing.Route {
37+
return nil
38+
}

api/handlers/space.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ import (
1919
)
2020

2121
const (
22-
SpacesPath = "/v3/spaces"
23-
SpacePath = "/v3/spaces/{guid}"
24-
RoutesForSpacePath = "/v3/spaces/{guid}/routes"
25-
SpaceFeaturePath = "/v3/spaces/{guid}/features/{name}"
26-
IsolationSegmentsForSpacePath = "/v3/spaces/{guid}/relationships/isolation_segment"
22+
SpacesPath = "/v3/spaces"
23+
SpacePath = "/v3/spaces/{guid}"
24+
RoutesForSpacePath = "/v3/spaces/{guid}/routes"
25+
SpaceFeaturePath = "/v3/spaces/{guid}/features/{name}"
26+
IsolationSegmentForSpacePath = "/v3/spaces/{guid}/relationships/isolation_segment"
2727
)
2828

2929
//counterfeiter:generate -o fake -fake-name CFSpaceRepository . CFSpaceRepository
@@ -200,8 +200,8 @@ func (h *Space) deleteUnmappedRoutes(r *http.Request) (*routing.Response, error)
200200
return routing.NewResponse(http.StatusAccepted).WithHeader("Location", presenter.JobURLForRedirects(spaceGUID, presenter.SpaceDeleteUnmappedRoutesOperation, h.apiBaseURL)), nil
201201
}
202202

203-
func (h *Space) getIsolationSegments(r *http.Request) (*routing.Response, error) {
204-
return routing.NewResponse(http.StatusOK).WithBody(presenter.ForIsolationSegment(h.apiBaseURL)), nil
203+
func (h *Space) getIsolationSegment(r *http.Request) (*routing.Response, error) {
204+
return routing.NewResponse(http.StatusOK).WithBody(struct{}{}), nil
205205
}
206206

207207
func (h *Space) getSpaceFeature(r *http.Request) (*routing.Response, error) {
@@ -231,7 +231,7 @@ func (h *Space) AuthenticatedRoutes() []routing.Route {
231231
{Method: "DELETE", Pattern: SpacePath, Handler: h.delete},
232232
{Method: "GET", Pattern: SpacePath, Handler: h.get},
233233
{Method: "DELETE", Pattern: RoutesForSpacePath, Handler: h.deleteUnmappedRoutes},
234-
{Method: "GET", Pattern: IsolationSegmentsForSpacePath, Handler: h.getIsolationSegments},
234+
{Method: "GET", Pattern: IsolationSegmentForSpacePath, Handler: h.getIsolationSegment},
235235
{Method: "GET", Pattern: SpaceFeaturePath, Handler: h.getSpaceFeature},
236236
}
237237
}

api/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,12 @@ func main() {
501501
spaceRepo,
502502
requestValidator,
503503
),
504+
handlers.NewOrgQuota(
505+
*serverURL,
506+
),
507+
handlers.NewIsolationSegment(
508+
*serverURL,
509+
),
504510
}
505511

506512
if !cfg.Experimental.ExternalLogCache.Enabled {

api/presenter/isolation_segment.go

Lines changed: 0 additions & 11 deletions
This file was deleted.

api/presenter/shared.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ type ToOneRelationship struct {
7575

7676
type itemPresenter[T, S any] func(T, url.URL, ...include.Resource) S
7777

78+
func Empty(any, url.URL, ...include.Resource) any {
79+
var result any
80+
return result
81+
}
82+
7883
func ForList[T, S any](itemPresenter itemPresenter[T, S], listResult repositories.ListResult[T], baseURL, requestURL url.URL, includes ...include.Resource) ListResponse[S] {
7984
presenters := []S{}
8085
for _, resource := range listResult.Records {

tests/smoke/org_quota_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package smoke_test
2+
3+
import (
4+
"code.cloudfoundry.org/korifi/tests/helpers"
5+
6+
. "github.com/onsi/ginkgo/v2"
7+
. "github.com/onsi/gomega"
8+
. "github.com/onsi/gomega/gexec"
9+
)
10+
11+
var _ = Describe("OrgQuotas", func() {
12+
Describe("cf org-quota", func() {
13+
It("returns OK", func() {
14+
session := helpers.Cf("org-quotas")
15+
Expect(session).To(Exit(0))
16+
})
17+
})
18+
})

tests/smoke/orgs_test.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package smoke_test
2+
3+
import (
4+
"code.cloudfoundry.org/korifi/tests/helpers"
5+
6+
"github.com/BooleanCat/go-functional/v2/it"
7+
"github.com/google/uuid"
8+
. "github.com/onsi/ginkgo/v2"
9+
. "github.com/onsi/gomega"
10+
. "github.com/onsi/gomega/gexec"
11+
)
12+
13+
var _ = Describe("Orgs", func() {
14+
var orgName string
15+
16+
BeforeEach(func() {
17+
orgName = uuid.NewString()
18+
Expect(helpers.Cf(
19+
"create-org",
20+
orgName,
21+
)).To(Exit(0))
22+
})
23+
24+
Describe("cf org", func() {
25+
It("returns successful", func() {
26+
session := helpers.Cf("org", orgName)
27+
Expect(session).To(Exit(0))
28+
29+
lines := it.MustCollect(it.LinesString(session.Out))
30+
Expect(lines).To(ContainElement(
31+
matchSubstrings(orgName),
32+
))
33+
})
34+
})
35+
})

0 commit comments

Comments
 (0)