Skip to content

Commit

Permalink
Added update_baseurl() function to programmatically update the base U…
Browse files Browse the repository at this point in the history
…RL (#7173)

* Added update_baseurl() function to programmatically update the base URL in App
* Fix querying of the base url to use metadata if it exists
* Updated location updates to match scope document
* Make sure app route is set up before configure()
* Removed AppResponse and other cleanup
* Fixed minor issue in c_api with get_base_url()
* Added tests for base url - minor fixes found from tests
* Updates from review - removed usage of App Metadata in App and reverted App Metadata changes - updated/added tests
* Updates from review - minor update to update_base_url api to allow resetting to default base url
* Updates from review - moved location update checking to response from updating the access token - added more unit tests
* Fixed object store tests compile failures in app.cpp if REALM_ENABLE_AUTH_TESTS was not enabled
* Added CAPI function to set the default base URL
* Updates from review - clang-format
* Updates from review - Updated CAPI and added additional tests
* Fix app streaming test after changing location url
* Simplify test code and release user object
  • Loading branch information
Michael Wilkerson-Barker authored Jan 22, 2024
1 parent 080108a commit 8c425b3
Show file tree
Hide file tree
Showing 22 changed files with 1,677 additions and 500 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

### Enhancements
* <New feature description> (PR [#????](https://github.com/realm/realm-core/pull/????))
* None.
* Added change_base_url() function to update the App base URL at runtime. (PR [#7173](https://github.com/realm/realm-core/pull/7173))
* Sync Client should use the base_url value provided in App::Config instead of always using stored info after first connection to server. ([#7201](https://github.com/realm/realm-core/issues/7201))

### Fixed
* <How do the end-user experience this issue? what was the impact?> ([#????](https://github.com/realm/realm-core/issues/????), since v?.?.?)
* Handle `EOPNOTSUPP` when using `posix_fallocate()` and fallback to manually consume space. This should enable android users to open a Realm on restrictive filesystems. ([realm-js #6349](https://github.com/realm/realm-js/issues/6349), more prevalent since v13.23.3 with the change to `REALM_HAVE_POSIX_FALLOCATE` but it was also an issue in some platforms before this)
* Application may crash with `incoming_changesets.size() != 0` when a download message is mistaken for a bootstrap message. This can happen if the synchronization session is paused and resumed at a specific time. (PR [#7238](https://github.com/realm/realm-core/pull/7238), since v11.8.0)
* Fixed errors complaining about missing symbols such as `__atomic_is_lock_free` on ARMv7 Linux. (PR [#7257](https://github.com/realm/realm-core/pull/7257))
Expand Down
2 changes: 2 additions & 0 deletions bindgen/spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,8 @@ classes:
unsubscribe: '(token: AppSubscriptionToken)'
call_function: '(user: const SharedSyncUser&, name: std::string, args: EJsonArray, service_name: util::Optional<std::string>, cb: AsyncCallback<(result: Nullable<const EJson*>, err: util::Optional<AppError>)>)'
make_streaming_request: '(user: SharedSyncUser, name: std::string, args: bson::BsonArray, service_name: util::Optional<std::string>) -> Request'
update_base_url: '(base_url: std::optional<std::string>, cb: AsyncCallback<(err: util::Optional<AppError>)>&&)'
get_base_url: '() const -> std::string'

WatchStream:
cppName: app::WatchStream
Expand Down
6 changes: 2 additions & 4 deletions evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ functions:
if [[ -n "${verbose_test_output}" ]]; then
TEST_FLAGS="$TEST_FLAGS -VV"
export UNITTEST_THREADS=1
export UNITTEST_LOG_LEVEL="${test_logging_level|debug}"
else
TEST_FLAGS="$TEST_FLAGS -V"
fi
Expand Down Expand Up @@ -259,9 +261,6 @@ functions:
rm "$UNITTEST_EVERGREEN_TEST_RESULTS"
fi
export UNITTEST_PROGRESS=1
if [[ -n "${report_test_progress|}" ]]; then
export UNITTEST_PROGRESS="${report_test_progress|}"
fi
if [[ -n "${run_with_encryption}" ]]; then
export UNITTEST_ENCRYPT_ALL=1
Expand Down Expand Up @@ -904,7 +903,6 @@ tasks:
- func: "run tests"
vars:
test_filter: CoreTests
report_test_progress: On

- name: core-tests
tags: [ "test_suite", "for_pull_requests" ]
Expand Down
30 changes: 30 additions & 0 deletions src/realm.h
Original file line number Diff line number Diff line change
Expand Up @@ -2939,6 +2939,36 @@ RLM_API void realm_clear_cached_apps(void) RLM_API_NOEXCEPT;
RLM_API const char* realm_app_get_app_id(const realm_app_t*) RLM_API_NOEXCEPT;
RLM_API realm_user_t* realm_app_get_current_user(const realm_app_t*) RLM_API_NOEXCEPT;

/**
* Update the URL used to communicate with the Realm server. This function will update the location
* information used for http and websocket requests to the server. Once this operation has completed,
* the new base_url value returned by realm_app_get_base_url() will match the base_url value provided
* to this function. Any App requests performed while the base URl update is currently in progress
* will continue to use the original base URL value.
*
* @param app ptr to realm_app
* @param base_url The new base URL value to set as the Realm server URL - a null or empty string will
* use the default base URL value
* @param callback invoked once operation has completed
* @return True if no error has been recorded, False otherwise
*/
RLM_API bool realm_app_update_base_url(realm_app_t* app, const char* base_url,
realm_app_void_completion_func_t callback, realm_userdata_t userdata,
realm_free_userdata_func_t userdata_free);

/**
* Return the current base URL value used by the app. If the realm_app_update_base_url() is called, this
* value will match the base_url value provided to that function when the update is complete. The value
* provided by this function is undefined if the realm_app_update_base_url() operation is in progress,
* since it will likely be the base_url value prior to realm_app_update_base_url() being called.
*
* @param app ptr to realm_app
* @return The current base URL string used by the app
*
* Return value must be manually released with realm_free().
*/
RLM_API char* realm_app_get_base_url(realm_app_t* app) RLM_API_NOEXCEPT;

/**
* Get the list of active users in this @a app.
* In case of errors this function will return false (errors to be fetched via `realm_get_last_error()`).
Expand Down
14 changes: 14 additions & 0 deletions src/realm/exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,20 @@ struct InvalidQueryArgError : InvalidArgument {
};

} // namespace query_parser

namespace sync {

// Exception thrown when the request/websocket URL is malformed
class BadServerUrl : public Exception {
public:
BadServerUrl(std::string_view url)
: Exception(ErrorCodes::BadServerUrl, util::format("Unable to parse server URL '%1'", url))
{
}
};

} // namespace sync

} // namespace realm

#endif // REALM_EXCEPTIONS_HPP
20 changes: 20 additions & 0 deletions src/realm/object-store/c_api/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,26 @@ RLM_API const char* realm_app_get_app_id(const realm_app_t* app) noexcept
return (*app)->config().app_id.c_str();
}

RLM_API bool realm_app_update_base_url(realm_app_t* app, const char* base_url,
realm_app_void_completion_func_t callback, realm_userdata_t userdata,
realm_free_userdata_func_t userdata_free)
{
std::optional<std::string> new_base_url;
if (base_url) {
new_base_url = base_url;
}
return wrap_err([&] {
(*app)->update_base_url(new_base_url, make_callback(callback, userdata, userdata_free));
return true;
});
}

RLM_API char* realm_app_get_base_url(realm_app_t* app) noexcept
{
auto url_stg = (*app)->get_base_url();
return duplicate_string(url_stg);
}

RLM_API realm_user_t* realm_app_get_current_user(const realm_app_t* app) noexcept
{
if (auto user = (*app)->current_user()) {
Expand Down
Loading

0 comments on commit 8c425b3

Please sign in to comment.