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: update agent setting (#5033)
ecmadao0ad00dfffb78
diff --git a/backend/enterprise/config/config.go b/backend/enterprise/config/config.goindex 3d6354de3f..54b2aa3b4c 100644--- a/backend/enterprise/config/config.go+++ b/backend/enterprise/config/config.go@@ -24,8 +24,6 @@ type Config struct {Issuer string// Audience is the license audience, it should always be "bb.license".Audience string- // HubAPIURL is the API URL for Bytebase hub.- HubAPIURL string// Mode can be "prod" or "dev"Mode common.ReleaseMode}@@ -43,8 +41,8 @@ const (MaximumInstanceForFreePlan = 10)-// getConfig will create a new enterprise config instance.-func getConfig(mode common.ReleaseMode) (*Config, error) {+// NewConfig will create a new enterprise config instance.+func NewConfig(mode common.ReleaseMode) (*Config, error) {licensePubKey, err := fs.ReadFile(keysFS, fmt.Sprintf("keys/%s.pub.pem", mode))if err != nil {return nil, errors.Errorf("cannot read license public key for env %s", mode)diff --git a/backend/enterprise/config/config_dev.go b/backend/enterprise/config/config_dev.godeleted file mode 100644index 7fbfe06fbd..0000000000--- a/backend/enterprise/config/config_dev.go+++ /dev/null@@ -1,19 +0,0 @@-//go:build !release-// +build !release--package config--import (- "github.com/bytebase/bytebase/backend/common"-)--// NewConfig will create a new enterprise config instance.-func NewConfig(mode common.ReleaseMode) (*Config, error) {- config, err := getConfig(mode)- if err != nil {- return nil, err- }-- config.HubAPIURL = "https://bytebase-hub-backend-dev.onrender.com"- return config, nil-}diff --git a/backend/enterprise/config/config_release.go b/backend/enterprise/config/config_release.godeleted file mode 100644index 1f5fce2121..0000000000--- a/backend/enterprise/config/config_release.go+++ /dev/null@@ -1,19 +0,0 @@-//go:build release-// +build release--package config--import (- "github.com/bytebase/bytebase/backend/common"-)--// NewConfig will create a new enterprise config instance.-func NewConfig(mode common.ReleaseMode) (*Config, error) {- config, err := getConfig(mode)- if err != nil {- return nil, err- }-- config.HubAPIURL = "https://bytebase-hub-backend-prod.onrender.com"- return config, nil-}diff --git a/backend/enterprise/service/provider.go b/backend/enterprise/service/provider.goindex cdba74639e..524e8624a9 100644--- a/backend/enterprise/service/provider.go+++ b/backend/enterprise/service/provider.go@@ -10,12 +10,14 @@ import ("github.com/golang-jwt/jwt/v4""github.com/pkg/errors"+ "google.golang.org/protobuf/encoding/protojson""github.com/bytebase/bytebase/backend/common""github.com/bytebase/bytebase/backend/common/log""github.com/bytebase/bytebase/backend/enterprise/config"api "github.com/bytebase/bytebase/backend/legacyapi""github.com/bytebase/bytebase/backend/store"+ storepb "github.com/bytebase/bytebase/proto/generated-go/store")const (@@ -63,7 +65,7 @@ func (p *LicenseProvider) FetchLicense(ctx context.Context) (string, error) {return "", nil}- settingName := api.SettingAgentToken+ settingName := api.SettingPluginAgentsetting, err := p.store.GetSetting(ctx, &api.SettingFind{Name: &settingName,})@@ -71,10 +73,13 @@ func (p *LicenseProvider) FetchLicense(ctx context.Context) (string, error) {return "", errors.Wrapf(err, "failed to find the hub token from settings")}if setting == nil || setting.Value == "" {- return "", errors.Wrapf(err, "hub token not found")+ return "", errors.Wrapf(err, "agent not found")}- claims, err := p.parseJWTToken(setting.Value)- if err != nil {+ payload := new(storepb.AgentPluginSetting)+ if err := protojson.Unmarshal([]byte(setting.Value), payload); err != nil {+ return "", errors.Wrapf(err, "failed to parse agent")+ }+ if _, err := p.parseJWTToken(payload.Token); err != nil {return "", errors.Wrapf(err, "invalid internal token")}@@ -82,25 +87,24 @@ func (p *LicenseProvider) FetchLicense(ctx context.Context) (string, error) {p.lastFetchTime = time.Now().Unix()}()- return p.requestLicense(ctx, setting.Value, claims)+ return p.requestLicense(ctx, payload.Url, setting.Value)}-func (p *LicenseProvider) requestLicense(ctx context.Context, token string, claims *internalTokenClaims) (string, error) {- url := fmt.Sprintf("%s/v1/orgs/%s/workspaces/%s/license", p.config.HubAPIURL, claims.OrgID, claims.WorkspaceID)- req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)+func (p *LicenseProvider) requestLicense(ctx context.Context, agentURL, agentToken string) (string, error) {+ req, err := http.NewRequestWithContext(ctx, http.MethodGet, agentURL, nil)if err != nil {- return "", errors.Wrapf(err, "construct GET %s", url)+ return "", errors.Wrapf(err, "construct GET %s", agentURL)}req.Header.Set("Content-Type", "application/json")- req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))+ req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", agentToken))resp, err := p.client.Do(req)if err != nil {- return "", errors.Wrapf(err, "GET %s", url)+ return "", errors.Wrapf(err, "GET %s", agentURL)}b, err := io.ReadAll(resp.Body)if err != nil {- return "", errors.Wrapf(err, "read body of GET %s", url)+ return "", errors.Wrapf(err, "read body of GET %s", agentURL)}defer resp.Body.Close()@@ -110,7 +114,7 @@ func (p *LicenseProvider) requestLicense(ctx context.Context, token string, claivar response getLicenseResponseif err := json.Unmarshal(b, &response); err != nil {- return "", errors.Wrapf(err, "unmarshal body from GET %s", url)+ return "", errors.Wrapf(err, "unmarshal body from GET %s", agentURL)}return response.License, nildiff --git a/backend/legacyapi/setting.go b/backend/legacyapi/setting.goindex 7519c5093c..3b5ed87065 100644--- a/backend/legacyapi/setting.go+++ b/backend/legacyapi/setting.go@@ -24,12 +24,12 @@ const (SettingAppIM SettingName = "bb.app.im"// SettingWatermark is the setting name for watermark displaying.SettingWatermark SettingName = "bb.workspace.watermark"- // SettingAgentToken is the setting name for the agent token to call the internal API.- // For now we will call the hub to fetch the subscription license.- SettingAgentToken SettingName = "bb.agent.token"// SettingPluginOpenAIKey is used for OpenAI's API key.// For AI-related features.- SettingPluginOpenAIKey SettingName = "bb.plugin.openai-key"+ SettingPluginOpenAIKey SettingName = "bb.plugin.openai.key"+ // SettingPluginAgent is the setting name for the internal agent API.+ // For now we will call the hub to fetch the subscription license.+ SettingPluginAgent SettingName = "bb.plugin.agent")// IMType is the type of IM.diff --git a/frontend/src/plugins/ai/components/AIPromptButton.vue b/frontend/src/plugins/ai/components/AIPromptButton.vueindex d7e0c555e4..307884d447 100644--- a/frontend/src/plugins/ai/components/AIPromptButton.vue+++ b/frontend/src/plugins/ai/components/AIPromptButton.vue@@ -50,7 +50,7 @@ const state = reactive<LocalState>({showDialog: false,});-const openAIKeySetting = useSettingByName("bb.plugin.openai-key");+const openAIKeySetting = useSettingByName("bb.plugin.openai.key");const openAIKey = computed(() => openAIKeySetting.value?.value ?? "");const events: AIContextEvents = new Emittery();diff --git a/frontend/src/types/proto/store/setting.ts b/frontend/src/types/proto/store/setting.tsindex 45d1cc9166..12df42ab34 100644--- a/frontend/src/types/proto/store/setting.ts+++ b/frontend/src/types/proto/store/setting.ts@@ -16,6 +16,13 @@ export interface WorkspaceProfileSetting {disallowSignup: boolean;}+export interface AgentPluginSetting {+ /** The URL for the agent API. */+ url: string;+ /** The token for the agent. */+ token: string;+}+function createBaseWorkspaceProfileSetting(): WorkspaceProfileSetting {return { externalUrl: "", disallowSignup: false };}@@ -74,6 +81,61 @@ export const WorkspaceProfileSetting = {},};+function createBaseAgentPluginSetting(): AgentPluginSetting {+ return { url: "", token: "" };+}++export const AgentPluginSetting = {+ encode(message: AgentPluginSetting, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {+ if (message.url !== "") {+ writer.uint32(10).string(message.url);+ }+ if (message.token !== "") {+ writer.uint32(18).string(message.token);+ }+ return writer;+ },++ decode(input: _m0.Reader | Uint8Array, length?: number): AgentPluginSetting {+ const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);+ let end = length === undefined ? reader.len : reader.pos + length;+ const message = createBaseAgentPluginSetting();+ while (reader.pos < end) {+ const tag = reader.uint32();+ switch (tag >>> 3) {+ case 1:+ message.url = reader.string();+ break;+ case 2:+ message.token = reader.string();+ break;+ default:+ reader.skipType(tag & 7);+ break;+ }+ }+ return message;+ },++ fromJSON(object: any): AgentPluginSetting {+ return { url: isSet(object.url) ? String(object.url) : "", token: isSet(object.token) ? String(object.token) : "" };+ },++ toJSON(message: AgentPluginSetting): unknown {+ const obj: any = {};+ message.url !== undefined && (obj.url = message.url);+ message.token !== undefined && (obj.token = message.token);+ return obj;+ },++ fromPartial(object: DeepPartial<AgentPluginSetting>): AgentPluginSetting {+ const message = createBaseAgentPluginSetting();+ message.url = object.url ?? "";+ message.token = object.token ?? "";+ return message;+ },+};+type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;export type DeepPartial<T> = T extends Builtin ? Tdiff --git a/frontend/src/types/setting.ts b/frontend/src/types/setting.tsindex 6b83eb9a35..0ed49bcee7 100644--- a/frontend/src/types/setting.ts+++ b/frontend/src/types/setting.ts@@ -5,7 +5,7 @@ export type SettingName =| "bb.app.im"| "bb.workspace.watermark"| "bb.workspace.profile"- | "bb.plugin.openai-key";+ | "bb.plugin.openai.key";export type Setting = {id: SettingId;diff --git a/proto/gen/grpc-doc/store/README.md b/proto/gen/grpc-doc/store/README.mdindex 1b9cefeabd..7749ab7f1b 100644--- a/proto/gen/grpc-doc/store/README.md+++ b/proto/gen/grpc-doc/store/README.md@@ -27,6 +27,7 @@- [IdentityProviderType](#bytebase-store-IdentityProviderType)- [store/setting.proto](#store_setting-proto)+ - [AgentPluginSetting](#bytebase-store-AgentPluginSetting)- [WorkspaceProfileSetting](#bytebase-store-WorkspaceProfileSetting)- [store/user.proto](#store_user-proto)@@ -397,6 +398,22 @@ OIDCIdentityProviderConfig is the structure for OIDC identity provider config.+<a name="bytebase-store-AgentPluginSetting"></a>++### AgentPluginSetting++++| Field | Type | Label | Description |+| ----- | ---- | ----- | ----------- |+| url | [string](#string) | | The URL for the agent API. |+| token | [string](#string) | | The token for the agent. |++++++<a name="bytebase-store-WorkspaceProfileSetting"></a>### WorkspaceProfileSettingdiff --git a/proto/generated-go/store/setting.pb.go b/proto/generated-go/store/setting.pb.goindex 50f412c2fd..8115bfebcb 100644--- a/proto/generated-go/store/setting.pb.go+++ b/proto/generated-go/store/setting.pb.go@@ -81,6 +81,63 @@ func (x *WorkspaceProfileSetting) GetDisallowSignup() bool {return false}+type AgentPluginSetting struct {+ state protoimpl.MessageState+ sizeCache protoimpl.SizeCache+ unknownFields protoimpl.UnknownFields++ // The URL for the agent API.+ Url string `protobuf:"bytes,1,opt,name=url,proto3" json:"url,omitempty"`+ // The token for the agent.+ Token string `protobuf:"bytes,2,opt,name=token,proto3" json:"token,omitempty"`+}++func (x *AgentPluginSetting) Reset() {+ *x = AgentPluginSetting{}+ if protoimpl.UnsafeEnabled {+ mi := &file_store_setting_proto_msgTypes[1]+ ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))+ ms.StoreMessageInfo(mi)+ }+}++func (x *AgentPluginSetting) String() string {+ return protoimpl.X.MessageStringOf(x)+}++func (*AgentPluginSetting) ProtoMessage() {}++func (x *AgentPluginSetting) ProtoReflect() protoreflect.Message {+ mi := &file_store_setting_proto_msgTypes[1]+ 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 AgentPluginSetting.ProtoReflect.Descriptor instead.+func (*AgentPluginSetting) Descriptor() ([]byte, []int) {+ return file_store_setting_proto_rawDescGZIP(), []int{1}+}++func (x *AgentPluginSetting) GetUrl() string {+ if x != nil {+ return x.Url+ }+ return ""+}++func (x *AgentPluginSetting) GetToken() string {+ if x != nil {+ return x.Token+ }+ return ""+}+var File_store_setting_proto protoreflect.FileDescriptorvar file_store_setting_proto_rawDesc = []byte{@@ -92,9 +149,13 @@ var file_store_setting_proto_rawDesc = []byte{0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x65, 0x78, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c,0x55, 0x72, 0x6c, 0x12, 0x27, 0x0a, 0x0f, 0x64, 0x69, 0x73, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x5f,0x73, 0x69, 0x67, 0x6e, 0x75, 0x70, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0e, 0x64, 0x69,- 0x73, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x53, 0x69, 0x67, 0x6e, 0x75, 0x70, 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,+ 0x73, 0x61, 0x6c, 0x6c, 0x6f, 0x77, 0x53, 0x69, 0x67, 0x6e, 0x75, 0x70, 0x22, 0x3c, 0x0a, 0x12,+ 0x41, 0x67, 0x65, 0x6e, 0x74, 0x50, 0x6c, 0x75, 0x67, 0x69, 0x6e, 0x53, 0x65, 0x74, 0x74, 0x69,+ 0x6e, 0x67, 0x12, 0x10, 0x0a, 0x03, 0x75, 0x72, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52,+ 0x03, 0x75, 0x72, 0x6c, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x02, 0x20,+ 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 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 (@@ -109,9 +170,10 @@ func file_store_setting_proto_rawDescGZIP() []byte {return file_store_setting_proto_rawDescData}-var file_store_setting_proto_msgTypes = make([]protoimpl.MessageInfo, 1)+var file_store_setting_proto_msgTypes = make([]protoimpl.MessageInfo, 2)var file_store_setting_proto_goTypes = []interface{}{(*WorkspaceProfileSetting)(nil), // 0: bytebase.store.WorkspaceProfileSetting+ (*AgentPluginSetting)(nil), // 1: bytebase.store.AgentPluginSetting}var file_store_setting_proto_depIdxs = []int32{0, // [0:0] is the sub-list for method output_type@@ -139,6 +201,18 @@ func file_store_setting_proto_init() {return nil}}+ file_store_setting_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {+ switch v := v.(*AgentPluginSetting); 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{@@ -146,7 +220,7 @@ func file_store_setting_proto_init() {GoPackagePath: reflect.TypeOf(x{}).PkgPath(),RawDescriptor: file_store_setting_proto_rawDesc,NumEnums: 0,- NumMessages: 1,+ NumMessages: 2,NumExtensions: 0,NumServices: 0,},diff --git a/proto/store/setting.proto b/proto/store/setting.protoindex 3b9208df0f..ae4a33f71e 100644--- a/proto/store/setting.proto+++ b/proto/store/setting.proto@@ -15,3 +15,11 @@ message WorkspaceProfileSetting {// Disallow self-service signup, users can only be invited by the owner.bool disallow_signup = 2;}++message AgentPluginSetting {+ // The URL for the agent API.+ string url = 1;++ // The token for the agent.+ string token = 2;+}