Skip to content

Commit 6b5ae7e

Browse files
authored
Feat/environments (#20)
feat: support environments. Fixes #17.
1 parent 02e3230 commit 6b5ae7e

File tree

23 files changed

+1588
-47
lines changed

23 files changed

+1588
-47
lines changed

acceptance/pactflow/pactflow-update.tf.next

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,13 @@ resource "pact_role" "special_role" {
156156
resource "pact_authentication" "authentication" {
157157
github_organizations = ["DiUS", "pactflow"]
158158
google_domains = ["dius.com.au", "onegeek.com.au", "pactflow.io"]
159+
}
160+
161+
### Environments
162+
163+
resource "pact_environment" "staging" {
164+
name = "staging"
165+
display_name = "Staging Environment new"
166+
production = false
167+
teams = [pact_team.Simpsons.uuid]
159168
}

acceptance/pactflow/pactflow.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,13 @@ resource "pact_role" "special_role" {
160160
resource "pact_authentication" "authentication" {
161161
github_organizations = ["DiUS", "pactflow"]
162162
google_domains = ["dius.com.au", "onegeek.com.au"]
163+
}
164+
165+
### Environments
166+
167+
resource "pact_environment" "staging" {
168+
name = "staging"
169+
display_name = "Staging Environment"
170+
production = false
171+
teams = [pact_team.Simpsons.uuid]
163172
}

broker/environment.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package broker
2+
3+
// Environment represents an environment and application may be deployed to
4+
type Environment struct {
5+
Name string `json:"name,omitempty"`
6+
Production bool `json:"production"`
7+
DisplayName string `json:"displayName,omitempty"`
8+
CreatedAt string `json:"createdAt,omitempty"`
9+
UpdatedAt string `json:"updatedAt,omitempty"`
10+
UUID string `json:"uuid,omitempty"`
11+
Embedded EnvironmentEmbeddedItems `json:"_embedded,omitempty"`
12+
}
13+
14+
type EnvironmentCreateOrUpdateRequest struct {
15+
UUID string `json:"-"`
16+
DisplayName string `json:"displayName,omitempty"`
17+
Name string `json:"name,omitempty"`
18+
Production bool `json:"production"`
19+
Teams []string `json:"teamUuids"`
20+
}
21+
22+
type EnvironmentCreateOrUpdateResponse struct {
23+
Name string `json:"name,omitempty"`
24+
Production bool `json:"production"`
25+
DisplayName string `json:"displayName,omitempty"`
26+
CreatedAt string `json:"createdAt,omitempty"`
27+
UpdatedAt string `json:"updatedAt,omitempty"`
28+
UUID string `json:"uuid,omitempty"`
29+
Teams []string `json:"teamUuids"`
30+
Embedded EnvironmentEmbeddedItems `json:"_embedded,omitempty"`
31+
}
32+
33+
type EnvironmentEmbeddedItems struct {
34+
Teams []Team `json:"teams,omitempty"`
35+
}
36+
37+
// POST environments
38+
// {"uuid":"2739c79b-a6ba-4398-be7a-85ec96f79fbe","name":"test1","displayName":"test1 with teams","production":false,"createdAt":"2022-03-07T12:22:05+00:00","teamUuids":["6d746ad5-919f-49e3-84c0-648cafc5d912"],"_embedded":{"teams":[{"uuid":"6d746ad5-919f-49e3-84c0-648cafc5d912","name":"Pactflow Demos","_links":{"self":{"title":"Team","href":"https://testdemo.pactflow.io/admin/teams/6d746ad5-919f-49e3-84c0-648cafc5d912"}}}]},"_links":{"self":{"title":"Environment","name":"test1","href":"https://testdemo.pactflow.io/environments/2739c79b-a6ba-4398-be7a-85ec96f79fbe"},"pb:currently-deployed-deployed-versions":{"title":"Versions currently deployed to test1 with teams environment","href":"https://testdemo.pactflow.io/environments/2739c79b-a6ba-4398-be7a-85ec96f79fbe/deployed-versions/currently-deployed"},"pb:currently-supported-released-versions":{"title":"Versions released and supported in test1 with teams environment","href":"https://testdemo.pactflow.io/environments/2739c79b-a6ba-4398-be7a-85ec96f79fbe/released-versions/currently-supported"},"pb:environments":{"title":"Environments","href":"https://testdemo.pactflow.io/environments"}}}
39+
40+
// TODO: why does the GET not return `teamUuids` also?
41+
42+
// GET environments/:env
43+
44+
// {
45+
// "uuid": "e188cc63-7e49-4243-8fba-a8e5437d7d5c",
46+
// "name": "aoeuaoeua",
47+
// "displayName": "aoeuaoeu",
48+
// "production": true,
49+
// "updatedAt": "2022-03-02T09:29:02+00:00",
50+
// "createdAt": "2022-03-02T09:28:34+00:00",
51+
// "_embedded": {
52+
// "teams": [
53+
// {
54+
// "uuid": "219af87b-7a6f-4efb-89dd-9cdd79a050d1",
55+
// "name": "O'reilly superstream",
56+
// "_links": {
57+
// "self": {
58+
// "title": "Team",
59+
// "href": "https://testdemo.pactflow.io/admin/teams/219af87b-7a6f-4efb-89dd-9cdd79a050d1"
60+
// }
61+
// }
62+
// }
63+
// ]
64+
// },
65+
// "_links": {
66+
// "self": {
67+
// "title": "Environment",
68+
// "name": "aoeuaoeua",
69+
// "href": "https://testdemo.pactflow.io/environments/e188cc63-7e49-4243-8fba-a8e5437d7d5c"
70+
// },
71+
// "pb:currently-deployed-deployed-versions": {
72+
// "title": "Versions currently deployed to aoeuaoeu environment",
73+
// "href": "https://testdemo.pactflow.io/environments/e188cc63-7e49-4243-8fba-a8e5437d7d5c/deployed-versions/currently-deployed"
74+
// },
75+
// "pb:currently-supported-released-versions": {
76+
// "title": "Versions released and supported in aoeuaoeu environment",
77+
// "href": "https://testdemo.pactflow.io/environments/e188cc63-7e49-4243-8fba-a8e5437d7d5c/released-versions/currently-supported"
78+
// },
79+
// "pb:environments": {
80+
// "title": "Environments",
81+
// "href": "https://testdemo.pactflow.io/environments"
82+
// }
83+
// }
84+
// }

client/client.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ const (
3939
listTokensTemplate = "/settings/tokens"
4040
tokenRegenerateTemplate = "/settings/tokens/%s/regenerate"
4141
metadataTemplate = "/"
42+
environmentCreateTemplate = "/environments"
43+
environmentReadUpdateDeleteTemplate = "/environments/%s"
4244
)
4345

4446
const (
@@ -381,6 +383,31 @@ func (c *Client) SetTenantAuthenticationSettings(r broker.AuthenticationSettings
381383
return res.(*broker.AuthenticationSettings), err
382384
}
383385

386+
// ReadEnvironment gets an Environment
387+
func (c *Client) ReadEnvironment(uuid string) (*broker.Environment, error) {
388+
res, err := c.doCrud("GET", urlEncodeTemplate(environmentReadUpdateDeleteTemplate, uuid), nil, new(broker.Environment))
389+
return res.(*broker.Environment), err
390+
}
391+
392+
// CreateEnvironment creates an Environment
393+
func (c *Client) CreateEnvironment(p broker.EnvironmentCreateOrUpdateRequest) (*broker.EnvironmentCreateOrUpdateResponse, error) {
394+
res, err := c.doCrud("POST", environmentCreateTemplate, p, new(broker.EnvironmentCreateOrUpdateResponse))
395+
return res.(*broker.EnvironmentCreateOrUpdateResponse), err
396+
}
397+
398+
// UpdateEnvironment updates an Environment
399+
func (c *Client) UpdateEnvironment(p broker.EnvironmentCreateOrUpdateRequest) (*broker.EnvironmentCreateOrUpdateResponse, error) {
400+
res, err := c.doCrud("PUT", urlEncodeTemplate(environmentReadUpdateDeleteTemplate, p.UUID), p, new(broker.EnvironmentCreateOrUpdateResponse))
401+
return res.(*broker.EnvironmentCreateOrUpdateResponse), err
402+
}
403+
404+
// DeleteEnvironment removes an Environment
405+
func (c *Client) DeleteEnvironment(p broker.Environment) error {
406+
_, err := c.doCrud("DELETE", urlEncodeTemplate(environmentReadUpdateDeleteTemplate, p.UUID), nil, nil)
407+
408+
return err
409+
}
410+
384411
func (c *Client) newRequest(method, path string, body interface{}) (*http.Request, error) {
385412
rel := &url.URL{Path: path}
386413
u := c.Config.BaseURL.ResolveReference(rel)

0 commit comments

Comments
 (0)