Skip to content

Commit d9e2246

Browse files
authored
feat: change ping to verify endpoint (#161)
1 parent a65d8e0 commit d9e2246

File tree

5 files changed

+29
-8
lines changed

5 files changed

+29
-8
lines changed

.github/workflows/ci.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Setup Go
1919
uses: actions/setup-go@v5
2020
with:
21-
go-version: "1.21"
21+
go-version: "1.24"
2222

2323
- name: Unittest
2424
run: |
@@ -32,7 +32,7 @@ jobs:
3232
3333
notify:
3434
if: failure()
35-
needs: [ test ]
35+
needs: test
3636
runs-on: ubuntu-latest
3737
steps:
3838
- uses: actions/checkout@v4
@@ -54,4 +54,4 @@ jobs:
5454
headers: {'Content-Type': 'application/json'}
5555
});
5656
const result = await response.json();
57-
console.log(result);
57+
console.log(result);

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.7.5
1+
0.8.0

client.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,10 +761,24 @@ func (c *APIClient) UploadToStageByAPI(ctx context.Context, stage *StageLocation
761761
return nil
762762
}
763763

764+
func (c *APIClient) Verify(ctx context.Context) error {
765+
var response VerifyResponse
766+
err := c.doRequest(ctx, "POST", "/v1/verify", nil, false, &response, nil)
767+
if err != nil {
768+
return errors.Wrap(err, "verify failed")
769+
}
770+
if c.tenant != "" && response.Tenant != c.tenant {
771+
return errors.Errorf("verify tenant mismatch, expected: %s, got: %s", c.tenant, response.Tenant)
772+
}
773+
if c.user != "" && response.User != c.user {
774+
return errors.Errorf("verify user mismatch, expected: %s, got: %s", c.user, response.User)
775+
}
776+
return nil
777+
}
778+
764779
func (c *APIClient) Logout(ctx context.Context) error {
765780
if c.NeedKeepAlive() {
766-
req := &struct{}{}
767-
return c.doRequest(ctx, "POST", "/v1/session/logout/", req, c.NeedSticky(), nil, nil)
781+
return c.doRequest(ctx, "POST", "/v1/session/logout", nil, c.NeedSticky(), nil, nil)
768782
}
769783
return nil
770784
}

connection.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"sync/atomic"
1010

1111
"github.com/google/uuid"
12+
"github.com/pkg/errors"
1213
)
1314

1415
const (
@@ -98,9 +99,9 @@ func (dc *DatabendConn) cleanup() {
9899
}
99100

100101
func (dc *DatabendConn) Ping(ctx context.Context) error {
101-
_, err := dc.exec(ctx, "SELECT 1")
102+
err := dc.rest.Verify(ctx)
102103
if err != nil {
103-
return err
104+
return errors.Wrap(err, "ping failed")
104105
}
105106
return nil
106107
}

query.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,9 @@ func parseAffectedRows(queryResp *QueryResponse) (int64, error) {
137137
}
138138
return 0, nil
139139
}
140+
141+
type VerifyResponse struct {
142+
Tenant string `json:"tenant"`
143+
User string `json:"user"`
144+
Roles []string `json:"roles"`
145+
}

0 commit comments

Comments
 (0)