-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathworkspaces.go
118 lines (88 loc) · 2.71 KB
/
workspaces.go
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package rockset
import (
"context"
"net/http"
"github.com/rs/zerolog"
rockerr "github.com/rockset/rockset-go-client/errors"
"github.com/rockset/rockset-go-client/openapi"
"github.com/rockset/rockset-go-client/option"
)
// CreateWorkspace creates a new workspace, with an optional description.
//
// REST API documentation https://docs.rockset.com/rest-api/#createworkspace
func (rc *RockClient) CreateWorkspace(ctx context.Context, workspace string,
options ...option.WorkspaceOption) (openapi.Workspace, error) {
var err error
var httpResp *http.Response
var resp *openapi.CreateWorkspaceResponse
q := rc.WorkspacesApi.CreateWorkspace(ctx)
req := openapi.NewCreateWorkspaceRequest(workspace)
opts := option.WorkspaceOptions{}
for _, o := range options {
o(&opts)
}
if opts.Description != nil {
req.Description = opts.Description
}
err = rc.Retry(ctx, func() error {
resp, httpResp, err = q.Body(*req).Execute()
return rockerr.NewWithStatusCode(err, httpResp)
})
if err != nil {
return openapi.Workspace{}, err
}
return resp.GetData(), nil
}
// GetWorkspace gets a workspace.
//
// REST API documentation https://docs.rockset.com/rest-api/#getworkspace
func (rc *RockClient) GetWorkspace(ctx context.Context, workspace string) (openapi.Workspace, error) {
var err error
var httpResp *http.Response
var resp *openapi.GetWorkspaceResponse
log := zerolog.Ctx(ctx)
q := rc.WorkspacesApi.GetWorkspace(ctx, workspace)
err = rc.Retry(ctx, func() error {
resp, httpResp, err = q.Execute()
return rockerr.NewWithStatusCode(err, httpResp)
})
if err != nil {
return openapi.Workspace{}, err
}
data := resp.GetData()
log.Debug().Str("name", data.GetName()).Msg("get workspace successful")
return data, nil
}
// ListWorkspaces list all workspaces.
//
// REST API documentation https://docs.rockset.com/rest-api/#listworkspaces
func (rc *RockClient) ListWorkspaces(ctx context.Context) ([]openapi.Workspace, error) {
var err error
var httpResp *http.Response
var resp *openapi.ListWorkspacesResponse
q := rc.WorkspacesApi.ListWorkspaces(ctx)
err = rc.Retry(ctx, func() error {
resp, httpResp, err = q.Execute()
return rockerr.NewWithStatusCode(err, httpResp)
})
if err != nil {
return nil, err
}
return resp.GetData(), nil
}
// DeleteWorkspace deletes a workspace.
//
// REST API documentation https://docs.rockset.com/rest-api/#deleteworkspace
func (rc *RockClient) DeleteWorkspace(ctx context.Context, name string) error {
var err error
var httpResp *http.Response
q := rc.WorkspacesApi.DeleteWorkspace(ctx, name)
err = rc.Retry(ctx, func() error {
_, httpResp, err = q.Execute()
return rockerr.NewWithStatusCode(err, httpResp)
})
if err != nil {
return err
}
return nil
}