Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore(store): moving data source option to proto in store (#4991)
h3n4ld8f3cd34c7c3
diff --git a/backend/legacyapi/data_source.go b/backend/legacyapi/data_source.goindex 26e999c7a3..9ae23d2fb7 100644--- a/backend/legacyapi/data_source.go+++ b/backend/legacyapi/data_source.go@@ -38,9 +38,9 @@ const (// DataSourceOptions is the options for a data source.type DataSourceOptions struct {// SRV is used for MongoDB only.- SRV bool `json:"srv" jsonapi:"attr,srv"`+ SRV bool `json:"srv"`// AuthenticationDatabase is used for MongoDB only.- AuthenticationDatabase string `json:"authenticationDatabase" jsonapi:"attr,authenticationDatabase"`+ AuthenticationDatabase string `json:"authenticationDatabase"`}// getDefaultDataSourceOptions returns the default data source options.diff --git a/backend/store/data_source.go b/backend/store/data_source.goindex 061a3a5478..74073a335a 100644--- a/backend/store/data_source.go+++ b/backend/store/data_source.go@@ -6,8 +6,10 @@ import ("strings""github.com/pkg/errors"+ "google.golang.org/protobuf/encoding/protojson"api "github.com/bytebase/bytebase/backend/legacyapi"+ storepb "github.com/bytebase/bytebase/proto/generated-go/store")// DataSourceMessage is the message for data source.@@ -77,8 +79,8 @@ func (*Store) listDataSourceV2(ctx context.Context, tx *Tx, instanceID string) (return nil, FormatError(err)}defer rows.Close()- var dataSourceOptions api.DataSourceOptionsfor rows.Next() {+ var protoBytes []bytevar dataSourceMessage DataSourceMessageif err := rows.Scan(&dataSourceMessage.UID,@@ -93,11 +95,16 @@ func (*Store) listDataSourceV2(ctx context.Context, tx *Tx, instanceID string) (&dataSourceMessage.Host,&dataSourceMessage.Port,&dataSourceMessage.Database,- &dataSourceOptions,+ &protoBytes,); err != nil {return nil, FormatError(err)}- dataSourceMessage.SRV = dataSourceOptions.SRV+ var dataSourceOptions storepb.DataSourceOptions+ decoder := protojson.UnmarshalOptions{DiscardUnknown: true}+ if err := decoder.Unmarshal(protoBytes, &dataSourceOptions); err != nil {+ return nil, err+ }+ dataSourceMessage.SRV = dataSourceOptions.SrvdataSourceMessage.AuthenticationDatabase = dataSourceOptions.AuthenticationDatabasedataSourceMessages = append(dataSourceMessages, &dataSourceMessage)@@ -196,6 +203,7 @@ func (s *Store) UpdateDataSourceV2(ctx context.Context, patch *UpdateDataSourceM}// Use jsonb_build_object to build the jsonb object to update some fields in jsonb instead of whole column.+ // To view the json tag, please refer to the struct definition of storepb.DataSourceOptions.var optionSet []stringif v := patch.SRV; v != nil {optionSet, args = append(optionSet, fmt.Sprintf("jsonb_build_object('srv', to_jsonb($%d::BOOLEAN))", len(args)+1)), append(args, *v)@@ -241,10 +249,14 @@ func (s *Store) UpdateDataSourceV2(ctx context.Context, patch *UpdateDataSourceMfunc (*Store) addDataSourceToInstanceImplV2(ctx context.Context, tx *Tx, instanceUID, databaseUID, creatorID int, dataSource *DataSourceMessage) error {// We flatten the data source fields in DataSourceMessage, so we need to compose them in store layer before INSERT.- dataSourceOptions := api.DataSourceOptions{- SRV: dataSource.SRV,+ dataSourceOptions := storepb.DataSourceOptions{+ Srv: dataSource.SRV,AuthenticationDatabase: dataSource.AuthenticationDatabase,}+ protoBytes, err := protojson.Marshal(&dataSourceOptions)+ if err != nil {+ return errors.Wrap(err, "failed to marshal data source options")+ }if _, err := tx.ExecContext(ctx, `INSERT INTO data_source (@@ -268,7 +280,7 @@ func (*Store) addDataSourceToInstanceImplV2(ctx context.Context, tx *Tx, instanc`, creatorID, creatorID, instanceUID, databaseUID, dataSource.Title,dataSource.Type, dataSource.Username, dataSource.ObfuscatedPassword, dataSource.ObfuscatedSslKey,dataSource.ObfuscatedSslCert, dataSource.ObfuscatedSslCa, dataSource.Host, dataSource.Port,- dataSourceOptions, dataSource.Database,+ protoBytes, dataSource.Database,); err != nil {return FormatError(err)}diff --git a/frontend/src/types/proto/store/data_source.ts b/frontend/src/types/proto/store/data_source.tsnew file mode 100644index 0000000000..502f885527--- /dev/null+++ b/frontend/src/types/proto/store/data_source.ts@@ -0,0 +1,80 @@+/* eslint-disable */+import * as _m0 from "protobufjs/minimal";++export const protobufPackage = "bytebase.store";++export interface DataSourceOptions {+ /** srv is a boolean flag that indicates whether the host is a DNS SRV record. */+ srv: boolean;+ /** authentication_database is the database name to authenticate against, which stores the user credentials. */+ authenticationDatabase: string;+}++function createBaseDataSourceOptions(): DataSourceOptions {+ return { srv: false, authenticationDatabase: "" };+}++export const DataSourceOptions = {+ encode(message: DataSourceOptions, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {+ if (message.srv === true) {+ writer.uint32(8).bool(message.srv);+ }+ if (message.authenticationDatabase !== "") {+ writer.uint32(18).string(message.authenticationDatabase);+ }+ return writer;+ },++ decode(input: _m0.Reader | Uint8Array, length?: number): DataSourceOptions {+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);+ let end = length === undefined ? reader.len : reader.pos + length;+ const message = createBaseDataSourceOptions();+ while (reader.pos < end) {+ const tag = reader.uint32();+ switch (tag >>> 3) {+ case 1:+ message.srv = reader.bool();+ break;+ case 2:+ message.authenticationDatabase = reader.string();+ break;+ default:+ reader.skipType(tag & 7);+ break;+ }+ }+ return message;+ },++ fromJSON(object: any): DataSourceOptions {+ return {+ srv: isSet(object.srv) ? Boolean(object.srv) : false,+ authenticationDatabase: isSet(object.authenticationDatabase) ? String(object.authenticationDatabase) : "",+ };+ },++ toJSON(message: DataSourceOptions): unknown {+ const obj: any = {};+ message.srv !== undefined && (obj.srv = message.srv);+ message.authenticationDatabase !== undefined && (obj.authenticationDatabase = message.authenticationDatabase);+ return obj;+ },++ fromPartial(object: DeepPartial<DataSourceOptions>): DataSourceOptions {+ const message = createBaseDataSourceOptions();+ message.srv = object.srv ?? false;+ message.authenticationDatabase = object.authenticationDatabase ?? "";+ return message;+ },+};++type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;++export type DeepPartial<T> = T extends Builtin ? T+ : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>+ : T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }+ : Partial<T>;++function isSet(value: any): boolean {+ return value !== null && value !== undefined;+}diff --git a/proto/gen/grpc-doc/store/README.md b/proto/gen/grpc-doc/store/README.mdindex a2451aa27d..51da2ebcab 100644--- a/proto/gen/grpc-doc/store/README.md+++ b/proto/gen/grpc-doc/store/README.md@@ -3,6 +3,9 @@## Table of Contents+- [store/data_source.proto](#store_data_source-proto)+ - [DataSourceOptions](#bytebase-store-DataSourceOptions)+- [store/database.proto](#store_database-proto)- [ColumnMetadata](#bytebase-store-ColumnMetadata)- [DatabaseMetadata](#bytebase-store-DatabaseMetadata)@@ -33,6 +36,38 @@+<a name="store_data_source-proto"></a>+<p align="right"><a href="#top">Top</a></p>++## store/data_source.proto++++<a name="bytebase-store-DataSourceOptions"></a>++### DataSourceOptions++++| Field | Type | Label | Description |+| ----- | ---- | ----- | ----------- |+| srv | [bool](#bool) | | srv is a boolean flag that indicates whether the host is a DNS SRV record. |+| authentication_database | [string](#string) | | authentication_database is the database name to authenticate against, which stores the user credentials. |+++++++++++++++<a name="store_database-proto"></a><p align="right"><a href="#top">Top</a></p>diff --git a/proto/generated-go/store/data_source.pb.go b/proto/generated-go/store/data_source.pb.gonew file mode 100644index 0000000000..e60e326b85--- /dev/null+++ b/proto/generated-go/store/data_source.pb.go@@ -0,0 +1,157 @@+// Code generated by protoc-gen-go. DO NOT EDIT.+// versions:+// protoc-gen-go v1.28.1+// protoc (unknown)+// source: store/data_source.proto++package store++import (+ protoreflect "google.golang.org/protobuf/reflect/protoreflect"+ protoimpl "google.golang.org/protobuf/runtime/protoimpl"+ reflect "reflect"+ sync "sync"+)++const (+ // Verify that this generated code is sufficiently up-to-date.+ _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)+ // Verify that runtime/protoimpl is sufficiently up-to-date.+ _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)+)++type DataSourceOptions struct {+ state protoimpl.MessageState+ sizeCache protoimpl.SizeCache+ unknownFields protoimpl.UnknownFields++ // srv is a boolean flag that indicates whether the host is a DNS SRV record.+ Srv bool `protobuf:"varint,1,opt,name=srv,proto3" json:"srv,omitempty"`+ // authentication_database is the database name to authenticate against, which stores the user credentials.+ AuthenticationDatabase string `protobuf:"bytes,2,opt,name=authentication_database,json=authenticationDatabase,proto3" json:"authentication_database,omitempty"`+}++func (x *DataSourceOptions) Reset() {+ *x = DataSourceOptions{}+ if protoimpl.UnsafeEnabled {+ mi := &file_store_data_source_proto_msgTypes[0]+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))+ ms.StoreMessageInfo(mi)+ }+}++func (x *DataSourceOptions) String() string {+ return protoimpl.X.MessageStringOf(x)+}++func (*DataSourceOptions) ProtoMessage() {}++func (x *DataSourceOptions) ProtoReflect() protoreflect.Message {+ mi := &file_store_data_source_proto_msgTypes[0]+ if protoimpl.UnsafeEnabled && x != nil {+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))+ if ms.LoadMessageInfo() == nil {+ ms.StoreMessageInfo(mi)+ }+ return ms+ }+ return mi.MessageOf(x)+}++// Deprecated: Use DataSourceOptions.ProtoReflect.Descriptor instead.+func (*DataSourceOptions) Descriptor() ([]byte, []int) {+ return file_store_data_source_proto_rawDescGZIP(), []int{0}+}++func (x *DataSourceOptions) GetSrv() bool {+ if x != nil {+ return x.Srv+ }+ return false+}++func (x *DataSourceOptions) GetAuthenticationDatabase() string {+ if x != nil {+ return x.AuthenticationDatabase+ }+ return ""+}++var File_store_data_source_proto protoreflect.FileDescriptor++var file_store_data_source_proto_rawDesc = []byte{+ 0x0a, 0x17, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x2f, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x73, 0x6f, 0x75,+ 0x72, 0x63, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0e, 0x62, 0x79, 0x74, 0x65, 0x62,+ 0x61, 0x73, 0x65, 0x2e, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x22, 0x5e, 0x0a, 0x11, 0x44, 0x61, 0x74,+ 0x61, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x4f, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x10,+ 0x0a, 0x03, 0x73, 0x72, 0x76, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x03, 0x73, 0x72, 0x76,+ 0x12, 0x37, 0x0a, 0x17, 0x61, 0x75, 0x74, 0x68, 0x65, 0x6e, 0x74, 0x69, 0x63, 0x61, 0x74, 0x69,+ 0x6f, 0x6e, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28,+ 0x09, 0x52, 0x16, 0x61, 0x75, 0x74, 0x68, 0x65, 0x6e, 0x74, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f,+ 0x6e, 0x44, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x42, 0x14, 0x5a, 0x12, 0x67, 0x65, 0x6e,+ 0x65, 0x72, 0x61, 0x74, 0x65, 0x64, 0x2d, 0x67, 0x6f, 0x2f, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x62,+ 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,+}++var (+ file_store_data_source_proto_rawDescOnce sync.Once+ file_store_data_source_proto_rawDescData = file_store_data_source_proto_rawDesc+)++func file_store_data_source_proto_rawDescGZIP() []byte {+ file_store_data_source_proto_rawDescOnce.Do(func() {+ file_store_data_source_proto_rawDescData = protoimpl.X.CompressGZIP(file_store_data_source_proto_rawDescData)+ })+ return file_store_data_source_proto_rawDescData+}++var file_store_data_source_proto_msgTypes = make([]protoimpl.MessageInfo, 1)+var file_store_data_source_proto_goTypes = []interface{}{+ (*DataSourceOptions)(nil), // 0: bytebase.store.DataSourceOptions+}+var file_store_data_source_proto_depIdxs = []int32{+ 0, // [0:0] is the sub-list for method output_type+ 0, // [0:0] is the sub-list for method input_type+ 0, // [0:0] is the sub-list for extension type_name+ 0, // [0:0] is the sub-list for extension extendee+ 0, // [0:0] is the sub-list for field type_name+}++func init() { file_store_data_source_proto_init() }+func file_store_data_source_proto_init() {+ if File_store_data_source_proto != nil {+ return+ }+ if !protoimpl.UnsafeEnabled {+ file_store_data_source_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {+ switch v := v.(*DataSourceOptions); i {+ case 0:+ return &v.state+ case 1:+ return &v.sizeCache+ case 2:+ return &v.unknownFields+ default:+ return nil+ }+ }+ }+ type x struct{}+ out := protoimpl.TypeBuilder{+ File: protoimpl.DescBuilder{+ GoPackagePath: reflect.TypeOf(x{}).PkgPath(),+ RawDescriptor: file_store_data_source_proto_rawDesc,+ NumEnums: 0,+ NumMessages: 1,+ NumExtensions: 0,+ NumServices: 0,+ },+ GoTypes: file_store_data_source_proto_goTypes,+ DependencyIndexes: file_store_data_source_proto_depIdxs,+ MessageInfos: file_store_data_source_proto_msgTypes,+ }.Build()+ File_store_data_source_proto = out.File+ file_store_data_source_proto_rawDesc = nil+ file_store_data_source_proto_goTypes = nil+ file_store_data_source_proto_depIdxs = nil+}diff --git a/proto/store/data_source.proto b/proto/store/data_source.protonew file mode 100644index 0000000000..80a01dc908--- /dev/null+++ b/proto/store/data_source.proto@@ -0,0 +1,13 @@+syntax = "proto3";++package bytebase.store;++option go_package = "generated-go/store";++message DataSourceOptions {+ // srv is a boolean flag that indicates whether the host is a DNS SRV record.+ bool srv = 1;++ // authentication_database is the database name to authenticate against, which stores the user credentials.+ string authentication_database = 2;+}\ No newline at end of file