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

Support more resource types #216

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ Use the `vpcgen` CLI tool with one of the following commands to specify the type

### nACLs Generation
Specifying the `--single` flag results in generating a single nACL for all subnets in the same VPC. Otherwise, an nACL is generated for each subnet separately.
The input supports subnets, subnet segments, CIDR segments, NIFs, instances (VSIs) and externals.
**Note 1**: The segments are defined in the `conn_spec.json` file.
**Note 2**: A required connection between NIFs or VSIs implies connectivity will be allowed between the subnets they are contained in.
**Note**: A required connection between NIFs/VSIs/VPEs implies connectivity will be allowed between the subnets they are contained in.

### SGs Generation
The input supports Instances (VSIs), NIFs, VPEs and externals.
### SGs Generation
**Note**: A Security Group, generated for a specific VSI (or for one of its NIFs), will be applied to all the NIFs of the VSI. The same goes for Reserved IPs of a VPE.

### Supported types
The input supports subnets, subnet segments, CIDR segments, NIFs, NIF segments, instances (VSIs), instance segments, VPEs, VPE segments and externals.
**Note 1**: The segments are defined in the `conn_spec.json` file.

### Output
1. If the `output-dir` flag is used, the specified folder will be created, containing one file per VPC. Each generated file will contain the network resources (Security Groups or Network ACLs) relevant to its VPC. File names are set as `prefix_vpc`, where prefix is ​​the value received in the `prefix` flag. If the `prefix` flag is omitted, file names will match VPC names.
2. If the `output-file` flag is used, all generated resources will be written to the specified file.
Expand Down
12 changes: 4 additions & 8 deletions cmd/subcmds/synth.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,12 @@ func NewSynthCommand(args *inArgs) *cobra.Command {
return cmd
}

func synthesis(cmd *cobra.Command, args *inArgs, newSynthesizer func(*ir.Spec, bool) synth.Synthesizer, single bool) error {
func synthesis(cmd *cobra.Command, args *inArgs, newSynthesizer func(*ir.Spec, bool) synth.Synthesizer, singleacl, isSG bool) error {
cmd.SilenceUsage = true // if we got this far, flags are syntactically correct, so no need to print usage
spec, err := unmarshal(args)
spec, err := unmarshal(args, isSG)
if err != nil {
return err
}
synthesizer := newSynthesizer(spec, single)
collection, err := synthesizer.Synth()
if err != nil {
return err
}
return writeOutput(args, collection, utils.MapKeys(spec.Defs.ConfigDefs.VPCs))
synthesizer := newSynthesizer(spec, singleacl)
return writeOutput(args, synthesizer.Synth(), utils.MapKeys(spec.Defs.ConfigDefs.VPCs))
}
2 changes: 1 addition & 1 deletion cmd/subcmds/synthACL.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func NewSynthACLCommand(args *inArgs) *cobra.Command {
Endpoints in the required-connectivity specification may be subnets, subnet segments, CIDR segments and externals.`,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
return synthesis(cmd, args, synth.NewACLSynthesizer, args.singleacl)
return synthesis(cmd, args, synth.NewACLSynthesizer, args.singleacl, false)
},
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/subcmds/synthSG.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func NewSynthSGCommand(args *inArgs) *cobra.Command {
Endpoints in the required-connectivity specification may be Instances (VSIs), Network Interfaces, VPEs and externals.`,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
return synthesis(cmd, args, synth.NewSGSynthesizer, false)
return synthesis(cmd, args, synth.NewSGSynthesizer, false, true)
},
}
return cmd
Expand Down
4 changes: 2 additions & 2 deletions cmd/subcmds/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ import (
"github.com/np-guard/vpc-network-config-synthesis/pkg/ir"
)

func unmarshal(args *inArgs) (*ir.Spec, error) {
func unmarshal(args *inArgs, isSG bool) (*ir.Spec, error) {
defs, err := confio.ReadDefs(args.configFile)
if err != nil {
return nil, fmt.Errorf("could not parse config file %v: %w", args.configFile, err)
}

model, err := jsonio.NewReader().ReadSpec(args.specFile, defs)
model, err := jsonio.NewReader().ReadSpec(args.specFile, defs, isSG)
if err != nil {
return nil, fmt.Errorf("could not parse connectivity file %s: %w", args.specFile, err)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.23.0
require (
github.com/IBM/vpc-go-sdk v0.60.0
github.com/np-guard/cloud-resource-collector v0.16.0
github.com/np-guard/models v0.5.1
github.com/np-guard/models v0.5.2-0.20241010083230-9425a786fb15
github.com/spf13/cobra v1.8.1
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWb
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/np-guard/cloud-resource-collector v0.16.0 h1:KxFLcH19ZIvfGU63jJuMNN5sxW1uSdOrhCDwKHOyy0M=
github.com/np-guard/cloud-resource-collector v0.16.0/go.mod h1:93qwf/IT1L2Bv+6C6kund2GmKrSupTPujT0Nh6qB+mg=
github.com/np-guard/models v0.5.1 h1:qxewCB3cBLkBdcpMk05gKJkV1D7qkbteQdIXbN1juW0=
github.com/np-guard/models v0.5.1/go.mod h1:29M8utxinyUpYaDuIuOyCcMBf7EsMWZcIrRWCjFm0Bw=
github.com/np-guard/models v0.5.2-0.20241010083230-9425a786fb15 h1:UYBqJOLWWP3WX9duDDZqsZ4axHnnzOodw9BUZ63MYAY=
github.com/np-guard/models v0.5.2-0.20241010083230-9425a786fb15/go.mod h1:29M8utxinyUpYaDuIuOyCcMBf7EsMWZcIrRWCjFm0Bw=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
Expand Down
Loading
Loading