Skip to content

Commit

Permalink
Update cli command from "new" to "enhance" with Generative AI (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-mizutani authored Jan 3, 2025
1 parent feebb47 commit 6b26d89
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/cli/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func New() *CLI {
cmdServe(),
cmdRun(),
cmdPlay(),
cmdNew(),
cmdEnhance(),
{
Name: "version",
Aliases: []string{"v"},
Expand Down
16 changes: 8 additions & 8 deletions pkg/controller/cli/new.go → pkg/controller/cli/enhance.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ import (
"github.com/urfave/cli/v3"
)

func cmdNew() *cli.Command {
func cmdEnhance() *cli.Command {
return &cli.Command{
Name: "new",
Aliases: []string{"n"},
Usage: "Create new alertchain policy",
Name: "enhance",
Aliases: []string{"e"},
Usage: "Enhance alertchain policy with Generative AI",
Commands: []*cli.Command{
cmdNewIgnore(),
cmdEnhanceIgnore(),
},
}
}

func cmdNewIgnore() *cli.Command {
func cmdEnhanceIgnore() *cli.Command {
var (
input usecase.NewIgnorePolicyInput
input usecase.EnhanceIgnorePolicyInput
alertIDSet []string
geminiProjectID string
geminiLocation string
Expand Down Expand Up @@ -111,7 +111,7 @@ func cmdNewIgnore() *cli.Command {
}
defer dbClose()

if err := usecase.NewIgnorePolicy(ctx, dbClient, geminiClient, input); err != nil {
if err := usecase.EnhanceIgnorePolicy(ctx, dbClient, geminiClient, input); err != nil {
return err
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/usecase/new_ignore.go → pkg/usecase/enhance_ignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ func getRegoPackageName(policyData string) (string, error) {
return strings.Join(terms, "."), nil
}

type NewIgnorePolicyInput struct {
type EnhanceIgnorePolicyInput struct {
AlertIDs []types.AlertID
BasePolicyFile string
TestDataDir string
TestDataRegoPath string
OverWrite bool
}

func (x NewIgnorePolicyInput) Validate() error {
func (x EnhanceIgnorePolicyInput) Validate() error {
if len(x.AlertIDs) == 0 {
return goerr.New("AlertID is empty")
}
Expand All @@ -80,10 +80,10 @@ func (x NewIgnorePolicyInput) Validate() error {
return nil
}

func NewIgnorePolicy(ctx context.Context,
func EnhanceIgnorePolicy(ctx context.Context,
dbClient interfaces.Database,
genAI interfaces.GenAI,
input NewIgnorePolicyInput,
input EnhanceIgnorePolicyInput,
) error {
if err := input.Validate(); err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
//go:embed testdata/example_policy.rego
var examplePolicy []byte

func TestNewIgnorePolicy(t *testing.T) {
func TestEnhanceIgnorePolicy(t *testing.T) {
ctx := context.Background()

alertID := types.AlertID("test-alert-id")
Expand Down Expand Up @@ -64,15 +64,15 @@ func TestNewIgnorePolicy(t *testing.T) {
// TODO: Enable this line
// defer os.RemoveAll(input.TestDataDir)

input := usecase.NewIgnorePolicyInput{
input := usecase.EnhanceIgnorePolicyInput{
AlertIDs: []types.AlertID{alertID},
BasePolicyFile: fd.Name(),
TestDataDir: dir,
TestDataRegoPath: "test_rego_path",
OverWrite: true,
}

gt.NoError(t, usecase.NewIgnorePolicy(ctx, dbClient, genAI, input))
gt.NoError(t, usecase.EnhanceIgnorePolicy(ctx, dbClient, genAI, input))

// Check if test data file is created
testDataPath := filepath.Join(input.TestDataDir, slug, "data.json")
Expand Down

0 comments on commit 6b26d89

Please sign in to comment.