From 5704081ae3055582ff09fe3fd29318716573df0b Mon Sep 17 00:00:00 2001 From: Jayce Date: Fri, 28 Sep 2018 16:22:20 +0200 Subject: [PATCH 1/2] Set API Key File in Config.Properties Added to GitIgnore Config.Properties with a default folder --- .gitignore | 7 ++----- config.properties | 3 ++- dialog/src/main/java/roboy/util/ConfigManager.java | 2 ++ dialog/src/main/java/roboy/util/api/APIHandler.java | 3 ++- resources/knowledgebase/apiKeys.yml | 3 --- 5 files changed, 8 insertions(+), 10 deletions(-) delete mode 100644 resources/knowledgebase/apiKeys.yml diff --git a/.gitignore b/.gitignore index b008a643..b4a5272c 100644 --- a/.gitignore +++ b/.gitignore @@ -20,7 +20,6 @@ local.properties .target resources/word2vec_toy_data_and_model -resources/knowledgebase/apikeys.yml resources_nlu/word2vec/roboy_enwik8.txt docs/doxyxml @@ -71,9 +70,7 @@ interactive/.ipynb_checkpoints community-server/data community-server/data-backup -*.iml nlu/parser/target/ -nlu/parser/src/main/java/edu/stanford/nlp/sempre/roboy/api/apiKeys\.yml - -dialog/src/main/java/roboy/util/api/apiKeys\.yml +# API KEYS +*.key \ No newline at end of file diff --git a/config.properties b/config.properties index 8bcf8dd7..45e2c793 100755 --- a/config.properties +++ b/config.properties @@ -79,4 +79,5 @@ DIALOG_LOG_MODE: "WARN" # Supports all Log4J levels. See Documentation for more details PARSER_LOG_MODE: "WARN" -TELEGRAM_API_TOKENS_FILE: "/Users/Apple/botboy/tokens.json" \ No newline at end of file +TELEGRAM_API_TOKENS_FILE: "/Users/Apple/botboy/tokens.json" +EXTERNAL_API_KEY_LIST: "resources/knowledgebase/api.key" \ No newline at end of file diff --git a/dialog/src/main/java/roboy/util/ConfigManager.java b/dialog/src/main/java/roboy/util/ConfigManager.java index 8aec3099..9558b35b 100644 --- a/dialog/src/main/java/roboy/util/ConfigManager.java +++ b/dialog/src/main/java/roboy/util/ConfigManager.java @@ -44,6 +44,7 @@ public class ConfigManager { public static boolean CONTEXT_GUI_ENABLED = false; public static String TELEGRAM_API_TOKENS_FILE = ""; + public static String EXTERNAL_API_KEY_LIST = "resources/knowledgebase/api.key"; public static String MEMORY_LOG_MODE = "INFO"; public static String DIALOG_LOG_MODE = "INFO"; @@ -122,6 +123,7 @@ private static void initializeConfig() { ACTION_CLIENT_SCRIPT = yamlConfig.getString("ACTION_CLIENT_SCRIPT"); TELEGRAM_API_TOKENS_FILE = yamlConfig.getString("TELEGRAM_API_TOKENS_FILE"); + EXTERNAL_API_KEY_LIST = yamlConfig.getString("EXTERNAL_API_KEY_LIST"); MEMORY_LOG_MODE = (yamlConfig.getString("MEMORY_LOG_MODE")); PARSER_LOG_MODE = (yamlConfig.getString("PARSER_LOG_MODE")); diff --git a/dialog/src/main/java/roboy/util/api/APIHandler.java b/dialog/src/main/java/roboy/util/api/APIHandler.java index 6aae1735..7f60aeb7 100644 --- a/dialog/src/main/java/roboy/util/api/APIHandler.java +++ b/dialog/src/main/java/roboy/util/api/APIHandler.java @@ -3,6 +3,7 @@ import org.apache.commons.configuration2.YAMLConfiguration; import org.apache.commons.configuration2.ex.ConfigurationException; import org.apache.logging.log4j.Logger; +import roboy.util.ConfigManager; import java.io.*; import java.net.HttpURLConnection; @@ -49,7 +50,7 @@ private static final class keyGetter { static String getKey(String key) { try { - yamlConfiguration.read(new FileReader("resources/knowledgebase/apiKeys.yml")); + yamlConfiguration.read(new FileReader(ConfigManager.EXTERNAL_API_KEY_LIST)); } catch (ConfigurationException e) { logger.error("Config File contains Errors"); logger.error(e.getMessage()); diff --git a/resources/knowledgebase/apiKeys.yml b/resources/knowledgebase/apiKeys.yml deleted file mode 100644 index 22207938..00000000 --- a/resources/knowledgebase/apiKeys.yml +++ /dev/null @@ -1,3 +0,0 @@ -moviekey: xxxxxxxxxxxxxxxxxxxxxxxx -translatekey: xxxxxxxxxxxxxxxxxxxxxxxx -weatherkey: xxxxxxxxxxxxxxxxxxxxxxxx \ No newline at end of file From ad941ac06d995205f3423a883d02ec63435ad854 Mon Sep 17 00:00:00 2001 From: Jayce Date: Fri, 28 Sep 2018 16:24:35 +0200 Subject: [PATCH 2/2] Update ReadMe & Documentation --- README.md | 2 +- docs/developer_manual/1_Tutorials.rst | 6 +++--- docs/user_manual/2_configuration.rst | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a9542a51..79ffc475 100755 --- a/README.md +++ b/README.md @@ -197,7 +197,7 @@ If you wish to have more detailed information, please view the [docs page](https ### Enabling External APIs -If you want to set external APIs, you will have to create an `APIkeys.yml` file containing all the keys. For more information, see the [relevant documentation page](https://roboydialog.readthedocs.io/en/devel/user_manual/2_configuration.html#enabling-external-apis) +If you want to set external APIs, you will have to create an `api.key` file containing all the keys. For more information, see the [relevant documentation page](https://roboydialog.readthedocs.io/en/devel/user_manual/2_configuration.html#enabling-external-apis) ## Troubleshooting diff --git a/docs/developer_manual/1_Tutorials.rst b/docs/developer_manual/1_Tutorials.rst index 9dbc99d9..f79bf011 100644 --- a/docs/developer_manual/1_Tutorials.rst +++ b/docs/developer_manual/1_Tutorials.rst @@ -650,7 +650,7 @@ To make the process of adding new external APIs easier, an interface is provided Storing API Keys ------------------------ -API Keys should be stored in the ``roboy_dialog/resources/knowledgebase/apiKeys.yml`` file. It is vitally important that this file does not end up on git. Entries should be stored in the YAML format: ``apikey: xxxxxxx_apikey_goes_here_xxxxxxx``. The first part of the entry is the YAML key, while the second is the actual API key. +API Keys should be stored in the ``roboy_dialog/resources/knowledgebase/api.key`` file. It is vitally important that this file does not end up on git. Entries should be stored in the YAML format: ``apikey: xxxxxxx_apikey_goes_here_xxxxxxx``. The first part of the entry is the YAML key, while the second is the actual API key. Implementing the Interface --------------------------- @@ -662,7 +662,7 @@ One must implement the methods... getKeyName ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -The purpose of ``getKeyName`` is to tell APIHub, what the YAML key associated with the API Key in the ``apiKeys.yml`` file is. ``return "weatherkey";`` in most cases shall suffice. +The purpose of ``getKeyName`` is to tell APIHub, what the YAML key associated with the API Key in the ``api.key`` file is. ``return "weatherkey";`` in most cases shall suffice. validateArguments ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -675,7 +675,7 @@ This method should be used to check if the arguments passed by the user are vali getAPIURL ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -This method is in charge of creating the API Request URL. Assuming the ``getKeyName`` function is implemented correctly, the first parameter shall automatically send you the API Key from the ``apiKeys.yml`` file. The second parameter are the API Request Arguments that your state sends to APIHub. +This method is in charge of creating the API Request URL. Assuming the ``getKeyName`` function is implemented correctly, the first parameter shall automatically send you the API Key from the ``api.key`` file. The second parameter are the API Request Arguments that your state sends to APIHub. This method expects a valid API request URL to be returned, like ``http://api.openweathermap.org/data/2.5/weather?q=davos&APPID=xxxxxxxxx``. diff --git a/docs/user_manual/2_configuration.rst b/docs/user_manual/2_configuration.rst index 3a1d3d79..b489575f 100644 --- a/docs/user_manual/2_configuration.rst +++ b/docs/user_manual/2_configuration.rst @@ -130,7 +130,7 @@ Roboy Dialog supports multiple external APIs. At the present moment, three exter - The Movie DB - Yandex Translate -If you wish to have Roboy be able to tell the weather, tell you upcoming movies and translate, you have to register on these websites, generate an API key and denote the key in the ``resources/knowledgebase/apiKeys.yml`` file. There you shall replace the ``xxxxxxx`` portions with your key. +If you wish to have Roboy be able to tell the weather, tell you upcoming movies and translate, you have to register on these websites, generate an API key and denote the key in the ``resources/knowledgebase/api.key`` file. There you shall replace the ``xxxxxxx`` portions with your key. .. warning:: Do not upload any changes to the apiKey file to Git. Consequences will be severe...