Skip to content

Commit 9ba97e6

Browse files
lucasfernog-crabnebulaindygreg
authored andcommitted
app-store-connect: add api to enable capability for a bundle ID
Closes #164.
1 parent e09f979 commit 9ba97e6

File tree

3 files changed

+97
-6
lines changed

3 files changed

+97
-6
lines changed

app-store-connect/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ Released on ReleaseDate.
88

99
* New APIs and CLI commands to: list capabilities with a bundle ID;
1010
list profiles associated with a bundle ID; get bundle ID associated with
11-
a profile; list certificates associated with a profile. (#164)
11+
a profile; list certificates associated with a profile; enable capacity
12+
for a bundle ID. (#164)
1213
* Added `IosDistribution` variant to `CertificateType` enum.
1314
* MSRV 1.70 -> 1.78.
1415
* `base64` 0.21 -> 0.22.

app-store-connect/src/bundle_api.rs

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use crate::{profile_api::ProfilesResponse, AppStoreConnectClient, Result};
88
use serde::{Deserialize, Serialize};
99

1010
const APPLE_BUNDLE_IDS_URL: &str = "https://api.appstoreconnect.apple.com/v1/bundleIds";
11+
const APPLE_BUNDLE_CAPABILITIES_URL: &str =
12+
"https://api.appstoreconnect.apple.com/v1/bundleIdCapabilities";
1113

1214
impl AppStoreConnectClient {
1315
pub fn register_bundle_id(&self, identifier: &str, name: &str) -> Result<BundleIdResponse> {
@@ -72,6 +74,38 @@ impl AppStoreConnectClient {
7274
Ok(self.send_request(req)?.json()?)
7375
}
7476

77+
pub fn enable_bundle_id_capability(
78+
&self,
79+
id: &str,
80+
capability: BundleIdCapabilityCreateRequestDataAttributes,
81+
) -> Result<()> {
82+
let token = self.get_token()?;
83+
84+
let body = BundleIdCapabilityCreateRequest {
85+
data: BundleIdCapabilityCreateRequestData {
86+
attributes: capability,
87+
relationships: BundleIdCapabilityCreateRequestDataRelationships {
88+
bundle_id: BundleIdCapabilityCreateRequestDataRelationshipBundleId {
89+
data: BundleIdCapabilityCreateRequestDataRelationshipBundleIdData {
90+
id: id.to_string(),
91+
r#type: "bundleIds".to_string(),
92+
},
93+
},
94+
},
95+
r#type: "bundleIdCapabilities".to_string(),
96+
},
97+
};
98+
99+
let req = self
100+
.client
101+
.post(APPLE_BUNDLE_CAPABILITIES_URL)
102+
.bearer_auth(token)
103+
.header("Accept", "application/json")
104+
.json(&body);
105+
self.send_request(req)?;
106+
Ok(())
107+
}
108+
75109
pub fn delete_bundle_id(&self, id: &str) -> Result<()> {
76110
let token = self.get_token()?;
77111
let req = self
@@ -159,8 +193,47 @@ pub struct BundleCapability {
159193
pub id: String,
160194
}
161195

162-
#[derive(Debug, Deserialize)]
196+
#[derive(Debug, Deserialize, Serialize)]
163197
#[serde(rename_all = "camelCase")]
164198
pub struct BundleCapabilityAttributes {
165199
pub capability_type: String,
166200
}
201+
202+
#[derive(Debug, Serialize)]
203+
#[serde(rename_all = "camelCase")]
204+
pub struct BundleIdCapabilityCreateRequest {
205+
data: BundleIdCapabilityCreateRequestData,
206+
}
207+
208+
#[derive(Debug, Serialize)]
209+
#[serde(rename_all = "camelCase")]
210+
pub struct BundleIdCapabilityCreateRequestData {
211+
attributes: BundleIdCapabilityCreateRequestDataAttributes,
212+
relationships: BundleIdCapabilityCreateRequestDataRelationships,
213+
r#type: String,
214+
}
215+
216+
#[derive(Debug, Serialize)]
217+
#[serde(rename_all = "camelCase")]
218+
pub struct BundleIdCapabilityCreateRequestDataAttributes {
219+
pub capability_type: String,
220+
}
221+
222+
#[derive(Debug, Serialize)]
223+
#[serde(rename_all = "camelCase")]
224+
pub struct BundleIdCapabilityCreateRequestDataRelationships {
225+
bundle_id: BundleIdCapabilityCreateRequestDataRelationshipBundleId,
226+
}
227+
228+
#[derive(Debug, Serialize)]
229+
#[serde(rename_all = "camelCase")]
230+
pub struct BundleIdCapabilityCreateRequestDataRelationshipBundleId {
231+
data: BundleIdCapabilityCreateRequestDataRelationshipBundleIdData,
232+
}
233+
234+
#[derive(Debug, Serialize)]
235+
#[serde(rename_all = "camelCase")]
236+
pub struct BundleIdCapabilityCreateRequestDataRelationshipBundleIdData {
237+
id: String,
238+
r#type: String,
239+
}

app-store-connect/src/cli.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
// option. This file may not be copied, modified, or distributed
55
// except according to those terms.
66

7-
use crate::bundle_api::{BundleCapability, BundleId, BundleIdPlatform};
7+
use crate::bundle_api::{
8+
BundleCapability, BundleId, BundleIdCapabilityCreateRequestDataAttributes, BundleIdPlatform,
9+
};
810
use crate::certs_api::{self, Certificate, CertificateType};
911
use crate::device_api::Device;
1012
use crate::profile_api::{Profile, ProfileType};
@@ -99,17 +101,23 @@ pub enum BundleCommand {
99101
},
100102
List,
101103
Get {
102-
/// Id of certificate.
104+
/// Id of bundle id.
103105
id: String,
104106
},
105107
GetProfiles {
106-
/// Id of certificate.
108+
/// Id of bundle id.
107109
id: String,
108110
},
109111
GetCapabilities {
110-
/// Id of certificate.
112+
/// Id of bundle id.
111113
id: String,
112114
},
115+
EnableCapability {
116+
/// Id of bundle id.
117+
id: String,
118+
/// Capability type.
119+
capability: String,
120+
},
113121
Delete {
114122
/// Id of bundle id to revoke.
115123
id: String,
@@ -144,6 +152,15 @@ impl BundleCommand {
144152
print_capability(&capability);
145153
}
146154
}
155+
Self::EnableCapability { id, capability } => {
156+
client.enable_bundle_id_capability(
157+
&id,
158+
BundleIdCapabilityCreateRequestDataAttributes {
159+
capability_type: capability.clone(),
160+
},
161+
)?;
162+
println!("capability {capability} enabled for bundle ID {id}");
163+
}
147164
Self::GetProfiles { id } => {
148165
let resp = client.list_bundle_profiles(&id)?;
149166
print_profile_header();

0 commit comments

Comments
 (0)