Yeuoly 10 months ago
parent
commit
fd82d23584

+ 9 - 7
internal/core/dify_invocation/real/encrypt_test.go

@@ -29,8 +29,8 @@ func TestEncryptRequired(t *testing.T) {
 			Namespace: dify_invocation.ENCRYPT_NAMESPACE_ENDPOINT,
 			Identity:  "test123",
 			Data:      data,
-			Config: map[string]plugin_entities.ProviderConfig{
-				"key": {
+			Config: []plugin_entities.ProviderConfig{
+				{
 					Name: "key",
 					Type: plugin_entities.CONFIG_TYPE_SECRET_INPUT,
 				},
@@ -42,9 +42,11 @@ func TestEncryptRequired(t *testing.T) {
 		t.Errorf("EncryptRequired should return true")
 	}
 
-	payload.Config["key"] = plugin_entities.ProviderConfig{
-		Name: "key",
-		Type: plugin_entities.CONFIG_TYPE_TEXT_INPUT,
+	payload.Config = []plugin_entities.ProviderConfig{
+		{
+			Name: "key",
+			Type: plugin_entities.CONFIG_TYPE_TEXT_INPUT,
+		},
 	}
 
 	if payload.EncryptRequired(data) {
@@ -116,8 +118,8 @@ func TestInvokeEncrypt(t *testing.T) {
 			Namespace: dify_invocation.ENCRYPT_NAMESPACE_ENDPOINT,
 			Identity:  "test123",
 			Data:      map[string]any{"key": "value"},
-			Config: map[string]plugin_entities.ProviderConfig{
-				"key": {
+			Config: []plugin_entities.ProviderConfig{
+				{
 					Name: "key",
 					Type: plugin_entities.CONFIG_TYPE_SECRET_INPUT,
 				},

+ 8 - 10
internal/core/dify_invocation/types.go

@@ -172,11 +172,11 @@ func init() {
 }
 
 type InvokeEncryptSchema struct {
-	Opt       EncryptOpt                                `json:"opt" validate:"required,encrypt_opt"`
-	Namespace EncryptNamespace                          `json:"namespace" validate:"required,encrypt_namespace"`
-	Identity  string                                    `json:"identity" validate:"required"`
-	Data      map[string]any                            `json:"data" validate:"omitempty"`
-	Config    map[string]plugin_entities.ProviderConfig `json:"config" validate:"omitempty,dive"`
+	Opt       EncryptOpt                       `json:"opt" validate:"required,encrypt_opt"`
+	Namespace EncryptNamespace                 `json:"namespace" validate:"required,encrypt_namespace"`
+	Identity  string                           `json:"identity" validate:"required"`
+	Data      map[string]any                   `json:"data" validate:"omitempty"`
+	Config    []plugin_entities.ProviderConfig `json:"config" validate:"omitempty,dive"`
 }
 
 type InvokeEncryptRequest struct {
@@ -191,11 +191,9 @@ func (r *InvokeEncryptRequest) EncryptRequired(settings map[string]any) bool {
 	}
 
 	// filter out which key needs encrypt
-	for k := range settings {
-		if config, ok := r.Config[k]; ok {
-			if config.Type == plugin_entities.CONFIG_TYPE_SECRET_INPUT {
-				return true
-			}
+	for _, config := range r.Config {
+		if config.Type == plugin_entities.CONFIG_TYPE_SECRET_INPUT {
+			return true
 		}
 	}
 

+ 2 - 0
internal/core/plugin_packager/decoder/decoder.go

@@ -90,6 +90,8 @@ func (p *PluginDecoderHelper) Manifest(decoder PluginDecoder) (plugin_entities.P
 			return plugin_entities.PluginDeclaration{}, errors.Join(err, fmt.Errorf("failed to read tool file: %s", tool))
 		}
 
+		// TODO
+
 		plugin_dec, err := parser.UnmarshalYamlBytes[plugin_entities.ToolProviderDeclaration](plugin_yaml)
 		if err != nil {
 			return plugin_entities.PluginDeclaration{}, errors.Join(err, fmt.Errorf("failed to unmarshal plugin file: %s", tool))

+ 1 - 2
internal/core/plugin_packager/neko.yaml

@@ -1,6 +1,5 @@
 settings:
-  api_key:
-    type: secret-input
+  - type: secret-input
     name: api_key
     required: true
     label:

+ 7 - 2
internal/types/entities/plugin_entities/config.go

@@ -217,12 +217,17 @@ func init() {
 }
 
 // ValidateProviderConfigs validates the provider configs
-func ValidateProviderConfigs(settings map[string]any, configs map[string]ProviderConfig) error {
+func ValidateProviderConfigs(settings map[string]any, configs []ProviderConfig) error {
 	if len(settings) > 64 {
 		return errors.New("too many setting fields")
 	}
 
-	for config_name, config := range configs {
+	configs_map := make(map[string]ProviderConfig)
+	for _, config := range configs {
+		configs_map[config.Name] = config
+	}
+
+	for config_name, config := range configs_map {
 		v, ok := settings[config_name]
 		if (!ok || v == nil) && config.Required {
 			return errors.New("missing required setting: " + config_name)

+ 7 - 2
internal/utils/encryption/mask.go

@@ -8,14 +8,19 @@ import (
 
 func MaskConfigCredentials(
 	credentials map[string]any,
-	provider_config map[string]plugin_entities.ProviderConfig,
+	provider_config []plugin_entities.ProviderConfig,
 ) map[string]any {
 	/*
 		Mask credentials based on provider config
 	*/
+	configs_map := make(map[string]plugin_entities.ProviderConfig)
+	for _, config := range provider_config {
+		configs_map[config.Name] = config
+	}
+
 	copied_credentials := make(map[string]any)
 	for key, value := range credentials {
-		if config, ok := provider_config[key]; ok {
+		if config, ok := configs_map[key]; ok {
 			if config.Type == plugin_entities.CONFIG_TYPE_SECRET_INPUT {
 				if original_value, ok := value.(string); ok {
 					if len(original_value) > 6 {