Skip to content

Commit e2d5c4a

Browse files
committed
Added WorkspaceConnections.Update
1 parent eff845c commit e2d5c4a

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ func (c *Client) WorkspaceOutputs() WorkspaceOutputs {
121121
func (c *Client) WorkspaceOutputCredentials() WorkspaceOutputCredentials {
122122
return WorkspaceOutputCredentials{Client: c}
123123
}
124+
func (c *Client) WorkspaceConnections() WorkspaceConnections {
125+
return WorkspaceConnections{Client: c}
126+
}
124127
func (c *Client) WorkspaceVariables() WorkspaceVariables {
125128
return WorkspaceVariables{Client: c}
126129
}

types/connection.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,8 @@ func (c *Connection) TargetEquals(other Connection) bool {
5353
return isConnectionTargetEqual(c.DesiredTarget, other.DesiredTarget) &&
5454
isConnectionTargetEqual(c.EffectiveTarget, other.EffectiveTarget)
5555
}
56+
57+
type ConnectionInput struct {
58+
Name string `json:"name"`
59+
DesiredTarget *ConnectionTarget `json:"desiredTarget"`
60+
}

workspace_connections.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package api
2+
3+
import (
4+
"context"
5+
"encoding/json"
6+
"fmt"
7+
"gopkg.in/nullstone-io/go-api-client.v0/response"
8+
"gopkg.in/nullstone-io/go-api-client.v0/types"
9+
"net/http"
10+
)
11+
12+
type WorkspaceConnections struct {
13+
Client *Client
14+
}
15+
16+
func (wc WorkspaceConnections) basePath(stackId, blockId, envId int64) string {
17+
return fmt.Sprintf("/orgs/%s/stacks/%d/blocks/%d/envs/%d/connections", wc.Client.Config.OrgName, stackId, blockId, envId)
18+
}
19+
20+
func (wc WorkspaceConnections) Update(ctx context.Context, stackId, blockId, envId int64, input []types.ConnectionInput) (*http.Response, error) {
21+
raw, _ := json.Marshal(input)
22+
res, err := wc.Client.Do(ctx, http.MethodPut, wc.basePath(stackId, blockId, envId), nil, nil, json.RawMessage(raw))
23+
if err != nil {
24+
return nil, err
25+
}
26+
27+
return res, response.Verify(res)
28+
}

0 commit comments

Comments
 (0)