Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: support database catalog #83

Merged
merged 10 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.5
1.0.6
4 changes: 4 additions & 0 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ type Client interface {
ListDatabase(ctx context.Context, instanceID, filter string) (*v1pb.ListDatabasesResponse, error)
// UpdateDatabase patches the database.
UpdateDatabase(ctx context.Context, patch *v1pb.Database, updateMasks []string) (*v1pb.Database, error)
// GetDatabaseCatalog gets the database catalog by the database full name.
GetDatabaseCatalog(ctx context.Context, databaseName string) (*v1pb.DatabaseCatalog, error)
// UpdateDatabaseCatalog patches the database catalog.
UpdateDatabaseCatalog(ctx context.Context, patch *v1pb.DatabaseCatalog, updateMasks []string) (*v1pb.DatabaseCatalog, error)

// Project
// GetProject gets the project by project full name.
Expand Down
30 changes: 30 additions & 0 deletions client/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,33 @@ func (c *client) UpdateDatabase(ctx context.Context, patch *v1pb.Database, updat

return &res, nil
}

// GetDatabaseCatalog gets the database catalog by the database full name.
func (c *client) GetDatabaseCatalog(ctx context.Context, databaseName string) (*v1pb.DatabaseCatalog, error) {
body, err := c.getResource(ctx, fmt.Sprintf("%s/catalog", databaseName))
if err != nil {
return nil, err
}

var res v1pb.DatabaseCatalog
if err := ProtojsonUnmarshaler.Unmarshal(body, &res); err != nil {
return nil, err
}

return &res, nil
}

// UpdateDatabaseCatalog patches the database catalog.
func (c *client) UpdateDatabaseCatalog(ctx context.Context, patch *v1pb.DatabaseCatalog, updateMasks []string) (*v1pb.DatabaseCatalog, error) {
body, err := c.updateResource(ctx, patch.Name, patch, updateMasks, false /* allow missing = false*/)
if err != nil {
return nil, err
}

var res v1pb.DatabaseCatalog
if err := ProtojsonUnmarshaler.Unmarshal(body, &res); err != nil {
return nil, err
}

return &res, nil
}
54 changes: 54 additions & 0 deletions docs/data-sources/database_catalog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "bytebase_database_catalog Data Source - terraform-provider-bytebase"
subcategory: ""
description: |-
The database catalog data source.
---

# bytebase_database_catalog (Data Source)

The database catalog data source.



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `database` (String) The database full name in instances/{instance}/databases/{database} format

### Read-Only

- `id` (String) The ID of this resource.
- `schemas` (List of Object) (see [below for nested schema](#nestedatt--schemas))

<a id="nestedatt--schemas"></a>
### Nested Schema for `schemas`

Read-Only:

- `name` (String)
- `tables` (List of Object) (see [below for nested schema](#nestedobjatt--schemas--tables))

<a id="nestedobjatt--schemas--tables"></a>
### Nested Schema for `schemas.tables`

Read-Only:

- `classification` (String)
- `columns` (List of Object) (see [below for nested schema](#nestedobjatt--schemas--tables--columns))
- `name` (String)

<a id="nestedobjatt--schemas--tables--columns"></a>
### Nested Schema for `schemas.tables.columns`

Read-Only:

- `classification` (String)
- `labels` (Map of String)
- `name` (String)
- `semantic_type` (String)


23 changes: 0 additions & 23 deletions docs/data-sources/policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ The policy data source.
### Optional

- `masking_exception_policy` (Block List, Max: 1) (see [below for nested schema](#nestedblock--masking_exception_policy))
- `masking_policy` (Block List, Max: 1) (see [below for nested schema](#nestedblock--masking_policy))
- `parent` (String) The policy parent name for the policy, support projects/{resource id}, environments/{resource id}, instances/{resource id}, or instances/{resource id}/databases/{database name}

### Read-Only
Expand All @@ -48,30 +47,8 @@ Optional:
- `column` (String)
- `database` (String) The database full name in instances/{instance resource id}/databases/{database name} format
- `expire_timestamp` (String) The expiration timestamp in YYYY-MM-DDThh:mm:ss.000Z format
- `masking_level` (String)
- `member` (String) The member in user:{email} or group:{email} format.
- `schema` (String)
- `table` (String)



<a id="nestedblock--masking_policy"></a>
### Nested Schema for `masking_policy`

Optional:

- `mask_data` (Block List) (see [below for nested schema](#nestedblock--masking_policy--mask_data))

<a id="nestedblock--masking_policy--mask_data"></a>
### Nested Schema for `masking_policy.mask_data`

Optional:

- `column` (String)
- `full_masking_algorithm_id` (String)
- `masking_level` (String)
- `partial_masking_algorithm_id` (String)
- `schema` (String)
- `table` (String)


23 changes: 0 additions & 23 deletions docs/data-sources/policy_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Read-Only:
- `enforce` (Boolean)
- `inherit_from_parent` (Boolean)
- `masking_exception_policy` (List of Object) (see [below for nested schema](#nestedobjatt--policies--masking_exception_policy))
- `masking_policy` (List of Object) (see [below for nested schema](#nestedobjatt--policies--masking_policy))
- `name` (String)
- `type` (String)

Expand All @@ -52,30 +51,8 @@ Read-Only:
- `column` (String)
- `database` (String)
- `expire_timestamp` (String)
- `masking_level` (String)
- `member` (String)
- `schema` (String)
- `table` (String)



<a id="nestedobjatt--policies--masking_policy"></a>
### Nested Schema for `policies.masking_policy`

Read-Only:

- `mask_data` (List of Object) (see [below for nested schema](#nestedobjatt--policies--masking_policy--mask_data))

<a id="nestedobjatt--policies--masking_policy--mask_data"></a>
### Nested Schema for `policies.masking_policy.mask_data`

Read-Only:

- `column` (String)
- `full_masking_algorithm_id` (String)
- `masking_level` (String)
- `partial_masking_algorithm_id` (String)
- `schema` (String)
- `table` (String)


4 changes: 2 additions & 2 deletions docs/data-sources/setting.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ The setting data source.

### Read-Only

- `approval_flow` (Block List) (see [below for nested schema](#nestedblock--approval_flow))
- `external_approval_nodes` (Block List) (see [below for nested schema](#nestedblock--external_approval_nodes))
- `approval_flow` (Block List) Configure risk level and approval flow for different tasks. Require ENTERPRISE subscription. (see [below for nested schema](#nestedblock--approval_flow))
- `external_approval_nodes` (Block List) Configure external nodes in the approval flow. Require ENTERPRISE subscription. (see [below for nested schema](#nestedblock--external_approval_nodes))
- `id` (String) The ID of this resource.

<a id="nestedblock--approval_flow"></a>
Expand Down
63 changes: 63 additions & 0 deletions docs/resources/database_catalog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
# generated by https://github.com/hashicorp/terraform-plugin-docs
page_title: "bytebase_database_catalog Resource - terraform-provider-bytebase"
subcategory: ""
description: |-
The database catalog resource.
---

# bytebase_database_catalog (Resource)

The database catalog resource.



<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `database` (String) The database full name in instances/{instance}/databases/{database} format
- `schemas` (Block List, Min: 1) (see [below for nested schema](#nestedblock--schemas))

### Read-Only

- `id` (String) The ID of this resource.

<a id="nestedblock--schemas"></a>
### Nested Schema for `schemas`

Required:

- `tables` (Block List, Min: 1) (see [below for nested schema](#nestedblock--schemas--tables))

Optional:

- `name` (String)

<a id="nestedblock--schemas--tables"></a>
### Nested Schema for `schemas.tables`

Required:

- `columns` (Block List, Min: 1) (see [below for nested schema](#nestedblock--schemas--tables--columns))
- `name` (String)

Optional:

- `classification` (String) The classification id

<a id="nestedblock--schemas--tables--columns"></a>
### Nested Schema for `schemas.tables.columns`

Required:

- `name` (String)

Optional:

- `classification` (String) The classification id
- `labels` (Map of String)
- `semantic_type` (String) The semantic type id


2 changes: 1 addition & 1 deletion docs/resources/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ The environment resource.

### Required

- `environment_tier_policy` (String) If marked as PROTECTED, developers cannot execute any query on this environment's databases using SQL Editor by default.
- `environment_tier_policy` (String) If marked as PROTECTED, developers cannot execute any query on this environment's databases using SQL Editor by default. Require ENTERPRISE subscription.
- `order` (Number) The environment sorting order.
- `resource_id` (String) The environment unique resource id.
- `title` (String) The environment title.
Expand Down
4 changes: 2 additions & 2 deletions docs/resources/group.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
page_title: "bytebase_group Resource - terraform-provider-bytebase"
subcategory: ""
description: |-
The group resource.
The group resource. Workspace domain is required for creating groups.
---

# bytebase_group (Resource)

The group resource.
The group resource. Workspace domain is required for creating groups.



Expand Down
23 changes: 0 additions & 23 deletions docs/resources/policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ The policy resource.
- `enforce` (Boolean) Decide if the policy is enforced.
- `inherit_from_parent` (Boolean) Decide if the policy should inherit from the parent.
- `masking_exception_policy` (Block List, Max: 1) (see [below for nested schema](#nestedblock--masking_exception_policy))
- `masking_policy` (Block List, Max: 1) (see [below for nested schema](#nestedblock--masking_policy))

### Read-Only

Expand All @@ -48,30 +47,8 @@ Optional:
- `column` (String)
- `database` (String) The database full name in instances/{instance resource id}/databases/{database name} format
- `expire_timestamp` (String) The expiration timestamp in YYYY-MM-DDThh:mm:ss.000Z format
- `masking_level` (String)
- `member` (String) The member in user:{email} or group:{email} format.
- `schema` (String)
- `table` (String)



<a id="nestedblock--masking_policy"></a>
### Nested Schema for `masking_policy`

Optional:

- `mask_data` (Block List) (see [below for nested schema](#nestedblock--masking_policy--mask_data))

<a id="nestedblock--masking_policy--mask_data"></a>
### Nested Schema for `masking_policy.mask_data`

Optional:

- `column` (String)
- `full_masking_algorithm_id` (String)
- `masking_level` (String)
- `partial_masking_algorithm_id` (String)
- `schema` (String)
- `table` (String)


4 changes: 2 additions & 2 deletions docs/resources/setting.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ The setting resource.

### Optional

- `approval_flow` (Block List) (see [below for nested schema](#nestedblock--approval_flow))
- `external_approval_nodes` (Block List) (see [below for nested schema](#nestedblock--external_approval_nodes))
- `approval_flow` (Block List) Configure risk level and approval flow for different tasks. Require ENTERPRISE subscription. (see [below for nested schema](#nestedblock--approval_flow))
- `external_approval_nodes` (Block List) Configure external nodes in the approval flow. Require ENTERPRISE subscription. (see [below for nested schema](#nestedblock--external_approval_nodes))

### Read-Only

Expand Down
29 changes: 29 additions & 0 deletions examples/database/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Examples for query the environments
terraform {
required_providers {
bytebase = {
version = "1.0.6"
# For local development, please use "terraform.local/bytebase/bytebase" instead
source = "registry.terraform.io/bytebase/bytebase"
}
}
}

provider "bytebase" {
# You need to replace the account and key with your Bytebase service account.
service_account = "[email protected]"
service_key = "bbs_BxVIp7uQsARl8nR92ZZV"
# The Bytebase service URL. You can use the external URL in production.
# Check the docs about external URL: https://www.bytebase.com/docs/get-started/install/external-url
url = "https://bytebase.example.com"
}



data "bytebase_database_catalog" "employee" {
database = "instances/test-sample-instance/databases/employee"
}

output "employee_catalog" {
value = data.bytebase_database_catalog.employee
}
2 changes: 1 addition & 1 deletion examples/environments/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
terraform {
required_providers {
bytebase = {
version = "1.0.5"
version = "1.0.6"
# For local development, please use "terraform.local/bytebase/bytebase" instead
source = "registry.terraform.io/bytebase/bytebase"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/groups/main.tf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
terraform {
required_providers {
bytebase = {
version = "1.0.5"
version = "1.0.6"
# For local development, please use "terraform.local/bytebase/bytebase" instead
source = "registry.terraform.io/bytebase/bytebase"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/instances/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
terraform {
required_providers {
bytebase = {
version = "1.0.5"
version = "1.0.6"
# For local development, please use "terraform.local/bytebase/bytebase" instead
source = "registry.terraform.io/bytebase/bytebase"
}
Expand Down
Loading
Loading