Skip to content

Commit 4d206dc

Browse files
author
Gogen120
committed
Update response and query fields
- Added new fields for the response and query params for some entities - Updated README - Updated Go version in GitHub Actions - Fix golangci-lint issues
1 parent db29407 commit 4d206dc

32 files changed

+409
-403
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- name: Checkout
14-
uses: actions/checkout@v3
14+
uses: actions/checkout@v4
1515

1616
- uses: actions/setup-go@v3
1717
with:
18-
go-version: 1.17
18+
go-version: 1.21
1919

2020
- name: golangci-lint
2121
uses: golangci/golangci-lint-action@v3
2222
with:
23-
version: v1.39
23+
version: v1.55.2

.github/workflows/unit-tests.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ jobs:
1313

1414
steps:
1515
- name: Checkout
16-
uses: actions/checkout@v2
16+
uses: actions/checkout@v4
1717

1818
- name: Set up Go
19-
uses: actions/setup-go@v2
19+
uses: actions/setup-go@v3
2020
with:
21-
go-version: 1.16
21+
go-version: 1.21
2222

2323
- name: Run test
2424
run: make unittest

.golangci.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ linters:
2121
- godox
2222
- goprintffuncname
2323
- gosimple
24-
- ifshort
2524
- lll
2625
- makezero
2726
- nakedret
@@ -55,8 +54,10 @@ linters-settings:
5554
- fieldalignment
5655
lll:
5756
tab-width: 4
58-
nolintlint:
59-
allow-leading-space: false
57+
dupl:
58+
threshold: 500
59+
revive:
60+
severity: error
6061
issues:
6162
max-issues-per-linter: 0
6263
max-same-issues: 0

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@ The Go library documentation is available at [go.dev](https://pkg.go.dev/github.
1212

1313
You can use this library to work with the following objects of the Selectel Managed Databases Service:
1414

15-
* datastore
15+
* acl
16+
* available extension
17+
* configuration parameter
1618
* database
17-
* user
18-
* grant
19+
* datastore
1920
* datastore type
20-
* flavor
2121
* extension
22-
* available extension
23-
* configuration parameter
24-
* prometheus metrics tokens
22+
* flavor
23+
* grant
2524
* logical replication slots
25+
* prometheus metrics tokens
26+
* topic
27+
* user
2628

2729
## Getting started
2830

@@ -56,6 +58,7 @@ Selectel Managed Databases Service currently has the following API endpoint:
5658
| https://ru-9.dbaas.selcloud.ru/v1 | ru-9 |
5759
| https://nl-1.dbaas.selcloud.ru/v1 | nl-1 |
5860
| https://uz-1.dbaas.selcloud.ru/v1 | uz-1 |
61+
| https://kz-1.dbaas.selcloud.ru/v1 | kz-1 |
5962

6063
You can also retrieve all available API endpoints from the Identity
6164
catalog.

acl.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,11 @@ type ACLQueryParams struct {
4949
Status Status `json:"status,omitempty"`
5050
}
5151

52+
const ACLsURI = "/acls"
53+
5254
// ACLs returns all ACLs.
5355
func (api *API) ACLs(ctx context.Context, params *ACLQueryParams) ([]ACL, error) {
54-
uri, err := setQueryParams("/acls", params)
56+
uri, err := setQueryParams(ACLsURI, params)
5557
if err != nil {
5658
return []ACL{}, err
5759
}
@@ -74,7 +76,7 @@ func (api *API) ACLs(ctx context.Context, params *ACLQueryParams) ([]ACL, error)
7476

7577
// ACL returns an ACL based on the ID.
7678
func (api *API) ACL(ctx context.Context, aclID string) (ACL, error) {
77-
uri := fmt.Sprintf("/acls/%s", aclID)
79+
uri := fmt.Sprintf("%s/%s", ACLsURI, aclID)
7880

7981
resp, err := api.makeRequest(ctx, http.MethodGet, uri, nil)
8082
if err != nil {
@@ -94,7 +96,6 @@ func (api *API) ACL(ctx context.Context, aclID string) (ACL, error) {
9496

9597
// CreateACL creates a new acl.
9698
func (api *API) CreateACL(ctx context.Context, opts ACLCreateOpts) (ACL, error) {
97-
uri := "/acls"
9899
createACLOpts := struct {
99100
ACL ACLCreateOpts `json:"acl"`
100101
}{
@@ -105,7 +106,7 @@ func (api *API) CreateACL(ctx context.Context, opts ACLCreateOpts) (ACL, error)
105106
return ACL{}, fmt.Errorf("Error marshalling params to JSON, %w", err)
106107
}
107108

108-
resp, err := api.makeRequest(ctx, http.MethodPost, uri, requestBody)
109+
resp, err := api.makeRequest(ctx, http.MethodPost, ACLsURI, requestBody)
109110
if err != nil {
110111
return ACL{}, err
111112
}
@@ -123,7 +124,7 @@ func (api *API) CreateACL(ctx context.Context, opts ACLCreateOpts) (ACL, error)
123124

124125
// UpdateACL updates an existing acl.
125126
func (api *API) UpdateACL(ctx context.Context, aclID string, opts ACLUpdateOpts) (ACL, error) {
126-
uri := fmt.Sprintf("/acls/%s", aclID)
127+
uri := fmt.Sprintf("%s/%s", ACLsURI, aclID)
127128
updateACLOpts := struct {
128129
ACL ACLUpdateOpts `json:"acl"`
129130
}{
@@ -152,7 +153,7 @@ func (api *API) UpdateACL(ctx context.Context, aclID string, opts ACLUpdateOpts)
152153

153154
// DeleteACL deletes an existing acl.
154155
func (api *API) DeleteACL(ctx context.Context, aclID string) error {
155-
uri := fmt.Sprintf("/acls/%s", aclID)
156+
uri := fmt.Sprintf("%s/%s", ACLsURI, aclID)
156157

157158
_, err := api.makeRequest(ctx, http.MethodDelete, uri, nil)
158159
if err != nil {

acl_test.go

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ package dbaas
33
import (
44
"context"
55
"encoding/json"
6+
"fmt"
67
"net/http"
78
"testing"
89

910
"github.com/jarcoal/httpmock"
1011
"github.com/stretchr/testify/assert"
12+
"github.com/stretchr/testify/require"
1113
)
1214

1315
const aclID = "20d7bcf4-f8d6-4bf6-b8f6-46cb440a87f4"
@@ -16,7 +18,7 @@ const testACLNotFoundResponse = `{
1618
"error": {
1719
"code": 404,
1820
"title": "Not Found",
19-
"message": "acl 123 not found."
21+
"message": "acl %s not found."
2022
}
2123
}`
2224

@@ -119,7 +121,7 @@ func TestACLs(t *testing.T) {
119121
testClient := SetupTestClient()
120122
defer httpmock.DeactivateAndReset()
121123

122-
httpmock.RegisterResponder("GET", testClient.Endpoint+"/acls",
124+
httpmock.RegisterResponder("GET", testClient.Endpoint+ACLsURI,
123125
httpmock.NewStringResponder(200, testACLsResponse))
124126

125127
expected := []ACL{
@@ -153,50 +155,49 @@ func TestACLs(t *testing.T) {
153155

154156
actual, err := testClient.ACLs(context.Background(), nil)
155157

156-
if assert.NoError(t, err) {
157-
assert.Equal(t, expected, actual)
158-
}
158+
require.NoError(t, err)
159+
assert.Equal(t, expected, actual)
159160
}
160161

161162
func TestACL(t *testing.T) {
162163
httpmock.Activate()
163164
testClient := SetupTestClient()
164165
defer httpmock.DeactivateAndReset()
165166

166-
httpmock.RegisterResponder("GET", testClient.Endpoint+"/acls/"+aclID,
167+
httpmock.RegisterResponder("GET", testClient.Endpoint+ACLsURI+"/"+aclID,
167168
httpmock.NewStringResponder(200, testACLResponse))
168169

169170
actual, err := testClient.ACL(context.Background(), aclID)
170171

171-
if assert.NoError(t, err) {
172-
assert.Equal(t, ACLExpected, actual)
173-
}
172+
require.NoError(t, err)
173+
assert.Equal(t, ACLExpected, actual)
174174
}
175175

176176
func TestACLNotFound(t *testing.T) {
177177
httpmock.Activate()
178178
testClient := SetupTestClient()
179179
defer httpmock.DeactivateAndReset()
180180

181-
httpmock.RegisterResponder("GET", testClient.Endpoint+"/acls/123",
182-
httpmock.NewStringResponder(404, testACLNotFoundResponse))
181+
notFoundResponse := fmt.Sprintf(testACLNotFoundResponse, NotFoundEntityID)
182+
httpmock.RegisterResponder("GET", testClient.Endpoint+ACLsURI+"/"+NotFoundEntityID,
183+
httpmock.NewStringResponder(404, notFoundResponse))
183184

184185
expected := &DBaaSAPIError{}
185186
expected.APIError.Code = 404
186187
expected.APIError.Title = ErrorNotFoundTitle
187-
expected.APIError.Message = "acl 123 not found."
188+
expected.APIError.Message = fmt.Sprintf("acl %s not found.", NotFoundEntityID)
188189

189-
_, err := testClient.ACL(context.Background(), "123")
190+
_, err := testClient.ACL(context.Background(), NotFoundEntityID)
190191

191-
assert.ErrorAs(t, err, &expected)
192+
require.ErrorAs(t, err, &expected)
192193
}
193194

194195
func TestCreateACL(t *testing.T) {
195196
httpmock.Activate()
196197
testClient := SetupTestClient()
197198
defer httpmock.DeactivateAndReset()
198199

199-
httpmock.RegisterResponder("POST", testClient.Endpoint+"/acls",
200+
httpmock.RegisterResponder("POST", testClient.Endpoint+ACLsURI,
200201
func(req *http.Request) (*http.Response, error) {
201202
if err := json.NewDecoder(req.Body).Decode(&ACLCreateOpts{}); err != nil {
202203
return httpmock.NewStringResponse(400, ""), err
@@ -228,17 +229,16 @@ func TestCreateACL(t *testing.T) {
228229

229230
ACLCreateExpected := ACLExpected
230231
ACLCreateExpected.Status = StatusPendingCreate
231-
if assert.NoError(t, err) {
232-
assert.Equal(t, ACLCreateExpected, actual)
233-
}
232+
require.NoError(t, err)
233+
assert.Equal(t, ACLCreateExpected, actual)
234234
}
235235

236236
func TestCreateACLInvalidDatastoreID(t *testing.T) {
237237
httpmock.Activate()
238238
testClient := SetupTestClient()
239239
defer httpmock.DeactivateAndReset()
240240

241-
httpmock.RegisterResponder("POST", testClient.Endpoint+"/acls",
241+
httpmock.RegisterResponder("POST", testClient.Endpoint+ACLsURI,
242242
httpmock.NewStringResponder(400, testCreateACLInvalidDatastoreIDResponse))
243243

244244
expected := &DBaaSAPIError{}
@@ -258,15 +258,15 @@ func TestCreateACLInvalidDatastoreID(t *testing.T) {
258258

259259
_, err := testClient.CreateACL(context.Background(), createACLOpts)
260260

261-
assert.ErrorAs(t, err, &expected)
261+
require.ErrorAs(t, err, &expected)
262262
}
263263

264264
func TestUpdateACL(t *testing.T) {
265265
httpmock.Activate()
266266
testClient := SetupTestClient()
267267
defer httpmock.DeactivateAndReset()
268268

269-
httpmock.RegisterResponder("PUT", testClient.Endpoint+"/acls/"+aclID,
269+
httpmock.RegisterResponder("PUT", testClient.Endpoint+ACLsURI+"/"+aclID,
270270
func(req *http.Request) (*http.Response, error) {
271271
if err := json.NewDecoder(req.Body).Decode(&ACLUpdateOpts{}); err != nil {
272272
return httpmock.NewStringResponse(400, ""), err
@@ -294,17 +294,16 @@ func TestUpdateACL(t *testing.T) {
294294

295295
ACLUpdateExpexted := ACLExpected
296296
ACLUpdateExpexted.Status = StatusPendingUpdate
297-
if assert.NoError(t, err) {
298-
assert.Equal(t, ACLUpdateExpexted, actual)
299-
}
297+
require.NoError(t, err)
298+
assert.Equal(t, ACLUpdateExpexted, actual)
300299
}
301300

302301
func TestUpdateACLInvalidResponse(t *testing.T) {
303302
httpmock.Activate()
304303
testClient := SetupTestClient()
305304
defer httpmock.DeactivateAndReset()
306305

307-
httpmock.RegisterResponder("PUT", testClient.Endpoint+"/acls/"+aclID,
306+
httpmock.RegisterResponder("PUT", testClient.Endpoint+ACLsURI+"/"+aclID,
308307
httpmock.NewStringResponder(400, testUpdateACLInvalidResponse))
309308

310309
expected := &DBaaSAPIError{}
@@ -320,5 +319,5 @@ func TestUpdateACLInvalidResponse(t *testing.T) {
320319

321320
_, err := testClient.UpdateACL(context.Background(), aclID, updateACLOpts)
322321

323-
assert.ErrorAs(t, err, &expected)
322+
require.ErrorAs(t, err, &expected)
324323
}

available_extension.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ type AvailableExtension struct {
1515
DependencyIDs []string `json:"dependency_ids"`
1616
}
1717

18+
const AvailableExtensionsURI = "/available-extensions"
19+
1820
// AvailableExtensions returns all available extensions.
1921
func (api *API) AvailableExtensions(ctx context.Context) ([]AvailableExtension, error) {
20-
uri := "/available-extensions"
21-
22-
resp, err := api.makeRequest(ctx, http.MethodGet, uri, nil)
22+
resp, err := api.makeRequest(ctx, http.MethodGet, AvailableExtensionsURI, nil)
2323
if err != nil {
2424
return []AvailableExtension{}, err
2525
}
@@ -37,7 +37,7 @@ func (api *API) AvailableExtensions(ctx context.Context) ([]AvailableExtension,
3737

3838
// AvailableExtension returns an available extension based on the ID.
3939
func (api *API) AvailableExtension(ctx context.Context, availableExtensionID string) (AvailableExtension, error) {
40-
uri := fmt.Sprintf("/available-extensions/%s", availableExtensionID)
40+
uri := fmt.Sprintf("%s/%s", AvailableExtensionsURI, availableExtensionID)
4141

4242
resp, err := api.makeRequest(ctx, http.MethodGet, uri, nil)
4343
if err != nil {

0 commit comments

Comments
 (0)