Просмотр исходного кода

feat(config): add new option to disable Miniflux's API

Julien Voisin 3 месяцев назад
Родитель
Сommit
4063ca39c9

+ 9 - 0
internal/config/options.go

@@ -194,6 +194,11 @@ func NewConfigOptions() *configOptions {
 				ValueType:         secretFileType,
 				TargetKey:         "DATABASE_URL",
 			},
+			"DISABLE_API": {
+				ParsedBoolValue: false,
+				RawValue:        "0",
+				ValueType:       boolType,
+			},
 			"DISABLE_HSTS": {
 				ParsedBoolValue: false,
 				RawValue:        "0",
@@ -711,6 +716,10 @@ func (c *configOptions) HasHTTPClientProxiesConfigured() bool {
 	return len(c.options["HTTP_CLIENT_PROXIES"].ParsedStringList) > 0
 }
 
+func (c *configOptions) HasAPI() bool {
+	return !c.options["DISABLE_API"].ParsedBoolValue
+}
+
 func (c *configOptions) HasHTTPService() bool {
 	return !c.options["DISABLE_HTTP_SERVICE"].ParsedBoolValue
 }

+ 3 - 1
internal/http/server/httpd.go

@@ -243,7 +243,9 @@ func setupHandler(store *storage.Storage, pool *worker.Pool) *mux.Router {
 
 	fever.Serve(subrouter, store)
 	googlereader.Serve(subrouter, store)
-	api.Serve(subrouter, store, pool)
+	if config.Opts.HasAPI() {
+		api.Serve(subrouter, store, pool)
+	}
 	ui.Serve(subrouter, store, pool)
 
 	subrouter.HandleFunc("/healthcheck", readinessProbe).Name("healthcheck")

+ 1 - 0
internal/template/functions.go

@@ -41,6 +41,7 @@ func (f *funcMap) Map() template.FuncMap {
 		"truncate":         truncate,
 		"isEmail":          isEmail,
 		"baseURL":          config.Opts.BaseURL,
+		"apiEnabled":       config.Opts.HasAPI,
 		"rootURL":          config.Opts.RootURL,
 		"disableLocalAuth": config.Opts.DisableLocalAuth,
 		"oidcProviderName": config.Opts.OAuth2OIDCProviderName,

+ 2 - 0
internal/template/templates/common/settings_menu.html

@@ -7,9 +7,11 @@
         <li>
             <a href="{{ route "integrations" }}">{{ icon "third-party-services" }}{{ t "menu.integrations" }}</a>
         </li>
+        {{ if apiEnabled }}
         <li>
             <a href="{{ route "apiKeys" }}">{{ icon "api" }}{{ t "menu.api_keys" }}</a>
         </li>
+        {{ end }}
         <li>
             <a href="{{ route "sessions" }}">{{ icon "sessions" }}{{ t "menu.sessions" }}</a>
         </li>

+ 6 - 4
internal/ui/ui.go

@@ -132,10 +132,12 @@ func Serve(router *mux.Router, store *storage.Storage, pool *worker.Pool) {
 	uiRouter.HandleFunc("/sessions/{sessionID}/remove", handler.removeSession).Name("removeSession").Methods(http.MethodPost)
 
 	// API Keys pages.
-	uiRouter.HandleFunc("/keys", handler.showAPIKeysPage).Name("apiKeys").Methods(http.MethodGet)
-	uiRouter.HandleFunc("/keys/{keyID}/delete", handler.deleteAPIKey).Name("deleteAPIKey").Methods(http.MethodPost)
-	uiRouter.HandleFunc("/keys/create", handler.showCreateAPIKeyPage).Name("createAPIKey").Methods(http.MethodGet)
-	uiRouter.HandleFunc("/keys/save", handler.saveAPIKey).Name("saveAPIKey").Methods(http.MethodPost)
+	if config.Opts.HasAPI() {
+		uiRouter.HandleFunc("/keys", handler.showAPIKeysPage).Name("apiKeys").Methods(http.MethodGet)
+		uiRouter.HandleFunc("/keys/{keyID}/delete", handler.deleteAPIKey).Name("deleteAPIKey").Methods(http.MethodPost)
+		uiRouter.HandleFunc("/keys/create", handler.showCreateAPIKeyPage).Name("createAPIKey").Methods(http.MethodGet)
+		uiRouter.HandleFunc("/keys/save", handler.saveAPIKey).Name("saveAPIKey").Methods(http.MethodPost)
+	}
 
 	// OPML pages.
 	uiRouter.HandleFunc("/export", handler.exportFeeds).Name("export").Methods(http.MethodGet)

+ 5 - 0
miniflux.1

@@ -235,6 +235,11 @@ Path to a secret key exposed as a file, it should contain $DATABASE_URL value\&.
 .br
 Default is empty\&.
 .TP
+.B DISABLE_API
+Disable miniflux's API\&.
+.br
+Default is false (The API is enabled)\&.
+.TP
 .B DISABLE_HSTS
 Disable HTTP Strict Transport Security header if \fBHTTPS\fR is set\&.
 .br