Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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: 2 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ linters-settings:
disabled: true
- name: unchecked-type-assertion
disabled: true
- name: redundant-import-alias
disabled: true
gocritic:
disabled-checks:
- ifElseChain
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.2
1.0.3
15 changes: 14 additions & 1 deletion api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package api
import (
"context"

v1pb "buf.build/gen/go/bytebase/bytebase/protocolbuffers/go/v1"
v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
v1alpha1 "google.golang.org/genproto/googleapis/api/expr/v1alpha1"
)

// Client is the API message for Bytebase OpenAPI client.
Expand Down Expand Up @@ -73,4 +74,16 @@ type Client interface {
DeleteProject(ctx context.Context, projectName string) error
// UndeleteProject undeletes the project.
UndeleteProject(ctx context.Context, projectName string) (*v1pb.Project, error)

// Setting
// ListSettings lists all settings.
ListSettings(ctx context.Context) (*v1pb.ListSettingsResponse, error)
// GetSetting gets the setting by the name.
GetSetting(ctx context.Context, settingName string) (*v1pb.Setting, error)
// UpsertSetting updates or creates the setting.
UpsertSetting(ctx context.Context, upsert *v1pb.Setting, updateMasks []string) (*v1pb.Setting, error)

// Cel
// ParseExpression parse the expression string.
ParseExpression(ctx context.Context, expression string) (*v1alpha1.Expr, error)
}
51 changes: 51 additions & 0 deletions api/setting.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package api

// SettingName is the Bytebase setting name without settings/ prefix.
type SettingName string

const (
// SettingWorkspaceApproval is the setting name for workspace approval config.
SettingWorkspaceApproval SettingName = "bb.workspace.approval"
// SettingWorkspaceExternalApproval is the setting name for workspace external approval config.
SettingWorkspaceExternalApproval SettingName = "bb.workspace.approval.external"
)

// RiskLevel is the approval risk level.
type RiskLevel string

const (
// RiskLevelDefault is the default risk level, the level number should be 0.
RiskLevelDefault RiskLevel = "DEFAULT"
// RiskLevelLow is the low risk level, the level number should be 100.
RiskLevelLow RiskLevel = "LOW"
// RiskLevelModerate is the moderate risk level, the level number should be 200.
RiskLevelModerate RiskLevel = "MODERATE"
// RiskLevelHigh is the high risk level, the level number should be 300.
RiskLevelHigh RiskLevel = "HIGH"
)

// Int returns the int value for risk.
func (r RiskLevel) Int() int {
switch r {
case RiskLevelLow:
return 100
case RiskLevelModerate:
return 200
case RiskLevelHigh:
return 300
default:
return 0
}
}

// ApprovalNodeType is the type for approval node.
type ApprovalNodeType string

const (
// ApprovalNodeTypeGroup means the approval node is a group.
ApprovalNodeTypeGroup ApprovalNodeType = "GROUP"
// ApprovalNodeTypeRole means the approval node is a role, the value should be role fullname.
ApprovalNodeTypeRole ApprovalNodeType = "ROLE"
// ApprovalNodeTypeExternalNodeID means the approval node is a external node, the value should be the node id.
ApprovalNodeTypeExternalNodeID ApprovalNodeType = "EXTERNAL_NODE"
)
2 changes: 1 addition & 1 deletion client/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/pkg/errors"
"google.golang.org/protobuf/encoding/protojson"

v1pb "buf.build/gen/go/bytebase/bytebase/protocolbuffers/go/v1"
v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
)

// Login will login the user and get the response.
Expand Down
48 changes: 48 additions & 0 deletions client/cel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package client

import (
"context"
"fmt"
"net/http"
"strings"

"github.com/hashicorp/terraform-plugin-log/tflog"

v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
"github.com/pkg/errors"
v1alpha1 "google.golang.org/genproto/googleapis/api/expr/v1alpha1"
"google.golang.org/protobuf/encoding/protojson"
)

// ParseExpression parse the expression string.
func (c *client) ParseExpression(ctx context.Context, expression string) (*v1alpha1.Expr, error) {
payload, err := protojson.Marshal(&v1pb.BatchParseRequest{
Expressions: []string{expression},
})
if err != nil {
return nil, err
}

req, err := http.NewRequestWithContext(ctx, "POST", fmt.Sprintf("%s/%s/cel/batchParse", c.url, c.version), strings.NewReader(string(payload)))
if err != nil {
return nil, err
}

body, err := c.doRequest(req)
if err != nil {
return nil, err
}

tflog.Debug(ctx, fmt.Sprintf("parse cel response:\n%v", string(body)))

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

if len(res.Expressions) != 1 {
return nil, errors.Errorf("failed to parse the cel: %v", expression)
}

return res.GetExpressions()[0], nil
}
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/pkg/errors"

v1pb "buf.build/gen/go/bytebase/bytebase/protocolbuffers/go/v1"
v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"

"github.com/bytebase/terraform-provider-bytebase/api"
)
Expand Down
19 changes: 4 additions & 15 deletions client/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/url"
"strings"

v1pb "buf.build/gen/go/bytebase/bytebase/protocolbuffers/go/v1"
v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
"google.golang.org/protobuf/encoding/protojson"
)

Expand All @@ -24,8 +24,7 @@ func (c *client) GetDatabase(ctx context.Context, databaseName string) (*v1pb.Da
}

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

Expand All @@ -50,8 +49,7 @@ func (c *client) ListDatabase(ctx context.Context, instanceID, filter string) (*
}

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

Expand All @@ -65,14 +63,6 @@ func (c *client) UpdateDatabase(ctx context.Context, patch *v1pb.Database, updat
return nil, err
}

// updateMask := []string{}
// if patch.Project != nil {
// updateMask = append(updateMask, "project")
// }
// if patch.Labels != nil {
// updateMask = append(updateMask, "labels")
// }

req, err := http.NewRequestWithContext(ctx, "PATCH", fmt.Sprintf("%s/%s/%s?update_mask=%s", c.url, c.version, patch.Name, strings.Join(updateMasks, ",")), strings.NewReader(string(payload)))
if err != nil {
return nil, err
Expand All @@ -84,8 +74,7 @@ func (c *client) UpdateDatabase(ctx context.Context, patch *v1pb.Database, updat
}

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

Expand Down
17 changes: 6 additions & 11 deletions client/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"
"strings"

v1pb "buf.build/gen/go/bytebase/bytebase/protocolbuffers/go/v1"
v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
"google.golang.org/protobuf/encoding/protojson"
)

Expand All @@ -28,8 +28,7 @@ func (c *client) CreateEnvironment(ctx context.Context, environmentID string, cr
}

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

Expand All @@ -49,8 +48,7 @@ func (c *client) GetEnvironment(ctx context.Context, environmentName string) (*v
}

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

Expand All @@ -70,8 +68,7 @@ func (c *client) ListEnvironment(ctx context.Context, showDeleted bool) (*v1pb.L
}

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

Expand All @@ -96,8 +93,7 @@ func (c *client) UpdateEnvironment(ctx context.Context, patch *v1pb.Environment,
}

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

Expand Down Expand Up @@ -130,8 +126,7 @@ func (c *client) UndeleteEnvironment(ctx context.Context, environmentName string
}

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

Expand Down
17 changes: 6 additions & 11 deletions client/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"net/http"
"strings"

v1pb "buf.build/gen/go/bytebase/bytebase/protocolbuffers/go/v1"
v1pb "github.com/bytebase/bytebase/proto/generated-go/v1"
"google.golang.org/protobuf/encoding/protojson"
)

Expand All @@ -23,8 +23,7 @@ func (c *client) ListInstance(ctx context.Context, showDeleted bool) (*v1pb.List
}

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

Expand All @@ -44,8 +43,7 @@ func (c *client) GetInstance(ctx context.Context, instanceName string) (*v1pb.In
}

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

Expand All @@ -71,8 +69,7 @@ func (c *client) CreateInstance(ctx context.Context, instanceID string, instance
}

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

Expand All @@ -98,8 +95,7 @@ func (c *client) UpdateInstance(ctx context.Context, patch *v1pb.Instance, updat
}

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

Expand Down Expand Up @@ -132,8 +128,7 @@ func (c *client) UndeleteInstance(ctx context.Context, instanceName string) (*v1
}

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

Expand Down
9 changes: 3 additions & 6 deletions client/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ func (c *client) ListPolicies(ctx context.Context, find *api.PolicyFindMessage)
}

var res api.ListPolicyMessage
err = json.Unmarshal(body, &res)
if err != nil {
if err := json.Unmarshal(body, &res); err != nil {
return nil, err
}

Expand All @@ -56,8 +55,7 @@ func (c *client) GetPolicy(ctx context.Context, policyName string) (*api.PolicyM
}

var res api.PolicyMessage
err = json.Unmarshal(body, &res)
if err != nil {
if err := json.Unmarshal(body, &res); err != nil {
return nil, err
}

Expand Down Expand Up @@ -93,8 +91,7 @@ func (c *client) UpsertPolicy(ctx context.Context, patch *api.PolicyPatchMessage
}

var res api.PolicyMessage
err = json.Unmarshal(body, &res)
if err != nil {
if err := json.Unmarshal(body, &res); err != nil {
return nil, err
}

Expand Down
Loading
Loading