Skip to content

Commit fd38b56

Browse files
authored
Merge pull request #249 from platformsh/project-expose-subscription-id
mockapi: add /organizations/{id}/subscriptions/{id}
2 parents b47708b + 3385e19 commit fd38b56

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

pkg/mockapi/api_server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ func NewHandler(t *testing.T) *Handler {
5353

5454
h.Mux.Post("/organizations/{organization_id}/subscriptions", h.handleCreateSubscription)
5555
h.Mux.Get("/subscriptions/{subscription_id}", h.handleGetSubscription)
56+
h.Mux.Get("/organizations/{organization_id}/subscriptions/{subscription_id}", h.handleGetSubscription)
5657
h.Mux.Get("/organizations/{organization_id}/subscriptions/can-create", h.handleCanCreateSubscriptions)
5758
h.Mux.Get("/organizations/{organization_id}/setup/options", func(w http.ResponseWriter, _ *http.Request) {
5859
type options struct {

pkg/mockapi/model.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,26 @@ type Project struct {
6161
CreatedAt time.Time `json:"created_at"`
6262
UpdatedAt time.Time `json:"updated_at"`
6363

64+
Subscription ProjectSubscriptionInfo `json:"subscription,omitempty"`
65+
6466
SubscriptionID string `json:"-"`
6567
}
6668

69+
type ProjectSubscriptionInfo struct {
70+
LicenseURI string `json:"license_uri,omitempty"`
71+
72+
Plan string `json:"plan,omitempty"`
73+
Environments int `json:"environments,omitempty"`
74+
Storage int `json:"storage,omitempty"`
75+
IncludedUsers int `json:"included_users,omitempty"`
76+
UserLicenses int `json:"user_licenses,omitempty"`
77+
78+
ManagementURI string `json:"subscription_management_uri,omitempty"`
79+
80+
Restricted bool `json:"restricted,omitempty"`
81+
Suspended bool `json:"suspended,omitempty"`
82+
}
83+
6784
func (p *Project) AsRef() *ProjectRef {
6885
return &ProjectRef{
6986
ID: p.ID,

pkg/mockapi/subscriptions.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package mockapi
22

33
import (
44
"encoding/json"
5+
"fmt"
56
"net/http"
67
"net/url"
78
"time"
@@ -17,11 +18,14 @@ func (h *Handler) handleCreateSubscription(w http.ResponseWriter, req *http.Requ
1718
}{}
1819
err := json.NewDecoder(req.Body).Decode(&createOptions)
1920
require.NoError(h.t, err)
21+
orgID := chi.URLParam(req, "organization_id")
2022
id := NumericID()
2123
projectID := ProjectID()
2224
sub := Subscription{
23-
ID: id,
24-
Links: MakeHALLinks("self=" + "/subscriptions/" + url.PathEscape(id)),
25+
ID: id,
26+
Links: MakeHALLinks(
27+
"self=" + "/organizations/" + url.PathEscape(orgID) + "/subscriptions/" + url.PathEscape(id),
28+
),
2529
ProjectRegion: createOptions.Region,
2630
ProjectTitle: createOptions.Title,
2731
Status: "provisioning",
@@ -40,7 +44,10 @@ func (h *Handler) handleCreateSubscription(w http.ResponseWriter, req *http.Requ
4044
Links: MakeHALLinks("self=/projects/" + projectID),
4145
Repository: ProjectRepository{URL: projectID + "@git.example.com:" + projectID + ".git"},
4246
SubscriptionID: sub.ID,
43-
Organization: chi.URLParam(req, "organization_id"),
47+
Subscription: ProjectSubscriptionInfo{
48+
LicenseURI: fmt.Sprintf("/licenses/%s", url.PathEscape(sub.ID)),
49+
},
50+
Organization: chi.URLParam(req, "organization_id"),
4451
}
4552
h.store.Unlock()
4653

0 commit comments

Comments
 (0)