-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: update sql review api tutorial
- Loading branch information
Showing
3 changed files
with
24 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ estimated_time: '40 mins' | |
description: 'Learn how to use the Bytebase API to configure SQL review rules in Bytebase' | ||
--- | ||
|
||
Bytebase is a database DevOps and CI/CD tool designed for developers, DBAs, and platform engineering teams. While it offers an intuitive GUI for managing database schema changes and access control, some teams may want to integrate Bytebase into their existing DevOps platforms using the [Bytebase API](/docs/api/overview/). | ||
Bytebase is a database DevSecOps platform designed for developers, security, DBA, and platform engineering teams. While it offers an intuitive GUI for managing database schema changes and access control, some teams may want to integrate Bytebase into their existing DevOps platforms using the [Bytebase API](/docs/api/overview/). | ||
|
||
This tutorial will guide you through configuring SQL review rules using the Bytebase API. This approach allows you to manage SQL review rules as code within your repository, enabling DBAs or platform engineering teams to apply them to Bytebase as needed. | ||
|
||
|
@@ -32,35 +32,33 @@ This tutorial code repository is at https://github.com/bytebase/api-example/tree | |
|
||
<IncludeBlock url="/docs/share/tutorials/create-service-account"></IncludeBlock> | ||
|
||
## Run Scripts in Terminal | ||
|
||
### Generate the Token | ||
## Obtain the Access Token | ||
|
||
1. Go to [Bytebase API Example | ||
repo](https://github.com/bytebase/api-example) and clone it. | ||
|
||
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`. | ||
|
||
```bash | ||
export bytebase_url=http://localhost:8080 | ||
export [email protected] | ||
export bytebase_password=bbs_xxxxxxxxxxxxxilcLVG | ||
bytebase_token=$(curl -v ${bytebase_url}/v1/auth/login \ | ||
--data-raw '{"email":"'${bytebase_account}'","password":"'${bytebase_password}'","web":true}' \ | ||
--compressed 2>&1 | grep token | grep -o 'access-token=[^;]*;' | grep -o '[^;]*' | sed 's/access-token=//g; s/;//g') | ||
echo $bytebase_token | ||
export bytebase_url=http://localhost:8080 | ||
export [email protected] | ||
export bytebase_password=bbs_xxxxxxxxxxxxxilcLVG | ||
bytebase_token=$(curl -v ${bytebase_url}/v1/auth/login \ | ||
--data-raw '{"email":"'${bytebase_account}'","password":"'${bytebase_password}'","web":true}' \ | ||
--compressed 2>&1 | grep token | grep -o 'access-token=[^;]*;' | grep -o '[^;]*' | sed 's/access-token=//g; s/;//g') | ||
echo $bytebase_token | ||
``` | ||
|
||
### Configure SQL Review Policies | ||
## Configure SQL Review Policies | ||
|
||
1. Continue following the `README.md` to run the scripts. | ||
|
||
```bash | ||
curl --request PATCH ${bytebase_url}/v1/reviewConfigs/basic \ | ||
curl --request PATCH ${bytebase_url}/v1/reviewConfigs/basic \ | ||
--header 'Authorization: Bearer '${bytebase_token} \ | ||
--data @policy/basic.json | ||
curl --request PATCH ${bytebase_url}/v1/reviewConfigs/advanced \ | ||
|
||
curl --request PATCH ${bytebase_url}/v1/reviewConfigs/advanced \ | ||
--header 'Authorization: Bearer '${bytebase_token} \ | ||
--data @policy/advanced.json | ||
``` | ||
|
@@ -71,16 +69,16 @@ This tutorial code repository is at https://github.com/bytebase/api-example/tree | |
1. To delete the SQL review rules, use the following commands: | ||
|
||
```bash | ||
curl --request PATCH "${bytebase_url}/v1/reviewConfigs/basic?allow_missing=true&update_mask=rules" \ | ||
curl --request PATCH "${bytebase_url}/v1/reviewConfigs/basic?allow_missing=true&update_mask=rules" \ | ||
--header 'Authorization: Bearer '${bytebase_token} \ | ||
--data @policy/basic.json | ||
|
||
curl --request PATCH "${bytebase_url}/v1/reviewConfigs/advanced?allow_missing=true&update_mask=rules" \ | ||
curl --request PATCH "${bytebase_url}/v1/reviewConfigs/advanced?allow_missing=true&update_mask=rules" \ | ||
--header 'Authorization: Bearer '${bytebase_token} \ | ||
--data @policy/advanced.json | ||
``` | ||
|
||
### Apply SQL Review Policies to Resources | ||
## Attach SQL Review Policies to Resources | ||
|
||
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. | ||
|
||
|
@@ -113,21 +111,21 @@ You may notice that the SQL review rules are not applied to any resources yet fr | |
1. Go to `Sample Project` page, click **Setting** on the left sidebar to see the applied the SQL review rules. | ||
![bb-project-setting](/content/docs/tutorials/api-sql-review/bb-project-setting.webp) | ||
|
||
1. To delete SQL review rules from environments and projects, use the following commands: | ||
1. To detach SQL review policies from environments and projects, use the following commands: | ||
|
||
```bash | ||
curl --request DELETE ${bytebase_url}/v1/environments/test/policies/tag \ | ||
curl --request DELETE ${bytebase_url}/v1/environments/test/policies/tag \ | ||
--header 'Authorization: Bearer '${bytebase_token} | ||
|
||
curl --request DELETE ${bytebase_url}/v1/environments/prod/policies/tag \ | ||
curl --request DELETE ${bytebase_url}/v1/environments/prod/policies/tag \ | ||
--header 'Authorization: Bearer '${bytebase_token} | ||
``` | ||
|
||
```bash | ||
curl --request DELETE ${bytebase_url}/v1/projects/project-sample/policies/tag \ | ||
--header 'Authorization: Bearer '${bytebase_token} | ||
curl --request DELETE ${bytebase_url}/v1/projects/project-sample/policies/tag \ | ||
--header 'Authorization: Bearer '${bytebase_token} | ||
``` | ||
|
||
## Summary | ||
|
||
Congratulations! You can now configure SQL review rules using the Bytebase API, in addition to the Bytebase GUI, making SQL review policy as code a reality. | ||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters