Remove web-push-(enabled|duration*), change endpoint, other cosmetic changes
This commit is contained in:
		
							parent
							
								
									4ce6fdcc5a
								
							
						
					
					
						commit
						d3ac976d05
					
				
					 17 changed files with 55 additions and 101 deletions
				
			
		
							
								
								
									
										13
									
								
								cmd/serve.go
									
										
									
									
									
								
							
							
						
						
									
										13
									
								
								cmd/serve.go
									
										
									
									
									
								
							|  | @ -94,13 +94,10 @@ var flagsServe = append( | |||
| 	altsrc.NewBoolFlag(&cli.BoolFlag{Name: "enable-metrics", Aliases: []string{"enable_metrics"}, EnvVars: []string{"NTFY_ENABLE_METRICS"}, Value: false, Usage: "if set, Prometheus metrics are exposed via the /metrics endpoint"}), | ||||
| 	altsrc.NewStringFlag(&cli.StringFlag{Name: "metrics-listen-http", Aliases: []string{"metrics_listen_http"}, EnvVars: []string{"NTFY_METRICS_LISTEN_HTTP"}, Usage: "ip:port used to expose the metrics endpoint (implicitly enables metrics)"}), | ||||
| 	altsrc.NewStringFlag(&cli.StringFlag{Name: "profile-listen-http", Aliases: []string{"profile_listen_http"}, EnvVars: []string{"NTFY_PROFILE_LISTEN_HTTP"}, Usage: "ip:port used to expose the profiling endpoints (implicitly enables profiling)"}), | ||||
| 	altsrc.NewBoolFlag(&cli.BoolFlag{Name: "web-push-enabled", Aliases: []string{"web_push_enabled"}, EnvVars: []string{"NTFY_WEB_PUSH_ENABLED"}, Usage: "enable web push (requires public and private key)"}), | ||||
| 	altsrc.NewStringFlag(&cli.StringFlag{Name: "web-push-public-key", Aliases: []string{"web_push_public_key"}, EnvVars: []string{"NTFY_WEB_PUSH_PUBLIC_KEY"}, Usage: "public key used for web push notifications"}), | ||||
| 	altsrc.NewStringFlag(&cli.StringFlag{Name: "web-push-private-key", Aliases: []string{"web_push_private_key"}, EnvVars: []string{"NTFY_WEB_PUSH_PRIVATE_KEY"}, Usage: "private key used for web push notifications"}), | ||||
| 	altsrc.NewStringFlag(&cli.StringFlag{Name: "web-push-subscriptions-file", Aliases: []string{"web_push_subscriptions_file"}, EnvVars: []string{"NTFY_WEB_PUSH_SUBSCRIPTIONS_FILE"}, Usage: "file used to store web push subscriptions"}), | ||||
| 	altsrc.NewStringFlag(&cli.StringFlag{Name: "web-push-email-address", Aliases: []string{"web_push_email_address"}, EnvVars: []string{"NTFY_WEB_PUSH_EMAIL_ADDRESS"}, Usage: "e-mail address of sender, required to use browser push services"}), | ||||
| 	altsrc.NewDurationFlag(&cli.DurationFlag{Name: "web-push-expiry-warning-duration", Aliases: []string{"web_push_expiry_warning_duration"}, EnvVars: []string{"NTFY_WEB_PUSH_EXPIRY_WARNING_DURATION"}, Value: server.DefaultWebPushExpiryWarningDuration, Usage: "duration after last update to send a warning notification"}), | ||||
| 	altsrc.NewDurationFlag(&cli.DurationFlag{Name: "web-push-expiry-duration", Aliases: []string{"web_push_expiry_duration"}, EnvVars: []string{"NTFY_WEB_PUSH_EXPIRY_DURATION"}, Value: server.DefaultWebPushExpiryDuration, Usage: "duration after last update to expire subscription"}), | ||||
| ) | ||||
| 
 | ||||
| var cmdServe = &cli.Command{ | ||||
|  | @ -136,12 +133,9 @@ func execServe(c *cli.Context) error { | |||
| 	keyFile := c.String("key-file") | ||||
| 	certFile := c.String("cert-file") | ||||
| 	firebaseKeyFile := c.String("firebase-key-file") | ||||
| 	webPushEnabled := c.Bool("web-push-enabled") | ||||
| 	webPushPrivateKey := c.String("web-push-private-key") | ||||
| 	webPushPublicKey := c.String("web-push-public-key") | ||||
| 	webPushSubscriptionsFile := c.String("web-push-subscriptions-file") | ||||
| 	webPushExpiryWarningDuration := c.Duration("web-push-expiry-warning-duration") | ||||
| 	webPushExpiryDuration := c.Duration("web-push-expiry-duration") | ||||
| 	webPushEmailAddress := c.String("web-push-email-address") | ||||
| 	cacheFile := c.String("cache-file") | ||||
| 	cacheDuration := c.Duration("cache-duration") | ||||
|  | @ -197,12 +191,10 @@ func execServe(c *cli.Context) error { | |||
| 	// Check values | ||||
| 	if firebaseKeyFile != "" && !util.FileExists(firebaseKeyFile) { | ||||
| 		return errors.New("if set, FCM key file must exist") | ||||
| 	} else if webPushEnabled && (webPushPrivateKey == "" || webPushPublicKey == "" || webPushSubscriptionsFile == "" || webPushEmailAddress == "" || baseURL == "") { | ||||
| 	} else if webPushPublicKey != "" && (webPushPrivateKey == "" || webPushSubscriptionsFile == "" || webPushEmailAddress == "" || baseURL == "") { | ||||
| 		return errors.New("if web push is enabled, web-push-private-key, web-push-public-key, web-push-subscriptions-file, web-push-email-address, and base-url should be set. run 'ntfy web-push generate-keys' to generate keys") | ||||
| 	} else if keepaliveInterval < 5*time.Second { | ||||
| 		return errors.New("keepalive interval cannot be lower than five seconds") | ||||
| 	} else if webPushEnabled && (webPushExpiryWarningDuration < 24*time.Hour || (webPushExpiryDuration-webPushExpiryWarningDuration < 24*time.Hour)) { | ||||
| 		return errors.New("web push expiry warning duration must be at least 1 day, expire duration must be at least 1 day later") | ||||
| 	} else if managerInterval < 5*time.Second { | ||||
| 		return errors.New("manager interval cannot be lower than five seconds") | ||||
| 	} else if cacheDuration > 0 && cacheDuration < managerInterval { | ||||
|  | @ -365,13 +357,10 @@ func execServe(c *cli.Context) error { | |||
| 	conf.MetricsListenHTTP = metricsListenHTTP | ||||
| 	conf.ProfileListenHTTP = profileListenHTTP | ||||
| 	conf.Version = c.App.Version | ||||
| 	conf.WebPushEnabled = webPushEnabled | ||||
| 	conf.WebPushPrivateKey = webPushPrivateKey | ||||
| 	conf.WebPushPublicKey = webPushPublicKey | ||||
| 	conf.WebPushSubscriptionsFile = webPushSubscriptionsFile | ||||
| 	conf.WebPushEmailAddress = webPushEmailAddress | ||||
| 	conf.WebPushExpiryDuration = webPushExpiryDuration | ||||
| 	conf.WebPushExpiryWarningDuration = webPushExpiryWarningDuration | ||||
| 
 | ||||
| 	// Set up hot-reloading of config | ||||
| 	go sigHandlerConfigReload(config) | ||||
|  |  | |||
|  | @ -14,7 +14,7 @@ func init() { | |||
| } | ||||
| 
 | ||||
| var cmdWebPush = &cli.Command{ | ||||
| 	Name:      "web-push", | ||||
| 	Name:      "webpush", | ||||
| 	Usage:     "Generate keys, in the future manage web push subscriptions", | ||||
| 	UsageText: "ntfy web-push [generate-keys]", | ||||
| 	Category:  categoryServer, | ||||
|  | @ -22,7 +22,7 @@ var cmdWebPush = &cli.Command{ | |||
| 	Subcommands: []*cli.Command{ | ||||
| 		{ | ||||
| 			Action:    generateWebPushKeys, | ||||
| 			Name:      "generate-keys", | ||||
| 			Name:      "keys", | ||||
| 			Usage:     "Generate VAPID keys to enable browser background push notifications", | ||||
| 			UsageText: "ntfy web-push generate-keys", | ||||
| 			Category:  categoryServer, | ||||
|  | @ -36,28 +36,15 @@ func generateWebPushKeys(c *cli.Context) error { | |||
| 		return err | ||||
| 	} | ||||
| 
 | ||||
| 	fmt.Fprintf(c.App.ErrWriter, `Keys generated. | ||||
| 	fmt.Fprintf(c.App.ErrWriter, `Web Push keys generated. Add the following lines to your config file: | ||||
| 
 | ||||
| VAPID Public Key: | ||||
| %s | ||||
| 
 | ||||
| VAPID Private Key: | ||||
| %s | ||||
| 
 | ||||
| --- | ||||
| 
 | ||||
| Add the following lines to your config file: | ||||
| 
 | ||||
| web-push-enabled: true | ||||
| web-push-public-key: %s | ||||
| web-push-private-key: %s | ||||
| web-push-subscriptions-file: <filename> | ||||
| web-push-subscriptions-file: /var/cache/ntfy/webpush.db # or similar | ||||
| web-push-email-address: <email address> | ||||
| 
 | ||||
| Look at the docs for other methods (e.g. command line flags & environment variables). | ||||
| 
 | ||||
| You will also need to set a base-url. | ||||
| `, publicKey, privateKey, publicKey, privateKey) | ||||
| See https://ntfy.sh/docs/config/#web-push for details. | ||||
| `, publicKey, privateKey) | ||||
| 
 | ||||
| 	return nil | ||||
| } | ||||
|  |  | |||
|  | @ -10,15 +10,15 @@ import ( | |||
| 
 | ||||
| func TestCLI_WebPush_GenerateKeys(t *testing.T) { | ||||
| 	app, _, _, stderr := newTestApp() | ||||
| 	require.Nil(t, runWebPushCommand(app, server.NewConfig(), "generate-keys")) | ||||
| 	require.Contains(t, stderr.String(), "Keys generated.") | ||||
| 	require.Nil(t, runWebPushCommand(app, server.NewConfig(), "keys")) | ||||
| 	require.Contains(t, stderr.String(), "Web Push keys generated.") | ||||
| } | ||||
| 
 | ||||
| func runWebPushCommand(app *cli.App, conf *server.Config, args ...string) error { | ||||
| 	webPushArgs := []string{ | ||||
| 		"ntfy", | ||||
| 		"--log-level=ERROR", | ||||
| 		"web-push", | ||||
| 		"webpush", | ||||
| 	} | ||||
| 	return app.Run(append(webPushArgs, args...)) | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue