Add credentials for remove REST API calls

The base URL and credentials used for REST API calls can now be defined in
the [maxscale] section. This allows encrypted passwords to be used.
This commit is contained in:
Markus Mäkelä
2018-08-22 17:19:27 +03:00
parent fe7d7475a4
commit a6bef0a80d
7 changed files with 79 additions and 12 deletions

View File

@ -145,6 +145,9 @@ extern const char CN_OPTIONS[];
extern const char CN_PARAMETERS[];
extern const char CN_PASSIVE[];
extern const char CN_PASSWORD[];
extern const char CN_PEER_HOSTS[];
extern const char CN_PEER_PASSWORD[];
extern const char CN_PEER_USER[];
extern const char CN_POLL_SLEEP[];
extern const char CN_PORT[];
extern const char CN_PROTOCOL[];
@ -275,6 +278,9 @@ typedef struct
time_t users_refresh_time; /**< How often the users can be refreshed */
uint64_t writeq_high_water; /**< High water mark of dcb write queue */
uint64_t writeq_low_water; /**< Low water mark of dcb write queue */
char peer_hosts[MAX_ADMIN_HOST_LEN]; /**< The protocol, address and port for peers (currently only one) */
char peer_user[MAX_ADMIN_HOST_LEN]; /**< Username for maxscale-to-maxscale traffic */
char peer_password[MAX_ADMIN_HOST_LEN]; /**< Password for maxscale-to-maxscale traffic */
} MXS_CONFIG;
/**

View File

@ -339,17 +339,15 @@ MXS_MONITOR_API MonitorApi<MonitorInstance>::s_api =
};
/**
* Get the master server of the monitor pointed by @c url
* Get the master server of the remote monitor
*
* The URL must be in `http://hostname-of-maxscale:<rest-api-port>/v1/monitors/<name-of-monitor>`
* format and must point to a single monitor resource.
* The `peer_hosts`, `peer_user` and `peer_password` parameters must have been defined for this
* to work.
*
* TODO: Move the base URL and credentials into a global parameter
*
* @param url URL to a REST API endpoint for a monitor
* @param name The name of the remote monitor
*
* @return The host and port of the monitor or an empty string and 0 if an error occurred
*/
std::pair<std::string, int> mon_get_external_master(const std::string& url);
std::pair<std::string, int> mon_get_external_master(const std::string& name);
}

View File

@ -662,10 +662,12 @@ struct Result
* Do a HTTP GET
*
* @param url URL to use
* @param user Username to use, optional
* @param passwor Password for the user, optional
*
* @return A Result
*/
Result get(const std::string& url);
Result get(const std::string& url, const std::string& user = "", const std::string& password = "");
}