Skip to content

Commit 28f6c71

Browse files
authored
docs: update sql review tut (#516)
* docs: update sql-review tut * update * update
1 parent dee9af0 commit 28f6c71

File tree

12 files changed

+28
-27
lines changed

12 files changed

+28
-27
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
1. Log in as the admin user, and go to **Security & Policy > Users & Groups**. Click **+ Add User**, fill in with `api-example`, choose the `DBA` role that is sufficient for this tutorial and click **Confirm**.
1+
1. Log in as 'Workspace Admin', and go to **IAM & Admin** > **Users & Groups**. Click **+ Add User**, fill in with `api-sample`, choose the `Workspace DBA` role sufficient for this tutorial and click **Confirm**.
22
![service-account-create](/content/docs/tutorials/share/add-service-account.webp)
33

4-
1. Find the newly created service account and click on **Copy Service Key**. We will use this token to authenticate the API calls.
4+
1. Find the newly created service account and **Copy Service Key**. We will use this token to authenticate the API calls.
55
![service-account-key](/content/docs/tutorials/share/service-account-key.webp)

content/docs/tutorials/api-sql-review.md

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ This tutorial will guide you through configuring SQL review rules using the Byte
1515

1616
<HintBlock type="info">
1717

18-
This tutorial code repository is at https://github.com/bytebase/api-example/tree/main/sql-review
18+
[Tutorial Code Repository](https://github.com/bytebase/api-example/tree/main/sql-review)
1919

2020
</HintBlock>
2121

@@ -34,15 +34,16 @@ This tutorial code repository is at https://github.com/bytebase/api-example/tree
3434

3535
## Obtain the Access Token
3636

37-
1. Go to [Bytebase API Example
38-
repo](https://github.com/bytebase/api-example) and clone it.
37+
1. Go to [Bytebase API Example repo](https://github.com/bytebase/api-example) and clone it.
3938

40-
1. Go to subfolder `sql-review`, and follow the instructions in the `README.md` to run the scripts. replace the `bytebase_url`, `bytebase_account`, `bytebase_password` with your own values. Then you will get a `bytebase_token` looks like `ey....9V8s`.
39+
1. Navigate to the `sql-review` subfolder and follow the instructions in the `README.md` file of the example code repository to execute the scripts.
40+
41+
1. Replace `bytebase_url`, `bytebase_account`, and `bytebase_password` in the commands below with your own values, then run them to obtain a `bytebase_token` in your terminal.
4142

4243
```bash
4344
export bytebase_url=http://localhost:8080
4445
export bytebase_account=api-sample@service.bytebase.com
45-
export bytebase_password=bbs_xxxxxxxxxxxxxilcLVG
46+
export bytebase_password=bbs_************ilcLVG
4647
bytebase_token=$(curl -v ${bytebase_url}/v1/auth/login \
4748
--data-raw '{"email":"'${bytebase_account}'","password":"'${bytebase_password}'","web":true}' \
4849
--compressed 2>&1 | grep token | grep -o 'access-token=[^;]*;' | grep -o '[^;]*' | sed 's/access-token=//g; s/;//g')
@@ -53,21 +54,6 @@ This tutorial code repository is at https://github.com/bytebase/api-example/tree
5354

5455
1. Continue following the `README.md` to run the scripts.
5556

56-
```bash
57-
curl --request PATCH ${bytebase_url}/v1/reviewConfigs/basic \
58-
--header 'Authorization: Bearer '${bytebase_token} \
59-
--data @policy/basic.json
60-
61-
curl --request PATCH ${bytebase_url}/v1/reviewConfigs/advanced \
62-
--header 'Authorization: Bearer '${bytebase_token} \
63-
--data @policy/advanced.json
64-
```
65-
66-
1. In the Bytebase console, navigate to **CI/CD > SQL Review** to see the applied SQL review rules. You may click **Edit** to change the rules.
67-
![bb-sql-review-config](/content/docs/tutorials/api-sql-review/bb-sql-review-config.webp)
68-
69-
1. To delete the SQL review rules, use the following commands:
70-
7157
```bash
7258
curl --request PATCH "${bytebase_url}/v1/reviewConfigs/basic?allow_missing=true&update_mask=rules" \
7359
--header 'Authorization: Bearer '${bytebase_token} \
@@ -78,11 +64,14 @@ This tutorial code repository is at https://github.com/bytebase/api-example/tree
7864
--data @policy/advanced.json
7965
```
8066

67+
1. In the Bytebase console, navigate to **CI/CD > SQL Review** to see the applied SQL review rules. You may click **Edit** to change the rules.
68+
![sql-review-config](/content/docs/tutorials/api-sql-review/sql-review-config.webp)
69+
8170
## Attach SQL Review Policies to Resources
8271

83-
You may notice that the SQL review rules are not applied to any resources yet from the above screenshot. In Bytebase, the SQL review rules can be applied to the `environments` or `projects`. Project-level rules take precedence over environment-level rules.
72+
We'll apply these SQL review rules to `environments` or `projects`. Project-level rules take precedence over environment-level rules.
8473

85-
1. Follow the `README.md` to run the scripts to apply the SQL review rules to environments.
74+
1. Run these command in 'README.md' of the repo to apply the SQL review rules to environments.
8675

8776
```bash
8877
curl --request PATCH "${bytebase_url}/v1/environments/test/policies/tag?allow_missing=true&update_mask=payload" \
@@ -103,15 +92,15 @@ You may notice that the SQL review rules are not applied to any resources yet fr
10392
```
10493

10594
1. On the **CI/CD > SQL Review** page, you will see the SQL review rules are applied to environments and projects.
106-
![bb-sql-review-config-rsc](/content/docs/tutorials/api-sql-review/bb-sql-review-config-rsc.webp)
95+
![sql-review-config-apply](/content/docs/tutorials/api-sql-review/sql-review-config-apply.webp)
10796

10897
1. Go to **Environments** page, click **Test** environment to see the applied SQL review rules.
109-
![bb-env](/content/docs/tutorials/api-sql-review/bb-env.webp)
98+
![sql-review-env](/content/docs/tutorials/api-sql-review/sql-review-env.webp)
11099

111100
1. Go to `Sample Project` page, click **Setting** on the left sidebar to see the applied the SQL review rules.
112101
![bb-project-setting](/content/docs/tutorials/api-sql-review/bb-project-setting.webp)
113102

114-
1. To detach SQL review policies from environments and projects, use the following commands:
103+
1. To detach SQL review policies from environments, use the following commands:
115104

116105
```bash
117106
curl --request DELETE ${bytebase_url}/v1/environments/test/policies/tag \
@@ -121,11 +110,23 @@ You may notice that the SQL review rules are not applied to any resources yet fr
121110
--header 'Authorization: Bearer '${bytebase_token}
122111
```
123112

113+
Similarly as to detach from projects:
114+
124115
```bash
125116
curl --request DELETE ${bytebase_url}/v1/projects/project-sample/policies/tag \
126117
--header 'Authorization: Bearer '${bytebase_token}
127118
```
128119

120+
1. To delete the SQL review rules, use the following commands:
121+
122+
```bash
123+
curl --request DELETE ${bytebase_url}/v1/reviewConfigs/basic \
124+
--header 'Authorization: Bearer '${bytebase_token}
125+
126+
curl --request DELETE ${bytebase_url}/v1/reviewConfigs/advanced \
127+
--header 'Authorization: Bearer '${bytebase_token}
128+
```
129+
129130
## Summary
130131

131132
Congratulations! You can now codify SQL review rules using the Bytebase API, in addition to the Bytebase GUI, making SQL review policy as code a reality.
-80.9 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
96.4 KB
Loading
91.7 KB
Loading
122 KB
Loading
54 KB
Loading

0 commit comments

Comments
 (0)