-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathworkspacesharing.go
More file actions
75 lines (66 loc) · 3 KB
/
workspacesharing.go
File metadata and controls
75 lines (66 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package codersdk
import (
"context"
"encoding/json"
"fmt"
"net/http"
)
// ShareableWorkspaceOwners controls whose workspaces can be shared
// within an organization.
type ShareableWorkspaceOwners string
const (
ShareableWorkspaceOwnersNone ShareableWorkspaceOwners = "none"
ShareableWorkspaceOwnersEveryone ShareableWorkspaceOwners = "everyone"
ShareableWorkspaceOwnersServiceAccounts ShareableWorkspaceOwners = "service_accounts"
)
// WorkspaceSharingSettings represents workspace sharing settings affecting an
// organization.
type WorkspaceSharingSettings struct {
// SharingGloballyDisabled is true if sharing has been disabled for this
// organization because of a deployment-wide setting.
SharingGloballyDisabled bool `json:"sharing_globally_disabled"`
// SharingDisabled is deprecated and left for backward compatibility
// purposes.
// Deprecated: use `ShareableWorkspaceOwners` instead
SharingDisabled bool `json:"sharing_disabled"`
// ShareableWorkspaceOwners controls whose workspaces can be shared
// within the organization.
ShareableWorkspaceOwners ShareableWorkspaceOwners `json:"shareable_workspace_owners" enums:"none,everyone,service_accounts"`
}
// UpdateWorkspaceSharingSettingsRequest represents workspace sharing settings
// that can be updated for an organization.
type UpdateWorkspaceSharingSettingsRequest struct {
// SharingDisabled is deprecated and left for backward compatibility
// purposes.
// Deprecated: use `ShareableWorkspaceOwners` instead
SharingDisabled bool `json:"sharing_disabled,omitempty"`
// ShareableWorkspaceOwners controls whose workspaces can be shared
// within the organization.
ShareableWorkspaceOwners ShareableWorkspaceOwners `json:"shareable_workspace_owners,omitempty" enums:"none,everyone,service_accounts"`
}
// WorkspaceSharingSettings retrieves the workspace sharing settings for an organization.
func (c *Client) WorkspaceSharingSettings(ctx context.Context, orgID string) (WorkspaceSharingSettings, error) {
res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/organizations/%s/settings/workspace-sharing", orgID), nil)
if err != nil {
return WorkspaceSharingSettings{}, err
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return WorkspaceSharingSettings{}, ReadBodyAsError(res)
}
var resp WorkspaceSharingSettings
return resp, json.NewDecoder(res.Body).Decode(&resp)
}
// PatchWorkspaceSharingSettings modifies the workspace sharing settings for an organization.
func (c *Client) PatchWorkspaceSharingSettings(ctx context.Context, orgID string, req UpdateWorkspaceSharingSettingsRequest) (WorkspaceSharingSettings, error) {
res, err := c.Request(ctx, http.MethodPatch, fmt.Sprintf("/api/v2/organizations/%s/settings/workspace-sharing", orgID), req)
if err != nil {
return WorkspaceSharingSettings{}, err
}
defer res.Body.Close()
if res.StatusCode != http.StatusOK {
return WorkspaceSharingSettings{}, ReadBodyAsError(res)
}
var resp WorkspaceSharingSettings
return resp, json.NewDecoder(res.Body).Decode(&resp)
}