Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

added flag to allow user to change configuration set changes #39

Merged
merged 4 commits into from
Aug 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions waflyctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,26 @@ func PatchRules(serviceID, wafID string, client fastly.Client) bool {
return true
}

// changeConfigurationSet function allows you to change a config set for a WAF object
func setConfigurationSet(wafID, configurationSet string, client fastly.Client) bool {

wafs := []fastly.ConfigSetWAFs{{ID:wafID}}

_, err := client.UpdateWAFConfigSet(&fastly.UpdateWAFConfigSetInput{
WAFList:wafs,
ConfigSetID: configurationSet,
})


//check if we had an issue with our call
if err != nil {
Error.Println("Error setting configuration set ID: " + configurationSet)
return false
}

return true

}

// getConfigurationSets function provides a listing of all config sets
func getConfigurationSets(apiEndpoint, apiKey string) bool {
Expand Down Expand Up @@ -1664,16 +1684,13 @@ func main() {
serviceID := flag.String("serviceid", "", "[Required] Service ID to Provision")
apiKey := flag.String("apikey", "", "[Required] API Key to use")
apiEndpoint := flag.String("apiendpoint", "https://api.fastly.com", "Fastly API endpoint to use.")
//emergency := flag.Bool("emergency", false, "is this an emergency provisioning..see [wiki link]")
//ssl := flag.Bool("ssl", false, "turn on ssl for this domain..see [wiki link]")
configFile := flag.String("config", HOMEDIRECTORY + "/.waflyctl.toml", "Location of configuration file for waflyctl.")

//var blocklist string
//flag.StringVar(&blocklist, "blocklist", "gcp,aws,azure,aws,TOR", "Which blocklist should we provisioned on block mode in a comma delimited fashion. Available choices are: [for look here]")
ListAllRules := flag.String("list-all-rules", "", "List all rules available on the Fastly platform for a given configuration set. Must pass a configuration set ID")
ListRules := flag.Bool("list-rules", false, "List current WAF rules and their status")

ListConfigSet := flag.Bool("list-configuration-sets", false, "List all configuration sets and their status")
//flag.StringVar(&blocklist, "blocklist", "gcp,aws,azure,aws,TOR", "Which blocklist should we provisioned on block mode in a comma delimited fashion. Available choices are: [for look here]")
ConfigurationSet := flag.String("configuration-set", "", "Changes WAF configuration set to the provided one]")

var Rules string
flag.StringVar(&Rules, "rules", "", "Which rules to apply action on in a comma delimited fashion, overwrites ruleid defined in config file, example: 94011,93110,1000101..")
Expand Down Expand Up @@ -1937,6 +1954,14 @@ func main() {
Info.Println("Completed")
os.Exit(1)

//change a configuration set
case *ConfigurationSet != "":
Info.Printf("Changing Configuration Set to: %s", *ConfigurationSet)
ConfigID := *ConfigurationSet
setConfigurationSet(waf.ID,ConfigID, *client)
Info.Println("Completed")
os.Exit(1)

case *Status != "":
Info.Println("Changing WAF Status")
//rule management
Expand Down