|
| 1 | +package cmd |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "github.com/itzg/saml-auth-proxy/server" |
| 6 | + "github.com/jamiealquiza/envy" |
| 7 | + "github.com/spf13/cobra" |
| 8 | + "log" |
| 9 | + "os" |
| 10 | +) |
| 11 | + |
| 12 | +var serverConfig server.Config |
| 13 | + |
| 14 | +var rootCmd = &cobra.Command{ |
| 15 | + Use: "saml-auth-proxy", |
| 16 | + Short: "Provides a SAML SP authentication proxy for backend web services", |
| 17 | + Run: func(cmd *cobra.Command, args []string) { |
| 18 | + err := server.Start(&serverConfig) |
| 19 | + log.Fatal(err) |
| 20 | + }, |
| 21 | +} |
| 22 | + |
| 23 | +func init() { |
| 24 | + rootCmd.Flags().StringVar(&serverConfig.Bind, "bind", ":8080", "host:port to bind for serving HTTP") |
| 25 | + rootCmd.Flags().StringVar(&serverConfig.BaseUrl, "base-url", "", "External URL of this proxy") |
| 26 | + rootCmd.Flags().StringVar(&serverConfig.BackendUrl, "backend-url", "", "URL of the backend being proxied") |
| 27 | + rootCmd.Flags().StringVar(&serverConfig.NewAuthWebhookUrl, "new-auth-webhook-url", "", "URL of webhook that will get POST'ed when a new authentication is processed") |
| 28 | + rootCmd.Flags().StringVar(&serverConfig.IdpMetadataUrl, "idp-metadata-url", "", "URL of the IdP's metadata XML") |
| 29 | + rootCmd.Flags().StringVar(&serverConfig.SpKeyPath, "sp-key-path", "saml-auth-proxy.key", "Path to the X509 private key PEM file for this SP") |
| 30 | + rootCmd.Flags().StringVar(&serverConfig.SpCertPath, "sp-cert-path", "saml-auth-proxy.cert", "Path to the X509 public certificate PEM file for this SP") |
| 31 | + rootCmd.Flags().StringToStringVar(&serverConfig.AttributeHeaderMappings, "attribute-header-mappings", nil, |
| 32 | + "Comma separated list of attribute=header pairs mapping SAML IdP response attributes to forwarded request header") |
| 33 | + |
| 34 | + _ = rootCmd.MarkFlagRequired("base-url") |
| 35 | + _ = rootCmd.MarkFlagRequired("backend-url") |
| 36 | + _ = rootCmd.MarkFlagRequired("idp-metadata-url") |
| 37 | +} |
| 38 | + |
| 39 | +func Execute(version string) { |
| 40 | + |
| 41 | + rootCmd.Version = version |
| 42 | + |
| 43 | + cfg := envy.CobraConfig{ |
| 44 | + Prefix: "SAML_PROXY", |
| 45 | + } |
| 46 | + |
| 47 | + envy.ParseCobra(rootCmd, cfg) |
| 48 | + |
| 49 | + if err := rootCmd.Execute(); err != nil { |
| 50 | + fmt.Println(err) |
| 51 | + os.Exit(1) |
| 52 | + } |
| 53 | +} |
0 commit comments