mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-06-14 20:41:15 +08:00
data mask log commit
This commit is contained in:
@@ -3,7 +3,7 @@ package apinto
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
|
||||
"github.com/APIParkLab/APIPark/gateway"
|
||||
admin_client "github.com/eolinker/eosc/process-admin/client"
|
||||
)
|
||||
@@ -14,6 +14,10 @@ type ClientDriver struct {
|
||||
client admin_client.Client
|
||||
}
|
||||
|
||||
func (c *ClientDriver) Strategy() gateway.IStrategyClient {
|
||||
return NewStrategyClient(c.client)
|
||||
}
|
||||
|
||||
func (c *ClientDriver) Close(ctx context.Context) error {
|
||||
if c.client != nil {
|
||||
return c.client.Close()
|
||||
@@ -74,7 +78,7 @@ func NewClientDriver(cfg *gateway.ClientConfig) (*ClientDriver, error) {
|
||||
}
|
||||
|
||||
func genWorkerID(id string, profession string) string {
|
||||
|
||||
|
||||
suffix := "@" + profession
|
||||
if strings.HasSuffix(id, suffix) {
|
||||
return id
|
||||
|
||||
@@ -63,6 +63,13 @@
|
||||
rely: eolinker.com:apinto:plugin_app
|
||||
config:
|
||||
cache: redis@output
|
||||
|
||||
- id: eolinker.com:apinto:strategy-plugin-data_mask
|
||||
name: strategy_data_mask
|
||||
status: global
|
||||
rely: eolinker.com:apinto:plugin_app
|
||||
config:
|
||||
cache: redis@output
|
||||
-
|
||||
id: eolinker.com:apinto:ai_prompt
|
||||
name: ai_prompt
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package apinto
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/eolinker/eosc"
|
||||
|
||||
"github.com/APIParkLab/APIPark/gateway"
|
||||
admin_client "github.com/eolinker/eosc/process-admin/client"
|
||||
)
|
||||
|
||||
var _ gateway.IStrategyClient = &StrategyClient{}
|
||||
|
||||
type StrategyClient struct {
|
||||
client admin_client.Client
|
||||
}
|
||||
|
||||
func (s *StrategyClient) Online(ctx context.Context, resources ...*eosc.Base[gateway.StrategyRelease]) error {
|
||||
s.client.Begin(ctx)
|
||||
for _, r := range resources {
|
||||
if r.Config.IsDelete {
|
||||
err := s.client.Del(ctx, genWorkerID(r.Config.Name, gateway.ProfessionStrategy))
|
||||
if err != nil {
|
||||
s.client.Rollback(ctx)
|
||||
return err
|
||||
}
|
||||
continue
|
||||
}
|
||||
err := s.client.Set(ctx, genWorkerID(r.Config.Name, gateway.ProfessionStrategy), r)
|
||||
if err != nil {
|
||||
s.client.Rollback(ctx)
|
||||
return err
|
||||
}
|
||||
}
|
||||
return s.client.Commit(ctx)
|
||||
}
|
||||
|
||||
func (s *StrategyClient) Offline(ctx context.Context, resources ...*eosc.Base[gateway.StrategyRelease]) error {
|
||||
s.client.Begin(ctx)
|
||||
for _, r := range resources {
|
||||
err := s.client.Del(ctx, genWorkerID(r.Config.Name, gateway.ProfessionStrategy))
|
||||
if err != nil {
|
||||
s.client.Rollback(ctx)
|
||||
return err
|
||||
}
|
||||
}
|
||||
return s.client.Commit(ctx)
|
||||
}
|
||||
|
||||
func NewStrategyClient(client admin_client.Client) *StrategyClient {
|
||||
return &StrategyClient{client: client}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ type IClientDriver interface {
|
||||
Application() IApplicationClient
|
||||
Service() IServiceClient
|
||||
Subscribe() ISubscribeClient
|
||||
Strategy() IStrategyClient
|
||||
Dynamic(resource string) (IDynamicClient, error)
|
||||
PluginSetting() IPluginSetting
|
||||
Commit(ctx context.Context) error
|
||||
|
||||
@@ -5,6 +5,7 @@ const (
|
||||
ProfessionCertificate = "certificate"
|
||||
ProfessionRouter = "router"
|
||||
ProfessionApplication = "app"
|
||||
ProfessionStrategy = "strategy"
|
||||
ProfessionService = "service"
|
||||
ProfessionAIProvider = "ai-provider"
|
||||
)
|
||||
|
||||
+18
-4
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/eolinker/eosc"
|
||||
|
||||
"github.com/APIParkLab/APIPark/model/plugin_model"
|
||||
)
|
||||
|
||||
@@ -15,6 +17,8 @@ type IServiceClient IResourceClient[ServiceRelease]
|
||||
|
||||
type ISubscribeClient IResourceClient[SubscribeRelease]
|
||||
|
||||
type IStrategyClient IResourceClient[eosc.Base[StrategyRelease]]
|
||||
|
||||
type IResourceClient[T any] interface {
|
||||
Online(ctx context.Context, resources ...*T) error
|
||||
Offline(ctx context.Context, resources ...*T) error
|
||||
@@ -27,10 +31,11 @@ type IDynamicClient interface {
|
||||
}
|
||||
|
||||
type ProjectRelease struct {
|
||||
Id string `json:"id"`
|
||||
Version string `json:"version"`
|
||||
Apis []*ApiRelease `json:"apis"`
|
||||
Upstream *UpstreamRelease `json:"upstreams"`
|
||||
Id string `json:"id"`
|
||||
Version string `json:"version"`
|
||||
Apis []*ApiRelease `json:"apis"`
|
||||
Upstream *UpstreamRelease `json:"upstreams"`
|
||||
Strategies []*eosc.Base[StrategyRelease] `json:"strategies"`
|
||||
}
|
||||
|
||||
type ApiRelease struct {
|
||||
@@ -73,6 +78,15 @@ type UpstreamRelease struct {
|
||||
Labels map[string]string
|
||||
}
|
||||
|
||||
type StrategyRelease struct {
|
||||
Name string `json:"name"`
|
||||
Desc string `json:"description"`
|
||||
Driver string `json:"driver"`
|
||||
Priority int `json:"priority"`
|
||||
Filters map[string][]string `json:"filters"`
|
||||
IsDelete bool `json:"-"`
|
||||
}
|
||||
|
||||
type MatchRule struct {
|
||||
Position string
|
||||
MatchType string
|
||||
|
||||
Reference in New Issue
Block a user