Skip to content

Commit 4d45a8f

Browse files
authored
Merge pull request #126 from jdschmitz15/master
Adding CSPIPList command.
2 parents 76b0a52 + 4cfbcad commit 4d45a8f

7 files changed

Lines changed: 931 additions & 16 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ version_notes
1212
cmd/virtualserviceimport/*
1313
templates/*
1414
jds*
15+
tmp*

cmd/cspiplist/cmd.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package cspiplist
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
ia "github.com/brian1917/illumioapi/v2"
8+
"github.com/brian1917/workloader/utils"
9+
"github.com/spf13/cobra"
10+
"github.com/spf13/viper"
11+
)
12+
13+
var pce ia.PCE
14+
var err error
15+
16+
var csp, ipListUrl, fileName, iplName, iplCsvFile, cspFilter string
17+
var testIPs, includev6, create, provision bool
18+
19+
//var ignoreCase, updatePCE bool
20+
21+
// init initializes the command line flags for the command
22+
func init() {
23+
CspIplistCmd.Flags().StringVarP(&csp, "csp", "", "", "Enter which csp (aws, azure, gcp,file) you want to get the ip list for.")
24+
CspIplistCmd.Flags().StringVarP(&ipListUrl, "url", "u", "", "If you want to override the default url for the csp ip list.")
25+
CspIplistCmd.Flags().BoolVarP(&testIPs, "test-ips", "t", false, "After consolidating/merging all the IP ranges validate that original subnets are part of some IP range.")
26+
CspIplistCmd.Flags().BoolVarP(&includev6, "ipv6", "", false, "Include ipv6 addresses. By default all ipv6 will be ignored.")
27+
CspIplistCmd.Flags().StringVarP(&fileName, "filename", "f", "", "Include filename if you enter \"file\" for as csp option.")
28+
CspIplistCmd.Flags().StringVarP(&cspFilter, "csp-filter", "", "", "Filter filename used filter IP ranges by service and/or region.")
29+
CspIplistCmd.Flags().BoolVarP(&create, "create", "c", false, "create ip list if it does not exist")
30+
CspIplistCmd.Flags().BoolVarP(&provision, "provision", "p", false, "provision ip list after replacing contents.")
31+
CspIplistCmd.MarkFlagRequired("csp")
32+
CspIplistCmd.Flags().SortFlags = false
33+
}
34+
35+
// TrafficCmd runs the workload identifier
36+
var CspIplistCmd = &cobra.Command{
37+
Use: "csp-iplist",
38+
Short: "Add/Update an IPList that consist of CSP ip ranges gathered from CSP website.",
39+
Long: `
40+
41+
This command will download the IP list for a given CSP via default, well-known urls. Workloader will try to create/update the specified IP List with the IP Ranges provided. There is an option to filter.
42+
the IP ranges by service and/or region. IP ranges will be consolidate by removing duplicates and merging consecutive ranges. By defalt the command will
43+
not include ipv6 addresses. If you want to include ipv6 addresses use the --ipv6 flag.
44+
45+
'workloader csp-iplist --csp gcp <ip listname>' or 'workloader csp-iplist --csp gcp --ipv6 <ip listname>' or 'workloader csp-iplist --csp gcp --csp-filter <filter filename> <ip listname>'
46+
The following CSPs are supported:
47+
- AWS
48+
- Azure
49+
- GCP
50+
51+
You can use the --url flag to override the default url for the csp ip range web location. You can also use specify 'file' as the CSP and provide the --filename flag to specify a file that contains a set of IP ranges. It perform the same
52+
check for duplicates and consolidate.
53+
54+
By default no changes will be made to the PCE. Please use --update-pce if you want to make changes. If the IP List is not configured on the PCE, use the --create flag to create it.
55+
56+
* Azure leaves services that span many regions with a blank region. This command will set those regions to "GLOBAL" so use "GLOBAL" in your filter file.
57+
`,
58+
Run: func(cmd *cobra.Command, args []string) {
59+
60+
pce, err = utils.GetTargetPCEV2(false)
61+
if err != nil {
62+
utils.LogError(fmt.Sprintf("error getting pce - %s", err.Error()))
63+
}
64+
65+
updatePCE := viper.Get("update_pce").(bool)
66+
noPrompt := viper.Get("no_prompt").(bool)
67+
68+
// Set the CSV file
69+
if len(args) > 1 {
70+
fmt.Println("command only accepts 1 or no arguments for the ip list name. See usage help.")
71+
os.Exit(0)
72+
}
73+
iplName = ""
74+
if len(args) > 0 {
75+
iplName = args[0]
76+
} else {
77+
utils.LogError("Please provide a name for the IP list.")
78+
}
79+
80+
cspiplist(&pce, updatePCE, noPrompt, csp, ipListUrl, iplName)
81+
},
82+
}

0 commit comments

Comments
 (0)