Add get_simple_config_firebase_firestore.

GitOrigin-RevId: 2c89f7667148f601d16aba01068ebb4f74bd12f8
This commit is contained in:
levlam 2019-11-19 19:26:39 +03:00
parent 4ce54818a3
commit 110b3d5832
3 changed files with 31 additions and 3 deletions

View File

@ -252,7 +252,7 @@ static ActorOwn<> get_simple_config_dns(Slice address, Slice host, Promise<Simpl
auto get_config = [](HttpQuery &http_query) -> Result<string> { auto get_config = [](HttpQuery &http_query) -> Result<string> {
TRY_RESULT(json, json_decode(http_query.content_)); TRY_RESULT(json, json_decode(http_query.content_));
if (json.type() != JsonValue::Type::Object) { if (json.type() != JsonValue::Type::Object) {
return Status::Error("JSON error"); return Status::Error("Expected JSON object");
} }
auto &answer_object = json.get_object(); auto &answer_object = json.get_object();
TRY_RESULT(answer, get_json_object_field(answer_object, "Answer", JsonValue::Type::Array, false)); TRY_RESULT(answer, get_json_object_field(answer_object, "Answer", JsonValue::Type::Array, false));
@ -260,7 +260,7 @@ static ActorOwn<> get_simple_config_dns(Slice address, Slice host, Promise<Simpl
vector<string> parts; vector<string> parts;
for (auto &v : answer_array) { for (auto &v : answer_array) {
if (v.type() != JsonValue::Type::Object) { if (v.type() != JsonValue::Type::Object) {
return Status::Error("JSON error"); return Status::Error("Expected JSON object");
} }
auto &data_object = v.get_object(); auto &data_object = v.get_object();
TRY_RESULT(part, get_json_object_string_field(data_object, "data", false)); TRY_RESULT(part, get_json_object_string_field(data_object, "data", false));
@ -320,7 +320,7 @@ ActorOwn<> get_simple_config_firebase_remote_config(Promise<SimpleConfigResult>
auto get_config = [](HttpQuery &http_query) -> Result<string> { auto get_config = [](HttpQuery &http_query) -> Result<string> {
TRY_RESULT(json, json_decode(http_query.get_arg("entries"))); TRY_RESULT(json, json_decode(http_query.get_arg("entries")));
if (json.type() != JsonValue::Type::Object) { if (json.type() != JsonValue::Type::Object) {
return Status::Error("JSON error"); return Status::Error("Expected JSON object");
} }
auto &entries_object = json.get_object(); auto &entries_object = json.get_object();
TRY_RESULT(config, get_json_object_string_field(entries_object, "ipconfigv3", false)); TRY_RESULT(config, get_json_object_string_field(entries_object, "ipconfigv3", false));
@ -346,6 +346,28 @@ ActorOwn<> get_simple_config_firebase_realtime(Promise<SimpleConfigResult> promi
prefer_ipv6, std::move(get_config)); prefer_ipv6, std::move(get_config));
} }
ActorOwn<> get_simple_config_firebase_firestore(Promise<SimpleConfigResult> promise, const ConfigShared *shared_config,
bool is_test, int32 scheduler_id) {
if (is_test) {
promise.set_error(Status::Error(400, "Test config is not supported"));
return ActorOwn<>();
}
string url = "https://www.google.com/v1/projects/reserve-5a846/databases/(default)/documents/ipconfig/v3";
const bool prefer_ipv6 = shared_config == nullptr ? false : shared_config->get_option_boolean("prefer_ipv6");
auto get_config = [](HttpQuery &http_query) -> Result<string> {
TRY_RESULT(json, json_decode(http_query.get_arg("fields")));
if (json.type() != JsonValue::Type::Object) {
return Status::Error("Expected JSON object");
}
TRY_RESULT(data, get_json_object_field(json.get_object(), "data", JsonValue::Type::Object, false));
TRY_RESULT(config, get_json_object_string_field(data.get_object(), "stringValue", false));
return std::move(config);
};
return get_simple_config_impl(std::move(promise), scheduler_id, std::move(url), "firestore.googleapis.com", {},
prefer_ipv6, std::move(get_config));
}
ActorOwn<> get_full_config(DcOption option, Promise<FullConfig> promise, ActorShared<> parent) { ActorOwn<> get_full_config(DcOption option, Promise<FullConfig> promise, ActorShared<> parent) {
class SessionCallback : public Session::Callback { class SessionCallback : public Session::Callback {
public: public:
@ -773,6 +795,8 @@ class ConfigRecoverer : public Actor {
return get_simple_config_firebase_remote_config; return get_simple_config_firebase_remote_config;
case 4: case 4:
return get_simple_config_firebase_realtime; return get_simple_config_firebase_realtime;
case 5:
return get_simple_config_firebase_firestore;
case 0: case 0:
return get_simple_config_google_dns; return get_simple_config_google_dns;
case 1: case 1:

View File

@ -51,6 +51,9 @@ ActorOwn<> get_simple_config_firebase_remote_config(Promise<SimpleConfigResult>
ActorOwn<> get_simple_config_firebase_realtime(Promise<SimpleConfigResult> promise, const ConfigShared *shared_config, ActorOwn<> get_simple_config_firebase_realtime(Promise<SimpleConfigResult> promise, const ConfigShared *shared_config,
bool is_test, int32 scheduler_id); bool is_test, int32 scheduler_id);
ActorOwn<> get_simple_config_firebase_firestore(Promise<SimpleConfigResult> promise, const ConfigShared *shared_config,
bool is_test, int32 scheduler_id);
class HttpDate { class HttpDate {
static bool is_leap(int32 year) { static bool is_leap(int32 year) {
return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0); return year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);

View File

@ -172,6 +172,7 @@ TEST(Mtproto, config) {
run(get_simple_config_mozilla_dns, true); run(get_simple_config_mozilla_dns, true);
run(get_simple_config_firebase_remote_config, false); run(get_simple_config_firebase_remote_config, false);
run(get_simple_config_firebase_realtime, false); run(get_simple_config_firebase_realtime, false);
run(get_simple_config_firebase_firestore, false);
} }
cnt--; cnt--;
sched.start(); sched.start();