Skip to content

Commit 81bb51b

Browse files
authored
Alter api (#3)
* alter get branch api * add test for sql user
1 parent 6ac3e77 commit 81bb51b

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

__tests__/main.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import {wait} from '../src/wait'
22
import {expect, test} from '@jest/globals'
3+
import {sqluser} from "../src/sqluser";
4+
import * as core from "@actions/core";
35

46
test('throws invalid number', async () => {
57
const input = parseInt('foo', 10)
@@ -13,3 +15,14 @@ test('wait 500 ms', async () => {
1315
var delta = Math.abs(end.getTime() - start.getTime())
1416
expect(delta).toBeGreaterThan(450)
1517
})
18+
19+
// replace the externalId, public key and private key with your own
20+
test('sqluser', async () => {
21+
const externalId = "{\"project_id\":\"163469\",\"cluster_id\":\"2939253\",\"branch_id\":\"branch-t393ywvw3qhswh7getjzwv\",\"branch_name\":\"syh-test2\"}"
22+
const sqlUser = await sqluser( externalId,
23+
msg => core.info(msg),
24+
"",
25+
"",
26+
"dev")
27+
console.log(sqlUser)
28+
})

dist/index.js

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/sqluser.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,22 @@ export async function sqluser(
6565
}
6666

6767
// get branch info
68-
const branchUrl = `${host}/api/internal/projects/${projectID}/clusters/${clusterID}/branches/${branchName}`
68+
const branchUrl = `${host}/api/v1beta/clusters/${clusterID}/branches/${branchID}`
6969
log(`request url to get host and port: ${branchUrl}`)
7070
const resp2 = await client.fetch(branchUrl)
7171
const branch = await resp2.json()
72-
if (branch['host'] === undefined || branch['port'] === undefined) {
72+
if (
73+
branch['endpoints'] === undefined ||
74+
branch['endpoints']['public_endpoint'] === undefined
75+
) {
7376
throw new Error(
7477
`Can not get branch host and port with: ${JSON.stringify(branch)}`
7578
)
7679
}
7780

7881
return new SqlUser(
79-
branch['host'],
80-
branch['port'],
82+
branch['endpoints']['public_endpoint']['host'],
83+
branch['endpoints']['public_endpoint']['port'],
8184
data['username'],
8285
data['password']
8386
)

0 commit comments

Comments
 (0)