-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathworker_status_linux.go
110 lines (91 loc) · 3.54 KB
/
worker_status_linux.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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package main
import (
"fmt"
"time"
"github.com/pkg/errors"
"howett.net/plist"
)
const (
iTunesSoftwareServiceURL = "https://contentdelivery.itunes.apple.com/WebObjects/MZLabelService.woa/json/MZITunesSoftwareService"
iTunesProducerServiceURL = "https://contentdelivery.itunes.apple.com/WebObjects/MZLabelService.woa/json/MZITunesProducerService"
)
type devInfoRequestStatus int
const (
devInfoRequestStatusInvalid devInfoRequestStatus = -2
devInfoRequestStatusSuccess devInfoRequestStatus = 0
devInfoRequestStatusInProgress devInfoRequestStatus = 1
)
var devInfoRequestStatusToString = map[devInfoRequestStatus]string{
devInfoRequestStatusSuccess: "success",
devInfoRequestStatusInProgress: "in progress",
devInfoRequestStatusInvalid: "invalid",
}
func (code devInfoRequestStatus) String() string {
if value, exists := devInfoRequestStatusToString[code]; exists {
return value
}
return fmt.Sprintf("unknown(%d)", code)
}
type tokenRequest struct {
Application string `json:"Application"`
ApplicationBundleId string `json:"ApplicationBundleId"`
Username string `json:"Username"`
Password string `json:"Password"`
}
type tokenResponse struct {
DSTokenCookieName string `json:"DSTokenCookieName"`
DSToken string `json:"DSToken"`
}
type devInfoRequest struct {
Application string `json:"Application"`
ApplicationBundleId string `json:"ApplicationBundleId"`
DsPlist string `json:"DS_PLIST"`
RequestUUID string `json:"RequestUUID"`
}
type devInfoResponse struct {
DevIDPlus struct {
LogFileURL string `json:"LogFileURL"`
MoreInfo struct {
Hash string `json:"Hash"`
} `json:"MoreInfo"`
DateStr string `json:"DateStr"`
StatusCode int `json:"StatusCode"`
RequestStatus devInfoRequestStatus `json:"RequestStatus"`
StatusMessage string `json:"StatusMessage"`
} `json:"DevIDPlus"`
}
func (worker *Worker) getNotarizationStatus(upload *NotarizationUpload) (*NotarizationInfo, error) {
var tokenResp tokenResponse
tokenReq := &tokenRequest{
Application: "notarization-helper",
ApplicationBundleId: "au.id.haworth.NotarizationHelper",
Username: worker.config.Username,
Password: worker.config.Password,
}
if err := worker.jsonRpcSendRequest(iTunesSoftwareServiceURL, "generateAppleConnectToken", tokenReq, &tokenResp); err != nil {
return nil, errors.Wrap(err, "authenticate with Apple")
}
dsPlist, err := plist.Marshal(map[string]string{tokenResp.DSTokenCookieName: tokenResp.DSToken}, plist.XMLFormat)
if err != nil {
return nil, errors.Wrap(err, "generate plist from authentication token")
}
var devInfoResp devInfoResponse
devInfoReq := &devInfoRequest{
Application: "notarization-helper",
ApplicationBundleId: "au.id.haworth.NotarizationHelper",
DsPlist: string(dsPlist),
RequestUUID: upload.RequestUUID,
}
if err := worker.jsonRpcSendRequest(iTunesProducerServiceURL, "developerIDPlusInfoForPackageWithArguments", devInfoReq, &devInfoResp); err != nil {
return nil, errors.Wrap(err, "authenticate with Apple")
}
info := new(NotarizationInfo)
info.Date, _ = time.Parse(time.RFC3339, devInfoResp.DevIDPlus.DateStr)
info.LogFileURL = devInfoResp.DevIDPlus.LogFileURL
info.Hash = devInfoResp.DevIDPlus.MoreInfo.Hash
info.RequestUUID = upload.RequestUUID
info.Status = devInfoResp.DevIDPlus.RequestStatus.String()
info.StatusCode = devInfoResp.DevIDPlus.StatusCode
info.StatusMessage = devInfoResp.DevIDPlus.StatusMessage
return info, nil
}