Commit 646e7f23 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

refactor: move command flag headers to the flag definitions

parent 46925b9c
......@@ -6,7 +6,8 @@ import (
)
// headerFlagsTemplate is copied from cobra.Command.UsageTemplate, modified to include an invocation
// of insertHeaders on the flags, which intersperses the flags with headers.
// of insertHeaders on the flags, which intersperses the flags with headers defined in the
// flagHeaders variable.
var headerFlagsTemplate = `Usage:{{if .Runnable}}
{{.UseLine}}{{end}}{{if .HasAvailableSubCommands}}
{{.CommandPath}} [command]{{end}}{{if gt (len .Aliases) 0}}
......
......@@ -32,14 +32,8 @@ func init() {
keyshareRootCmd.AddCommand(myirmaServerCmd)
myirmaServerCmd.SetUsageTemplate(headerFlagsTemplate)
flagHeaders["irma keyshare myirmaserver"] = map[string]string{
"port": "Server address and port to listen on",
"db-type": "Database configuration",
"keyshare-attributes": "IRMA session configuration",
"email-server": "Email configuration (leave empty to disable sending emails)",
"tls-cert": "TLS configuration (leave empty to disable TLS)",
"verbose": "Other options",
}
headers := map[string]string{}
flagHeaders["irma keyshare myirmaserver"] = headers
flags := myirmaServerCmd.Flags()
flags.SortFlags = false
......@@ -53,17 +47,21 @@ func init() {
flags.String("static-prefix", "/", "Host static files under this URL prefix")
flags.Bool("sse", false, "Enable server sent for status updates (experimental)")
headers["port"] = "Server address and port to listen on"
flags.IntP("port", "p", 8080, "port at which to listen")
flags.StringP("listen-addr", "l", "", "address at which to listen (default 0.0.0.0)")
flags.StringSlice("cors-allowed-origins", nil, "CORS allowed origins")
headers["db-type"] = "Database configuration"
flags.String("db-type", string(myirmaserver.DBTypePostgres), "Type of database to connect keyshare server to")
flags.String("db", "", "Database server connection string")
headers["keyshare-attributes"] = "IRMA session configuration"
flags.StringSlice("keyshare-attributes", nil, "Attributes allowed for login to myirma")
flags.StringSlice("email-attributes", nil, "Attributes allowed for adding email addresses")
flags.Int("session-lifetime", myirmaserver.SessionLifetimeDefault, "Session lifetime in seconds")
headers["email-server"] = "Email configuration (leave empty to disable sending emails)"
flags.String("email-server", "", "Email server to use for sending email address confirmation emails")
flags.String("email-hostname", "", "Hostname used in email server tls certificate (leave empty when mail server does not use tls)")
flags.String("email-username", "", "Username to use when authenticating with email server")
......@@ -79,12 +77,14 @@ func init() {
flags.StringToString("delete-account-files", nil, "Translated emails for the delete account email")
flags.Int("delete-delay", 0, "delay in days before a user or email address deletion becomes effective")
headers["tls-cert"] = "TLS configuration (leave empty to disable TLS)"
flags.String("tls-cert", "", "TLS certificate (chain)")
flags.String("tls-cert-file", "", "path to TLS certificate (chain)")
flags.String("tls-privkey", "", "TLS private key")
flags.String("tls-privkey-file", "", "path to TLS private key")
flags.Bool("no-tls", false, "Disable TLS")
headers["verbose"] = "Other options"
flags.CountP("verbose", "v", "verbose (repeatable)")
flags.BoolP("quiet", "q", false, "quiet")
flags.Bool("log-json", false, "Log in JSON format")
......
......@@ -33,15 +33,8 @@ func init() {
keyshareRootCmd.AddCommand(keyshareServerCmd)
keyshareServerCmd.SetUsageTemplate(headerFlagsTemplate)
flagHeaders["irma keyshare server"] = map[string]string{
"port": "Server address and port to listen on",
"db-type": "Database configuration",
"jwt-privkey": "Cryptographic keys",
"keyshare-attribute": "Keyshare server attribute issued during registration",
"email-server": "Email configuration (leave empty to disable sending emails)",
"tls-cert": "TLS configuration (leave empty to disable TLS)",
"verbose": "Other options",
}
headers := map[string]string{}
flagHeaders["irma keyshare server"] = headers
flags := keyshareServerCmd.Flags()
flags.SortFlags = false
......@@ -52,12 +45,15 @@ func init() {
flags.StringP("privkeys", "k", "", "path to IRMA private keys")
flags.StringP("url", "u", "", "external URL to server to which the IRMA client connects, \":port\" being replaced by --port value")
headers["port"] = "Server address and port to listen on"
flags.IntP("port", "p", 8080, "port at which to listen")
flags.StringP("listen-addr", "l", "", "address at which to listen (default 0.0.0.0)")
headers["db-type"] = "Database configuration"
flags.String("db-type", string(keyshareserver.DBTypePostgres), "Type of database to connect keyshare server to")
flags.String("db", "", "Database server connection string")
headers["jwt-privkey"] = "Cryptographic keys"
flags.String("jwt-privkey", "", "Private jwt key of keyshare server")
flags.String("jwt-privkey-file", "", "Path to file containing private jwt key of keyshare server")
flags.Int("jwt-privkey-id", 0, "Key identifier of keyshare server public key matching used private key")
......@@ -66,8 +62,10 @@ func init() {
flags.String("storage-primary-keyfile", "", "Primary key used for encrypting and decrypting secure containers")
flags.StringSlice("storage-fallback-keyfile", nil, "Fallback key(s) used to decrypt older secure containers")
headers["keyshare-attribute"] = "Keyshare server attribute issued during registration"
flags.String("keyshare-attribute", "", "Attribute identifier that contains username")
headers["email-server"] = "Email configuration (leave empty to disable sending emails)"
flags.String("email-server", "", "Email server to use for sending email address confirmation emails")
flags.String("email-hostname", "", "Hostname used in email server tls certificate (leave empty when mail server does not use tls)")
flags.String("email-username", "", "Username to use when authenticating with email server")
......@@ -78,12 +76,14 @@ func init() {
flags.StringToString("registration-email-files", nil, "Translated emails for the registration email")
flags.StringToString("verification-url", nil, "Base URL for the email verification link (localized)")
headers["tls-cert"] = "TLS configuration (leave empty to disable TLS)"
flags.String("tls-cert", "", "TLS certificate (chain)")
flags.String("tls-cert-file", "", "path to TLS certificate (chain)")
flags.String("tls-privkey", "", "TLS private key")
flags.String("tls-privkey-file", "", "path to TLS private key")
flags.Bool("no-tls", false, "Disable TLS")
headers["verbose"] = "Other options"
flags.CountP("verbose", "v", "verbose (repeatable)")
flags.BoolP("quiet", "q", false, "quiet")
flags.Bool("log-json", false, "Log in JSON format")
......
......@@ -21,23 +21,22 @@ func init() {
keyshareRootCmd.AddCommand(keyshareTaskCmd)
keyshareTaskCmd.SetUsageTemplate(headerFlagsTemplate)
flagHeaders["irma keyshare tasks"] = map[string]string{
"db": "Database configuration",
"expiry-delay": "Time period configuraiton",
"email-server": "Email configuration (leave empty to disable sending emails)",
"verbose": "Other options",
}
headers := map[string]string{}
flagHeaders["irma keyshare tasks"] = headers
flags := keyshareTaskCmd.Flags()
flags.SortFlags = false
flags.StringP("config", "c", "", "path to configuration file")
headers["db"] = "Database configuration"
flags.String("db", "", "Database server connection string")
headers["expiry-delay"] = "Time period configuration"
flags.Int("expiry-delay", 365, "Number of days of inactivity until account expires")
flags.Int("delete-delay", 30, "Number of days until expired account should be deleted")
headers["email-server"] = "Email configuration (leave empty to disable sending emails)"
flags.String("email-server", "", "Email server to use for sending email address confirmation emails")
flags.String("email-hostname", "", "Hostname used in email server tls certificate (leave empty when mail server does not use tls)")
flags.String("email-username", "", "Username to use when authenticating with email server")
......@@ -47,6 +46,7 @@ func init() {
flags.StringToString("expired-email-subjects", nil, "Translated subject lines for the expired account email")
flags.StringToString("expired-email-files", nil, "Translated emails for the expired account email")
headers["verbose"] = "Other options"
flags.CountP("verbose", "v", "verbose (repeatable)")
flags.BoolP("quiet", "q", false, "quiet")
flags.Bool("log-json", false, "Log in JSON format")
......
......@@ -68,14 +68,8 @@ func init() {
func setFlags(cmd *cobra.Command, production bool) error {
cmd.SetUsageTemplate(headerFlagsTemplate)
flagHeaders["irma server"] = map[string]string{
"port": "Server address and port to listen on",
"no-auth": "Requestor authentication and default requestor permissions",
"jwt-issuer": "JWT configuration",
"tls-cert": "TLS configuration (leave empty to disable TLS)",
"email": "Email address (see README for more info)",
"verbose": "Other options",
}
headers := map[string]string{}
flagHeaders["irma server"] = headers
var defaulturl string
if !production {
......@@ -101,12 +95,14 @@ func setFlags(cmd *cobra.Command, production bool) error {
flags.String("revocation-db-str", "", "connection string for revocation database")
flags.Bool("sse", false, "Enable server sent for status updates (experimental)")
headers["port"] = "Server address and port to listen on"
flags.IntP("port", "p", 8088, "port at which to listen")
flags.StringP("listen-addr", "l", "", "address at which to listen (default 0.0.0.0)")
flags.StringP("api-prefix", "a", "/", "prefix API endpoints with this string, e.g. POST /session becomes POST {api-prefix}/session")
flags.Int("client-port", 0, "if specified, start a separate server for the IRMA app at this port")
flags.String("client-listen-addr", "", "address at which server for IRMA app listens")
headers["no-auth"] = "Requestor authentication and default requestor permissions"
flags.Bool("no-auth", !production, "whether or not to authenticate requestors (and reject all authenticated requests)")
flags.String("requestors", "", "requestor configuration (in JSON)")
flags.StringSlice("disclose-perms", nil, "list of attributes that all requestors may verify (default *)")
......@@ -122,6 +118,7 @@ func setFlags(cmd *cobra.Command, production bool) error {
flags.String("revocation-settings", "", "revocation settings (in JSON)")
headers["jwt-issuer"] = "JWT configuration"
flags.StringP("jwt-issuer", "j", "irmaserver", "JWT issuer")
flags.String("jwt-privkey", "", "JWT private key")
flags.String("jwt-privkey-file", "", "path to JWT private key")
......@@ -129,6 +126,7 @@ func setFlags(cmd *cobra.Command, production bool) error {
flags.Bool("allow-unsigned-callbacks", false, "Allow callbackUrl in session requests when no JWT privatekey is installed (potentially unsafe)")
flags.Bool("augment-client-return-url", false, "Augment the client return url with the server session token if present")
headers["tls-cert"] = "TLS configuration (leave empty to disable TLS)"
flags.String("tls-cert", "", "TLS certificate (chain)")
flags.String("tls-cert-file", "", "path to TLS certificate (chain)")
flags.String("tls-privkey", "", "TLS private key")
......@@ -139,9 +137,11 @@ func setFlags(cmd *cobra.Command, production bool) error {
flags.String("client-tls-privkey-file", "", "path to TLS private key for IRMA app server")
flags.Bool("no-tls", false, "Disable TLS")
headers["email"] = "Email address (see README for more info)"
flags.StringP("email", "e", "", "Email address of server admin, for incidental notifications such as breaking API changes")
flags.Bool("no-email", !production, "Opt out of providing an email address with --email")
headers["verbose"] = "Other options"
flags.CountP("verbose", "v", "verbose (repeatable)")
flags.BoolP("quiet", "q", false, "quiet")
flags.Bool("log-json", false, "Log in JSON format")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment