diff --git a/README.md b/README.md index 886d96fb75807c2649e80839d9239f669fa81432..50c41572aa265dd4557b4fdf6b9c1c8cee75f04e 100644 --- a/README.md +++ b/README.md @@ -134,24 +134,25 @@ docker-compose up -d --build ## Arguments -| Argument | Description | Default | Env. name | -| ------------- | ------------------------------ | -------------------- | ---------------------- | -| --host | Set host to bind the server to | `127.0.0.1` | LT_HOST | -| --port | Set port to bind the server to | `5000` | LT_PORT | -| --char-limit | Set character limit | `No limit` | LT_CHAR_LIMIT | -| --req-limit | Set maximum number of requests per minute per client | `No limit` | LT_REQ_LIMIT | -| --batch-limit | Set maximum number of texts to translate in a batch request | `No limit` | LT_BATCH_LIMIT | -| --ga-id | Enable Google Analytics on the API client page by providing an ID | `No tracking` | LT_GA_ID | -| --debug | Enable debug environment | `False` | LT_DEBUG | -| --ssl | Whether to enable SSL | `False` | LT_SSL | -| --frontend-language-source | Set frontend default language - source | `en` | LT_FRONTEND_LANGUAGE_SOURCE | -| --frontend-language-target | Set frontend default language - target | `es` | LT_FRONTEND_LANGUAGE_TARGET | -| --frontend-timeout | Set frontend translation timeout | `500` | LT_FRONTEND_TIMEOUT | -| --api-keys | Enable API keys database for per-user rate limits lookup | `Don't use API keys` | LT_API_KEYS | -| --require-api-key-origin | Require use of an API key for programmatic access to the API, unless the request origin matches this domain | `No restrictions on domain origin` | LT_REQUIRE_API_KEY_ORIGIN | -| --load-only | Set available languages | `all from argostranslate` | LT_LOAD_ONLY | -| --suggestions | Allow user suggestions | `false` | LT_SUGGESTIONS | -| --disable-files-translation | Disable files translation | `false` | LT_DISABLE_FILES_TRANSLATION | +| Argument | Description | Default | Env. name | +|-----------------------------|-------------------------------------------------------------------------------------------------------------| -------------------- |------------------------------| +| --host | Set host to bind the server to | `127.0.0.1` | LT_HOST | +| --port | Set port to bind the server to | `5000` | LT_PORT | +| --char-limit | Set character limit | `No limit` | LT_CHAR_LIMIT | +| --req-limit | Set maximum number of requests per minute per client | `No limit` | LT_REQ_LIMIT | +| --batch-limit | Set maximum number of texts to translate in a batch request | `No limit` | LT_BATCH_LIMIT | +| --ga-id | Enable Google Analytics on the API client page by providing an ID | `No tracking` | LT_GA_ID | +| --debug | Enable debug environment | `False` | LT_DEBUG | +| --ssl | Whether to enable SSL | `False` | LT_SSL | +| --frontend-language-source | Set frontend default language - source | `en` | LT_FRONTEND_LANGUAGE_SOURCE | +| --frontend-language-target | Set frontend default language - target | `es` | LT_FRONTEND_LANGUAGE_TARGET | +| --frontend-timeout | Set frontend translation timeout | `500` | LT_FRONTEND_TIMEOUT | +| --api-keys | Enable API keys database for per-user rate limits lookup | `Don't use API keys` | LT_API_KEYS | +| --require-api-key-origin | Require use of an API key for programmatic access to the API, unless the request origin matches this domain | `No restrictions on domain origin` | LT_REQUIRE_API_KEY_ORIGIN | +| --load-only | Set available languages | `all from argostranslate` | LT_LOAD_ONLY | +| --suggestions | Allow user suggestions | `false` | LT_SUGGESTIONS | +| --disable-files-translation | Disable files translation | `false` | LT_DISABLE_FILES_TRANSLATION | +| --disable-web-ui | Disable web ui | `false` | LT_DISABLE_WEB_UI | Note that each argument has an equivalent env. variable that can be used instead. The env. variables overwrite the default values but have lower priority than the command aguments. They are particularly useful if used with Docker. Their name is the upper-snake case of the command arguments' ones, with a `LT` prefix. diff --git a/app/app.py b/app/app.py index 03f0b0fcb7052e6abe10cbdc42b68acc7f4ca9ea..411e5a30cba974ad13f2d059d560de6f45094e66 100644 --- a/app/app.py +++ b/app/app.py @@ -209,6 +209,9 @@ def create_app(args): @app.route("/") @limiter.exempt def index(): + if args.disable_web_ui: + abort(404) + return render_template( "index.html", gaId=args.ga_id, @@ -221,6 +224,9 @@ def create_app(args): @app.route("/javascript-licenses", methods=["GET"]) @limiter.exempt def javascript_licenses(): + if args.disable_web_ui: + abort(404) + return render_template("javascript-licenses.html") @app.route("/languages", methods=["GET", "POST"]) diff --git a/app/default_values.py b/app/default_values.py index 8808d176f761a5a3e7c16712fb0e4acc3b16d5fe..b6fff3fe4872d1fc714aa8187e013a0e0de638dc 100644 --- a/app/default_values.py +++ b/app/default_values.py @@ -19,7 +19,7 @@ def _get_value_bool(name, default_value): if env_value in ['TRUE', 'True', 'true', '1']: return True return default_value - + def _get_value(name, default_value, value_type): env_name = _prefix + name if value_type == 'str': @@ -75,7 +75,7 @@ _default_options_objects = [ 'name': 'DEBUG', 'default_value': False, 'value_type': 'bool' - }, + }, { 'name': 'SSL', 'default_value': None, @@ -120,7 +120,12 @@ _default_options_objects = [ 'name': 'DISABLE_FILES_TRANSLATION', 'default_value': False, 'value_type': 'bool' - } + }, + { + 'name': 'DISABLE_WEB_UI', + 'default_value': False, + 'value_type': 'bool' + }, ] diff --git a/app/main.py b/app/main.py index 4905865e4b68e4d59b6d847c38dde3d2cc88c67d..ab0e61c499f9c0c22a7773dadc44aa6d001ba6da 100644 --- a/app/main.py +++ b/app/main.py @@ -108,6 +108,9 @@ def main(): parser.add_argument( "--disable-files-translation", default=DEFARGS['DISABLE_FILES_TRANSLATION'], action="store_true", help="Disable files translation" ) + parser.add_argument( + "--disable-web-ui", default=DEFARGS['DISABLE_WEB_UI'], action="store_true", help="Disable web ui" + ) args = parser.parse_args() app = create_app(args)