-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathadc.go
35 lines (31 loc) · 1.06 KB
/
adc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package util
import (
"log"
"net/http"
"net/url"
"strings"
)
// Return cookie header and value
func ADCCookieHeader(cookieRequestUrl string) string {
resp, err := http.Get(cookieRequestUrl)
if err != nil {
// TODO: pass this error back
log.Fatal(err)
}
// naively assuming we have a single Set-Cookie and no problem scanning for the cookie name,
// no error-checking here yet!
header := resp.Header["Set-Cookie"][0]
firstSegment, _, _ := strings.Cut(header, ";")
_, valueOnly, _ := strings.Cut(firstSegment, "ADCDownloadAuth=")
return valueOnly
}
// Given an ADC download URL that requires authentication, return the /services/download
// service URL we can use to retrieve the needed auth header for that ADC download URL
// i.e. https://developerservices2.apple.com/services/download?path=/path/to/the.dmg
func AppleDownloadServicesURL(adcUrl string) string {
newUrl := "https://developerservices2.apple.com/services/download?path="
// blindly assuming Apple's URLs are well-formed
adcUrlPath, _ := url.Parse(adcUrl)
newUrl += adcUrlPath.Path
return newUrl
}