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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
use {
crate::{AppStoreConnectClient, Result},
serde::{Deserialize, Serialize},
serde_json::Value,
thiserror::Error,
};
pub const APPLE_NOTARY_SUBMIT_SOFTWARE_URL: &str =
"https://appstoreconnect.apple.com/notary/v2/submissions";
#[derive(Clone, Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct NewSubmissionRequestNotification {
pub channel: String,
pub target: String,
}
#[derive(Clone, Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct NewSubmissionRequest {
pub notifications: Vec<NewSubmissionRequestNotification>,
pub sha256: String,
pub submission_name: String,
}
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NewSubmissionResponseDataAttributes {
pub aws_access_key_id: String,
pub aws_secret_access_key: String,
pub aws_session_token: String,
pub bucket: String,
pub object: String,
}
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NewSubmissionResponseData {
pub attributes: NewSubmissionResponseDataAttributes,
pub id: String,
pub r#type: String,
}
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct NewSubmissionResponse {
pub data: NewSubmissionResponseData,
pub meta: Value,
}
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "PascalCase")]
pub enum SubmissionResponseStatus {
Accepted,
#[serde(rename = "In Progress")]
InProgress,
Invalid,
Rejected,
#[serde(other)]
Unknown,
}
impl std::fmt::Display for SubmissionResponseStatus {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
let s = match self {
Self::Accepted => "accepted",
Self::InProgress => "in progress",
Self::Invalid => "invalid",
Self::Rejected => "rejected",
Self::Unknown => "unknown",
};
f.write_str(s)
}
}
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SubmissionResponseDataAttributes {
pub created_date: String,
pub name: String,
pub status: SubmissionResponseStatus,
}
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SubmissionResponseData {
pub attributes: SubmissionResponseDataAttributes,
pub id: String,
pub r#type: String,
}
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SubmissionResponse {
pub data: SubmissionResponseData,
pub meta: Value,
}
impl SubmissionResponse {
pub fn into_result(self) -> Result<Self> {
match self.data.attributes.status {
SubmissionResponseStatus::Accepted => Ok(self),
status => Err(NotarizationError(status).into()),
}
}
}
#[derive(Clone, Copy, Debug, Error)]
#[error("notarization {0}")]
pub struct NotarizationError(SubmissionResponseStatus);
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SubmissionLogResponseDataAttributes {
pub developer_log_url: String,
}
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SubmissionLogResponseData {
pub attributes: SubmissionLogResponseDataAttributes,
pub id: String,
pub r#type: String,
}
#[derive(Clone, Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct SubmissionLogResponse {
pub data: SubmissionLogResponseData,
pub meta: Value,
}
impl AppStoreConnectClient {
pub fn create_submission(
&self,
sha256: &str,
submission_name: &str,
) -> Result<NewSubmissionResponse> {
let token = self.get_token()?;
let body = NewSubmissionRequest {
notifications: Vec::new(),
sha256: sha256.to_string(),
submission_name: submission_name.to_string(),
};
let req = self
.client
.post(APPLE_NOTARY_SUBMIT_SOFTWARE_URL)
.bearer_auth(token)
.header("Accept", "application/json")
.header("Content-Type", "application/json")
.json(&body);
Ok(self.send_request(req)?.json()?)
}
pub fn get_submission(&self, submission_id: &str) -> Result<SubmissionResponse> {
let token = self.get_token()?;
let req = self
.client
.get(format!(
"{APPLE_NOTARY_SUBMIT_SOFTWARE_URL}/{submission_id}"
))
.bearer_auth(token)
.header("Accept", "application/json");
Ok(self.send_request(req)?.json()?)
}
pub fn get_submission_log(&self, submission_id: &str) -> Result<Value> {
let token = self.get_token()?;
let req = self
.client
.get(format!(
"{APPLE_NOTARY_SUBMIT_SOFTWARE_URL}/{submission_id}/logs"
))
.bearer_auth(token)
.header("Accept", "application/json");
let res: SubmissionLogResponse = self.send_request(req)?.json()?;
let url = res.data.attributes.developer_log_url;
let logs = self.client.get(url).send()?.json::<Value>()?;
Ok(logs)
}
}