Skip to content

Commit dfc6acb

Browse files
committed
Use AndroidBuildUrl as a constructor parameter
Avoids passing multiple strings into `AndroidBuildApi` in favor of a semantic object. Also, include some dependencies used/referenced in `downloaders.cc`.
1 parent a6278a9 commit dfc6acb

4 files changed

Lines changed: 22 additions & 16 deletions

File tree

base/cvd/cuttlefish/host/commands/cvd/fetch/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ cf_cc_library(
7272
"//cuttlefish/common/libs/utils:result",
7373
"//cuttlefish/host/commands/cvd/fetch:fetch_cvd_parser",
7474
"//cuttlefish/host/commands/cvd/utils:common",
75+
"//cuttlefish/host/libs/web:android_build_api",
76+
"//cuttlefish/host/libs/web:android_build_url",
7577
"//cuttlefish/host/libs/web:build_api",
7678
"//cuttlefish/host/libs/web:caching_build_api",
7779
"//cuttlefish/host/libs/web:credential_source",

base/cvd/cuttlefish/host/commands/cvd/fetch/downloaders.cc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#include "cuttlefish/common/libs/utils/result.h"
2323
#include "cuttlefish/host/commands/cvd/fetch/fetch_cvd_parser.h"
2424
#include "cuttlefish/host/commands/cvd/utils/common.h"
25+
#include "cuttlefish/host/libs/web/android_build_api.h"
26+
#include "cuttlefish/host/libs/web/android_build_url.h"
27+
#include "cuttlefish/host/libs/web/build_api.h"
2528
#include "cuttlefish/host/libs/web/caching_build_api.h"
2629
#include "cuttlefish/host/libs/web/credential_source.h"
2730
#include "cuttlefish/host/libs/web/http_client/curl_http_client.h"
@@ -49,6 +52,7 @@ struct Downloaders::Impl {
4952
std::unique_ptr<HttpClient> curl_;
5053
std::unique_ptr<HttpClient> retrying_http_client_;
5154
std::unique_ptr<CredentialSource> android_creds_;
55+
std::unique_ptr<AndroidBuildUrl> android_build_url_;
5256
std::unique_ptr<CasDownloader> cas_downloader_;
5357
std::unique_ptr<AndroidBuildApi> android_build_api_;
5458
std::unique_ptr<CachingBuildApi> caching_build_api_;
@@ -86,6 +90,9 @@ Result<Downloaders> Downloaders::Create(const BuildApiFlags& flags) {
8690
: CF_EXPECT(GetCredentialSourceFromFlags(*impl->retrying_http_client_,
8791
flags, oauth_filepath));
8892

93+
impl->android_build_url_ = std::make_unique<AndroidBuildUrl>(
94+
flags.api_base_url, flags.api_key, flags.project_id);
95+
8996
Result<std::unique_ptr<CasDownloader>> cas_downloader_result =
9097
CasDownloader::Create(flags.cas_downloader_flags,
9198
flags.credential_flags.service_account_filepath);
@@ -94,8 +101,8 @@ Result<Downloaders> Downloaders::Create(const BuildApiFlags& flags) {
94101
}
95102

96103
impl->android_build_api_ = std::make_unique<AndroidBuildApi>(
97-
*impl->retrying_http_client_, impl->android_creds_.get(), flags.api_key,
98-
flags.wait_retry_period, flags.api_base_url, flags.project_id,
104+
*impl->retrying_http_client_, impl->android_creds_.get(),
105+
impl->android_build_url_.get(), flags.wait_retry_period,
99106
impl->cas_downloader_.get());
100107

101108
const std::string cache_base_path = PerUserCacheDir();

base/cvd/cuttlefish/host/libs/web/android_build_api.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,12 @@ std::ostream& operator<<(std::ostream& out, const Build& build) {
101101

102102
AndroidBuildApi::AndroidBuildApi(HttpClient& http_client,
103103
CredentialSource* credential_source,
104-
std::string api_key,
104+
AndroidBuildUrl* android_build_url,
105105
const std::chrono::seconds retry_period,
106-
std::string api_base_url,
107-
std::string project_id,
108106
CasDownloader* cas_downloader)
109107
: http_client(http_client),
110108
credential_source(credential_source),
111-
android_build_url_(std::move(api_base_url), std::move(api_key),
112-
std::move(project_id)),
109+
android_build_url_(android_build_url),
113110
retry_period_(retry_period),
114111
cas_downloader_(cas_downloader) {}
115112

@@ -188,7 +185,7 @@ Result<std::vector<std::string>> AndroidBuildApi::Headers() {
188185
Result<std::optional<std::string>> AndroidBuildApi::LatestBuildId(
189186
const std::string& branch, const std::string& target) {
190187
const std::string url =
191-
android_build_url_.GetLatestBuildIdUrl(branch, target);
188+
android_build_url_->GetLatestBuildIdUrl(branch, target);
192189
auto response =
193190
CF_EXPECT(HttpGetToJson(http_client, url, CF_EXPECT(Headers())));
194191
const auto& json = response.data;
@@ -214,7 +211,7 @@ Result<std::optional<std::string>> AndroidBuildApi::LatestBuildId(
214211

215212
Result<std::string> AndroidBuildApi::BuildStatus(const DeviceBuild& build) {
216213
const std::string url =
217-
android_build_url_.GetBuildStatusUrl(build.id, build.target);
214+
android_build_url_->GetBuildStatusUrl(build.id, build.target);
218215
auto response =
219216
CF_EXPECT(HttpGetToJson(http_client, url, CF_EXPECT(Headers())));
220217
const auto& json = response.data;
@@ -231,7 +228,7 @@ Result<std::string> AndroidBuildApi::BuildStatus(const DeviceBuild& build) {
231228

232229
Result<std::string> AndroidBuildApi::ProductName(const DeviceBuild& build) {
233230
const std::string url =
234-
android_build_url_.GetProductNameUrl(build.id, build.target);
231+
android_build_url_->GetProductNameUrl(build.id, build.target);
235232
auto response =
236233
CF_EXPECT(HttpGetToJson(http_client, url, CF_EXPECT(Headers())));
237234
const auto& json = response.data;
@@ -252,7 +249,7 @@ Result<std::unordered_set<std::string>> AndroidBuildApi::Artifacts(
252249
std::string page_token = "";
253250
std::unordered_set<std::string> artifacts;
254251
do {
255-
const std::string url = android_build_url_.GetArtifactUrl(
252+
const std::string url = android_build_url_->GetArtifactUrl(
256253
build.id, build.target, artifact_filenames, page_token);
257254
auto response =
258255
CF_EXPECT(HttpGetToJson(http_client, url, CF_EXPECT(Headers())));
@@ -303,8 +300,8 @@ Result<std::unordered_set<std::string>> AndroidBuildApi::Artifacts(
303300
Result<std::string> AndroidBuildApi::GetArtifactDownloadUrl(
304301
const DeviceBuild& build, const std::string& artifact) {
305302
const std::string download_url_endpoint =
306-
android_build_url_.GetArtifactDownloadUrl(build.id, build.target,
307-
artifact);
303+
android_build_url_->GetArtifactDownloadUrl(build.id, build.target,
304+
artifact);
308305
auto response = CF_EXPECT(
309306
HttpGetToJson(http_client, download_url_endpoint, CF_EXPECT(Headers())));
310307
const auto& json = response.data;

base/cvd/cuttlefish/host/libs/web/android_build_api.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ class AndroidBuildApi : public BuildApi {
4242
AndroidBuildApi(AndroidBuildApi&&) = delete;
4343
virtual ~AndroidBuildApi() = default;
4444
AndroidBuildApi(HttpClient& http_client, CredentialSource* credential_source,
45-
std::string api_key, std::chrono::seconds retry_period,
46-
std::string api_base_url, std::string project_id,
45+
AndroidBuildUrl* android_build_url,
46+
std::chrono::seconds retry_period,
4747
CasDownloader* cas_downloader = nullptr);
4848

4949
Result<Build> GetBuild(const BuildString& build_string) override;
@@ -103,7 +103,7 @@ class AndroidBuildApi : public BuildApi {
103103

104104
HttpClient& http_client;
105105
CredentialSource* credential_source;
106-
AndroidBuildUrl android_build_url_;
106+
AndroidBuildUrl* android_build_url_;
107107
std::chrono::seconds retry_period_;
108108
CasDownloader* cas_downloader_;
109109
};

0 commit comments

Comments
 (0)