Skip to content

Commit 7ffd4bf

Browse files
committed
Use custom pod when applicable in download, get-version-metadata and list-versions APIs
1 parent 496595a commit 7ffd4bf

7 files changed

Lines changed: 112 additions & 14 deletions

pkg/appstore/appstore_download.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,6 @@ func (t *appstore) downloadFile(src, dst string, progress *progressbar.ProgressB
168168
}
169169

170170
func (*appstore) downloadRequest(acc Account, app App, guid string, externalVersionID string) http.Request {
171-
host := fmt.Sprintf("%s-%s", PrivateAppStoreAPIDomainPrefixWithoutAuthCode, PrivateAppStoreAPIDomain)
172-
173171
payload := map[string]interface{}{
174172
"creditDisplay": "",
175173
"guid": guid,
@@ -180,8 +178,13 @@ func (*appstore) downloadRequest(acc Account, app App, guid string, externalVers
180178
payload["externalVersionId"] = externalVersionID
181179
}
182180

181+
podPrefix := ""
182+
if acc.Pod != "" {
183+
podPrefix = "p" + acc.Pod + "-"
184+
}
185+
183186
return http.Request{
184-
URL: fmt.Sprintf("https://%s%s?guid=%s", host, PrivateAppStoreAPIPathDownload, guid),
187+
URL: fmt.Sprintf("https://%s%s%s?guid=%s", podPrefix, PrivateAppStoreAPIDomain, PrivateAppStoreAPIPathDownload, guid),
185188
Method: http.MethodPOST,
186189
ResponseFormat: http.ResponseFormatXML,
187190
Headers: map[string]string{

pkg/appstore/appstore_download_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,36 @@ var _ = Describe("AppStore (Download)", func() {
9797
})
9898
})
9999

100+
When("request uses a custom pod", func() {
101+
const (
102+
testPod = "42"
103+
testGUID = "001122334455"
104+
)
105+
106+
BeforeEach(func() {
107+
mockMachine.EXPECT().
108+
MacAddress().
109+
Return("00:11:22:33:44:55", nil)
110+
111+
mockDownloadClient.EXPECT().
112+
Send(gomock.Any()).
113+
Do(func(req http.Request) {
114+
expectedURL := "https://p" + testPod + "-" + PrivateAppStoreAPIDomain + PrivateAppStoreAPIPathDownload + "?guid=" + testGUID
115+
Expect(req.URL).To(Equal(expectedURL))
116+
}).
117+
Return(http.Result[downloadResult]{}, errors.New(""))
118+
})
119+
120+
It("sends the download request to the pod-specific host", func() {
121+
_, err := as.Download(DownloadInput{
122+
Account: Account{
123+
Pod: testPod,
124+
},
125+
})
126+
Expect(err).To(HaveOccurred())
127+
})
128+
})
129+
100130
When("password token is expired", func() {
101131
BeforeEach(func() {
102132
mockMachine.EXPECT().

pkg/appstore/appstore_get_version_metadata.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,20 @@ func (t *appstore) GetVersionMetadata(input GetVersionMetadataInput) (GetVersion
6969
}
7070

7171
func (t *appstore) getVersionMetadataRequest(acc Account, app App, guid string, version string) http.Request {
72-
host := fmt.Sprintf("%s-%s", PrivateAppStoreAPIDomainPrefixWithoutAuthCode, PrivateAppStoreAPIDomain)
73-
7472
payload := map[string]interface{}{
7573
"creditDisplay": "",
7674
"guid": guid,
7775
"salableAdamId": app.ID,
7876
"externalVersionId": version,
7977
}
8078

79+
podPrefix := ""
80+
if acc.Pod != "" {
81+
podPrefix = "p" + acc.Pod + "-"
82+
}
83+
8184
return http.Request{
82-
URL: fmt.Sprintf("https://%s%s?guid=%s", host, PrivateAppStoreAPIPathDownload, guid),
85+
URL: fmt.Sprintf("https://%s%s%s?guid=%s", podPrefix, PrivateAppStoreAPIDomain, PrivateAppStoreAPIPathDownload, guid),
8386
Method: http.MethodPOST,
8487
ResponseFormat: http.ResponseFormatXML,
8588
Headers: map[string]string{

pkg/appstore/appstore_get_version_metadata_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,37 @@ var _ = Describe("AppStore (GetVersionMetadata)", func() {
6565
})
6666
})
6767

68+
When("request uses a custom pod", func() {
69+
const (
70+
testPod = "42"
71+
testGUID = "001122334455"
72+
)
73+
74+
BeforeEach(func() {
75+
mockMachine.EXPECT().
76+
MacAddress().
77+
Return("00:11:22:33:44:55", nil)
78+
79+
mockDownloadClient.EXPECT().
80+
Send(gomock.Any()).
81+
Do(func(req http.Request) {
82+
expectedURL := "https://p" + testPod + "-" + PrivateAppStoreAPIDomain + PrivateAppStoreAPIPathDownload + "?guid=" + testGUID
83+
Expect(req.URL).To(Equal(expectedURL))
84+
}).
85+
Return(http.Result[downloadResult]{}, errors.New("request error"))
86+
})
87+
88+
It("sends the request to the pod-specific host", func() {
89+
_, err := as.GetVersionMetadata(GetVersionMetadataInput{
90+
Account: Account{
91+
Pod: testPod,
92+
},
93+
})
94+
Expect(err).To(HaveOccurred())
95+
Expect(err.Error()).To(ContainSubstring("failed to send http request"))
96+
})
97+
})
98+
6899
When("password token is expired", func() {
69100
BeforeEach(func() {
70101
mockMachine.EXPECT().

pkg/appstore/appstore_list_versions.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,19 @@ func (t *appstore) ListVersions(input ListVersionsInput) (ListVersionsOutput, er
7777
}
7878

7979
func (t *appstore) listVersionsRequest(acc Account, app App, guid string) http.Request {
80-
host := fmt.Sprintf("%s-%s", PrivateAppStoreAPIDomainPrefixWithoutAuthCode, PrivateAppStoreAPIDomain)
81-
8280
payload := map[string]interface{}{
8381
"creditDisplay": "",
8482
"guid": guid,
8583
"salableAdamId": app.ID,
8684
}
8785

86+
podPrefix := ""
87+
if acc.Pod != "" {
88+
podPrefix = "p" + acc.Pod + "-"
89+
}
90+
8891
return http.Request{
89-
URL: fmt.Sprintf("https://%s%s?guid=%s", host, PrivateAppStoreAPIPathDownload, guid),
92+
URL: fmt.Sprintf("https://%s%s%s?guid=%s", podPrefix, PrivateAppStoreAPIDomain, PrivateAppStoreAPIPathDownload, guid),
9093
Method: http.MethodPOST,
9194
ResponseFormat: http.ResponseFormatXML,
9295
Headers: map[string]string{

pkg/appstore/appstore_list_versions_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,36 @@ var _ = Describe("AppStore (ListVersions)", func() {
6262
})
6363
})
6464

65+
When("request uses a custom pod", func() {
66+
const (
67+
testPod = "42"
68+
testGUID = "001122334455"
69+
)
70+
71+
BeforeEach(func() {
72+
mockMachine.EXPECT().
73+
MacAddress().
74+
Return("00:11:22:33:44:55", nil)
75+
76+
mockDownloadClient.EXPECT().
77+
Send(gomock.Any()).
78+
Do(func(req http.Request) {
79+
expectedURL := "https://p" + testPod + "-" + PrivateAppStoreAPIDomain + PrivateAppStoreAPIPathDownload + "?guid=" + testGUID
80+
Expect(req.URL).To(Equal(expectedURL))
81+
}).
82+
Return(http.Result[downloadResult]{}, errors.New(""))
83+
})
84+
85+
It("sends the request to the pod-specific host", func() {
86+
_, err := as.ListVersions(ListVersionsInput{
87+
Account: Account{
88+
Pod: testPod,
89+
},
90+
})
91+
Expect(err).To(HaveOccurred())
92+
})
93+
})
94+
6595
When("password token is expired", func() {
6696
BeforeEach(func() {
6797
mockMachine.EXPECT().

pkg/appstore/constants.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ const (
1717
PrivateInitDomain = "init." + iTunesAPIDomain
1818
PrivateInitPath = "/bag.xml"
1919

20-
PrivateAppStoreAPIDomainPrefixWithoutAuthCode = "p25"
21-
PrivateAppStoreAPIDomainPrefixWithAuthCode = "p71"
22-
PrivateAppStoreAPIDomain = "buy." + iTunesAPIDomain
23-
PrivateAppStoreAPIPathPurchase = "/WebObjects/MZFinance.woa/wa/buyProduct"
24-
PrivateAppStoreAPIPathDownload = "/WebObjects/MZFinance.woa/wa/volumeStoreDownloadProduct"
20+
PrivateAppStoreAPIDomain = "buy." + iTunesAPIDomain
21+
PrivateAppStoreAPIPathPurchase = "/WebObjects/MZFinance.woa/wa/buyProduct"
22+
PrivateAppStoreAPIPathDownload = "/WebObjects/MZFinance.woa/wa/volumeStoreDownloadProduct"
2523

2624
HTTPHeaderStoreFront = "X-Set-Apple-Store-Front"
2725
HTTPHeaderPod = "pod"

0 commit comments

Comments
 (0)