Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nACL optimization - fix cmd #231

Open
wants to merge 13 commits into
base: read_nacls
Choose a base branch
from
5 changes: 3 additions & 2 deletions cmd/subcmds/optimize.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ import (
func newOptimizeCommand(args *inArgs) *cobra.Command {
cmd := &cobra.Command{
Use: "optimize",
Short: "optimization of existing SG (nACLS are not supported yet)",
Long: `optimization of existing SG (nACLS are not supported yet)`,
Short: "optimization of existing SG and nACLs",
Long: `optimization of existing SG and nACLs`,
}

// sub cmds
cmd.AddCommand(newOptimizeSGCommand(args))
cmd.AddCommand(newOptimizeACLCommand(args))

return cmd
}
Expand Down
21 changes: 15 additions & 6 deletions cmd/subcmds/optimizeACL.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,27 @@ SPDX-License-Identifier: Apache-2.0

package subcmds

import "github.com/spf13/cobra"
import (
"github.com/spf13/cobra"

// temporarily exported and currently unused
func NewOptimizeACLCommand(_ *inArgs) *cobra.Command {
acloptimizer "github.com/np-guard/vpc-network-config-synthesis/pkg/optimize/acl"
)

const aclNameFlag = "acl-name"

func newOptimizeACLCommand(args *inArgs) *cobra.Command {
cmd := &cobra.Command{
Use: "acl",
Short: "OptimizeACL is not supported yet",
Long: `OptimizeACL is not supported yet`,
Short: "OptimizeACL attempts to reduce the number of nACL rules in an nACL without changing the semantic.",
Long: `OptimizeACL attempts to reduce the number of nACL rules in an nACL without changing the semantic.`,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
return nil
return optimization(cmd, args, acloptimizer.NewACLOptimizer, false)
},
}

// flags
cmd.PersistentFlags().StringVarP(&args.firewallName, aclNameFlag, "n", "", "which nacl to optimize")

return cmd
}
31 changes: 31 additions & 0 deletions pkg/optimize/acl/acl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
Copyright 2023- IBM Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package acloptimizer

import (
"github.com/np-guard/vpc-network-config-synthesis/pkg/ir"
"github.com/np-guard/vpc-network-config-synthesis/pkg/optimize"
)

type (
aclOptimizer struct {
aclCollection *ir.ACLCollection
aclName string
aclVPC string
}
)

func NewACLOptimizer(collection ir.Collection, aclName string) optimize.Optimizer {
components := ir.ScopingComponents(aclName)
if len(components) == 1 {
return &aclOptimizer{aclCollection: collection.(*ir.ACLCollection), aclName: aclName, aclVPC: ""}
}
return &aclOptimizer{aclCollection: collection.(*ir.ACLCollection), aclName: components[1], aclVPC: components[0]}
}

func (a *aclOptimizer) Optimize() (ir.Collection, error) {
return nil, nil
}
Loading