-
Notifications
You must be signed in to change notification settings - Fork 906
Expand file tree
/
Copy pathappstore_bag.go
More file actions
66 lines (52 loc) · 1.47 KB
/
Copy pathappstore_bag.go
File metadata and controls
66 lines (52 loc) · 1.47 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package appstore
import (
"fmt"
gohttp "net/http"
"strings"
"github.com/majd/ipatool/v2/pkg/http"
)
type BagInput struct{}
type BagOutput struct {
AuthEndpoint string
}
func (t *appstore) Bag(input BagInput) (BagOutput, error) {
macAddr, err := t.machine.MacAddress()
if err != nil {
return BagOutput{}, fmt.Errorf("failed to get mac address: %w", err)
}
guid := strings.ReplaceAll(strings.ToUpper(macAddr), ":", "")
req := t.bagRequest(guid)
res, err := t.bagClient.Send(req)
if err != nil {
return BagOutput{}, fmt.Errorf("failed to send http request: %w", err)
}
if res.StatusCode != gohttp.StatusOK {
return BagOutput{}, fmt.Errorf("received unexpected status code: %d", res.StatusCode)
}
return BagOutput{
AuthEndpoint: res.Data.AuthEndpoint(),
}, nil
}
type bagResult struct {
AuthenticateAccount string `plist:"authenticateAccount,omitempty"`
URLBag urlBag `plist:"urlBag,omitempty"`
}
type urlBag struct {
AuthEndpoint string `plist:"authenticateAccount,omitempty"`
}
func (r bagResult) AuthEndpoint() string {
if r.AuthenticateAccount != "" {
return r.AuthenticateAccount
}
return r.URLBag.AuthEndpoint
}
func (*appstore) bagRequest(guid string) http.Request {
return http.Request{
URL: fmt.Sprintf("https://%s%s?ix=6&guid=%s", PrivateInitDomain, PrivateInitPath, guid),
Method: http.MethodGET,
ResponseFormat: http.ResponseFormatXML,
Headers: map[string]string{
"Accept": "application/xml",
},
}
}