waf.go 1.39 KB
Newer Older
qiuqunfeng's avatar
qiuqunfeng committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
package service

import (
	"context"

	"gitlab.com/tensorsecurity-rd/waf-console/pkg/apis/waf.security.io/v1alpha1"
	"gitlab.com/tensorsecurity-rd/waf-console/pkg/generated/clientset/versioned"
	"gorm.io/gorm"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

type wafService struct {
	client *versioned.Clientset
	db     *gorm.DB
}

func NewWafService(client *versioned.Clientset, db *gorm.DB) Service {
	return &wafService{client: client, db: db}
}

func (s *wafService) GetWaf(ctx context.Context, gatewayName string) (*Waf, error) {
	waf := &Waf{
		GatewayName: gatewayName,
		Mode:        "block",
		RuleNum:     100,
		AttackNum:   100,
	}
	return waf, nil
}

func (s *wafService) CreateWaf(ctx context.Context, req *CreateWafReq) (*Waf, error) {
	service := &v1alpha1.Service{
		ObjectMeta: metav1.ObjectMeta{
			Name:      req.GatewayName,
			Namespace: req.Namespace,
		},
		Spec: v1alpha1.ServiceSpec{
			HostNames:   req.Host,
			ServiceName: req.GatewayName,
			Port:        req.Port,
			Workload: v1alpha1.WorkloadRef{
				Kind:      "Deployment",
				Name:      req.GatewayName,
				Namespace: req.Namespace,
			},
		},
	}
	_, err := s.client.WafV1alpha1().Services(req.Namespace).Create(context.Background(), service, metav1.CreateOptions{})
	if err != nil {
		return nil, err
	}

	return nil, nil
}
qiuqunfeng's avatar
commit  
qiuqunfeng committed
55 56 57 58

func (s *wafService) UpdateMode(ctx context.Context, req *UpdateModeReq) (*Waf, error) {
	return nil, nil
}