package gtm import ( "net" "time" "github.com/zalando-techmonkeys/baboon-proxy/config" "github.com/zalando-techmonkeys/baboon-proxy/errors" ) // Baboon Config var ( conf = config.LoadConfig() gtmPartition = conf.Partition["gtm"] ltmPartition = conf.Partition["ltm"] ) // Trafficmanager matches internal (ITM) // or external (GTM) // Check if ITM/GTM is available // Required to create WIPs and Pools func Trafficmanager(cluster string) (string, *errors.Error) { var ( dnsserver string seconds = 2 tm map[string]string internalListeners = conf.Internalgtmlisteners externalListeners = conf.Externalgtmlisteners ) switch cluster {
func main() { app := gin.New() // Initialize config file conf := config.LoadConfig() // Version version := client.Version{Build: BuildTime, Hash: GitHash} // Use Logger, Cross-Origin Ressource and GZIP compression middleware app.Use(client.LoggerMiddleware()) app.Use(client.CORSMiddleware()) app.Use(gzip.Gzip(gzip.DefaultCompression)) rootusers, emergencyusers, OAuth2Endpoint, err := config.LoadAuthConf(conf) if err != nil { glog.Errorf("Could not load configuration. Reason: %s", err.Message) panic("Could not load configuration for Baboon. Exiting.") } glog.Infof("%+v", rootusers) app.GET("/api/version", version.BaboonVersion) if *gtmenabled { publicGTM := app.Group("/api/gtms/:trafficmanager") { publicGTM.GET("/pools", client.GTMPoolList) publicGTM.GET("/pools/:pool", client.GTMPoolNameList) publicGTM.GET("/pools/:pool/members", client.GTMPoolMemberList) publicGTM.GET("/wideips", client.GTMWipList) publicGTM.GET("/wideips/:wideip", client.GTMWipNameList) publicGTM.GET("/irules", client.GTMIRuleList) publicGTM.GET("/irules/:irule", client.GTMIRuleNameList) } privateGTM := app.Group("/api/gtms/:trafficmanager") privateGTM.Use(ginoauth2.Auth(ginoauth2.UidCheck, *OAuth2Endpoint, rootusers)) { privateGTM.POST("/pools", client.GTMPoolPost) privateGTM.POST("/pools/:pool/members", client.GTMPoolMemberPost) privateGTM.POST("/wideips", client.GTMWideipPost) privateGTM.DELETE("/pools/:pool", client.GTMPoolDelete) privateGTM.DELETE("/wideips/:wideip", client.GTMWipDelete) privateGTM.DELETE("/pools/:pool/members", client.GTMPoolMemberDelete) } emergencyGTM := app.Group("/api/gtms/:trafficmanager") emergencyGTM.Use(ginoauth2.Auth(ginoauth2.UidCheck, *OAuth2Endpoint, emergencyusers)) { emergencyGTM.PUT("/pools/:pool/members", client.GTMPoolMemberStatusPut) emergencyGTM.PUT("/pools", client.GTMPoolStatusPut) } } if *ltmenabled { publicLTM := app.Group("/api/ltms/:lbpair") { publicLTM.GET("/pools", client.LTMPoolList) publicLTM.GET("/pools/:pool", client.LTMPoolNameList) publicLTM.GET("/pools/:pool/members", client.LTMPoolMemberList) publicLTM.GET("/devices", client.LTMDeviceList) publicLTM.GET("/devices/:devicename", client.LTMDeviceNameList) publicLTM.GET("/virtuals", client.LTMVirtualServerList) publicLTM.GET("/virtuals/:virtual", client.LTMVirtualServerNameList) publicLTM.GET("/virtuals/:virtual/rules", client.LTMFWRuleList) publicLTM.GET("/virtuals/:virtual/profiles", client.LTMProfileList) publicLTM.GET("/datagroups", client.LTMDataGroupList) publicLTM.GET("/datagroups/:datagroupname", client.LTMDataGroupNameList) publicLTM.GET("/blacklist", client.LTMBlackAddressList) publicLTM.GET("/whitelist", client.LTMWhiteAddressList) publicLTM.GET("/irules", client.LTMIRuleList) publicLTM.GET("/irules/:irule", client.LTMIRuleNameList) } privateLTM := app.Group("/api/ltms/:lbpair") privateLTM.Use(ginoauth2.Auth(ginoauth2.UidCheck, *OAuth2Endpoint, rootusers)) { privateLTM.POST("/pools", client.LTMPoolPost) privateLTM.POST("/virtuals", client.LTMVirtualServerPost) privateLTM.POST("/pools/:pool/members", client.LTMPoolMemberPost) privateLTM.POST("/datagroups", client.LTMDataGroupPost) privateLTM.PUT("/pools", client.LTMPoolPut) privateLTM.PUT("/pools/:pool/members", client.LTMPoolMemberPut) privateLTM.DELETE("/pools/:pool", client.LTMPoolDelete) privateLTM.DELETE("/pools/:pool/members", client.LTMPoolMemberDelete) privateLTM.DELETE("/datagroups", client.LTMDataGroupDelete) privateLTM.PUT("/datagroups/:datagroupname", client.LTMDataGroupItemPut) privateLTM.PATCH("/datagroups/:datagroupname", client.LTMDataGroupItemPatch) //To do: privateLTM.DELETE("/datagroups/:direction/:datagroupname", client.LTMDataGroupItemDelete) } emergencyLTM := app.Group("/api/ltms/:lbpair") emergencyLTM.Use(ginoauth2.Auth(ginoauth2.UidCheck, *OAuth2Endpoint, emergencyusers)) { emergencyLTM.PATCH("/blacklist", client.LTMBlockIPPatch) emergencyLTM.PATCH("/whitelist", client.LTMWhiteIPPatch) emergencyLTM.DELETE("/whitelist", client.LTMRemoveWhiteIPPatch) emergencyLTM.DELETE("/blacklist", client.LTMRemoveBlockIPPatch) } } switch { case *sslenabled: run := app.RunTLS(fmt.Sprintf(":%s", strconv.Itoa(*port)), conf.Security["certFile"], conf.Security["keyFile"]) if run != nil { fmt.Println("Could not start web server,", run.Error()) } default: run := app.Run(fmt.Sprintf(":%s", strconv.Itoa(*port))) if run != nil { fmt.Println("Could not start web server,", run.Error()) } } }