Skip to content

Commit

Permalink
docs: update sql review api tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
tianzhou committed Nov 12, 2024
1 parent 51d8e11 commit 7c3689f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
2 changes: 1 addition & 1 deletion content/docs/tutorials/api-audit-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ estimated_time: '40 mins'
description: 'Learn how to use the Bytebase API to fetch audit log 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/).

![before-after](/content/docs/tutorials/api-audit-log/api-audit-log-graph.webp)

Expand Down
46 changes: 22 additions & 24 deletions content/docs/tutorials/api-sql-review.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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
```
Expand All @@ -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.

Expand Down Expand Up @@ -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.
2 changes: 1 addition & 1 deletion content/docs/tutorials/api-user-database-permission.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ estimated_time: '40 mins'
description: 'Learn how to use the Bytebase API to inspect user and database permissions.'
---

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/).

![before-after](/content/docs/tutorials/api-user-database-permission/api-user-db-permission.webp)

Expand Down

0 comments on commit 7c3689f

Please sign in to comment.