-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathprovisioning_profiles.go
251 lines (225 loc) · 10.6 KB
/
provisioning_profiles.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
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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
package asc
import (
"context"
"fmt"
)
// Profile defines model for Profile.
//
// https://developer.apple.com/documentation/appstoreconnectapi/profile
type Profile struct {
Attributes *ProfileAttributes `json:"attributes,omitempty"`
ID string `json:"id"`
Links ResourceLinks `json:"links"`
Relationships *ProfileRelationships `json:"relationships,omitempty"`
Type string `json:"type"`
}
// ProfileAttributes defines model for Profile.Attributes
//
// https://developer.apple.com/documentation/appstoreconnectapi/profile/attributes
type ProfileAttributes struct {
CreatedDate *DateTime `json:"createdDate,omitempty"`
ExpirationDate *DateTime `json:"expirationDate,omitempty"`
Name *string `json:"name,omitempty"`
Platform *BundleIDPlatform `json:"platform,omitempty"`
ProfileContent *string `json:"profileContent,omitempty"`
ProfileState *string `json:"profileState,omitempty"`
ProfileType *string `json:"profileType,omitempty"`
UUID *string `json:"uuid,omitempty"`
}
// ProfileRelationships defines model for Profile.Relationships
//
// https://developer.apple.com/documentation/appstoreconnectapi/profile/relationships
type ProfileRelationships struct {
BundleID *Relationship `json:"bundleId,omitempty"`
Certificates *PagedRelationship `json:"certificates,omitempty"`
Devices *PagedRelationship `json:"devices,omitempty"`
}
// ProfileCreateRequest defines model for ProfileCreateRequest.
//
// https://developer.apple.com/documentation/appstoreconnectapi/profilecreaterequest/data
type profileCreateRequest struct {
Attributes profileCreateRequestAttributes `json:"attributes"`
Relationships profileCreateRequestRelationships `json:"relationships"`
Type string `json:"type"`
}
// ProfileCreateRequestAttributes are attributes for ProfileCreateRequest
//
// https://developer.apple.com/documentation/appstoreconnectapi/profilecreaterequest/data/attributes
type profileCreateRequestAttributes struct {
Name string `json:"name"`
ProfileType string `json:"profileType"`
}
// ProfileCreateRequestRelationships are relationships for ProfileCreateRequest
//
// https://developer.apple.com/documentation/appstoreconnectapi/profilecreaterequest/data/relationships
type profileCreateRequestRelationships struct {
BundleID relationshipDeclaration `json:"bundleId"`
Certificates pagedRelationshipDeclaration `json:"certificates"`
Devices *pagedRelationshipDeclaration `json:"devices,omitempty"`
}
// ProfileResponse defines model for ProfileResponse.
//
// https://developer.apple.com/documentation/appstoreconnectapi/profileresponse
type ProfileResponse struct {
Data Profile `json:"data"`
Included []ProfileResponseIncluded `json:"included,omitempty"`
Links DocumentLinks `json:"links"`
}
// ProfilesResponse defines model for ProfilesResponse.
//
// https://developer.apple.com/documentation/appstoreconnectapi/profilesresponse
type ProfilesResponse struct {
Data []Profile `json:"data"`
Included []ProfileResponseIncluded `json:"included,omitempty"`
Links PagedDocumentLinks `json:"links"`
Meta *PagingInformation `json:"meta,omitempty"`
}
// ProfileResponseIncluded is a heterogenous wrapper for the possible types that can be returned
// in a ProfileResponse or ProfilesResponse.
type ProfileResponseIncluded included
// ListProfilesQuery are query options for ListProfile
//
// https://developer.apple.com/documentation/appstoreconnectapi/list_and_download_profiles
type ListProfilesQuery struct {
FieldsCertificates []string `url:"fields[certificates],omitempty"`
FieldsDevices []string `url:"fields[devices],omitempty"`
FieldsProfiles []string `url:"fields[profiles],omitempty"`
FieldsID []string `url:"fields[id],omitempty"`
FieldsName []string `url:"fields[name],omitempty"`
FieldsBundleIDs []string `url:"fields[bundleIds],omitempty"`
Include []string `url:"include,omitempty"`
Limit int `url:"limit,omitempty"`
LimitCertificates int `url:"limit[certificates],omitempty"`
LimitDevices int `url:"limit[devices],omitempty"`
Sort []string `url:"sort,omitempty"`
FilterProfileState []string `url:"filter[profileState],omitempty"`
FilterProfileType []string `url:"filter[profileType],omitempty"`
Cursor string `url:"cursor,omitempty"`
}
// GetProfileQuery are query options for GetProfile
//
// https://developer.apple.com/documentation/appstoreconnectapi/read_and_download_profile_information
type GetProfileQuery struct {
FieldsCertificates []string `url:"fields[certificates],omitempty"`
FieldsDevices []string `url:"fields[devices],omitempty"`
FieldsProfiles []string `url:"fields[profiles],omitempty"`
FieldsBundleIds []string `url:"fields[bundleIds],omitempty"`
LimitCertificates int `url:"limit[certificates],omitempty"`
LimitDevices int `url:"limit[devices],omitempty"`
Include []string `url:"include,omitempty"`
}
// GetBundleIDForProfileQuery are query options for GetBundleIDForProfile
//
// https://developer.apple.com/documentation/appstoreconnectapi/read_the_bundle_id_in_a_profile
type GetBundleIDForProfileQuery struct {
FieldsCertificates []string `url:"fields[certificates],omitempty"`
}
// ListCertificatesForProfileQuery are query options for ListCertificatesForProfile
//
// https://developer.apple.com/documentation/appstoreconnectapi/list_all_certificates_in_a_profile
type ListCertificatesForProfileQuery struct {
FieldsCertificates []string `url:"fields[certificates],omitempty"`
Limit int `url:"limit,omitempty"`
Cursor string `url:"cursor,omitempty"`
}
// ListDevicesInProfileQuery are query options for ListDevicesInProfile
//
// https://developer.apple.com/documentation/appstoreconnectapi/list_all_devices_in_a_profile
type ListDevicesInProfileQuery struct {
FieldsDevices []string `url:"fields[devices],omitempty"`
Limit int `url:"limit,omitempty"`
Cursor string `url:"cursor,omitempty"`
}
// CreateProfile creates a new provisioning profile.
//
// https://developer.apple.com/documentation/appstoreconnectapi/create_a_profile
func (s *ProvisioningService) CreateProfile(ctx context.Context, name string, profileType string, bundleIDRelationship string, certificateIDs []string, deviceIDs []string) (*ProfileResponse, *Response, error) {
req := profileCreateRequest{
Attributes: profileCreateRequestAttributes{
Name: name,
ProfileType: profileType,
},
Relationships: profileCreateRequestRelationships{
BundleID: *newRelationshipDeclaration(&bundleIDRelationship, "bundleIds"),
Certificates: newPagedRelationshipDeclaration(certificateIDs, "certificates"),
},
Type: "profiles",
}
if len(deviceIDs) > 0 {
relationships := newPagedRelationshipDeclaration(deviceIDs, "devices")
req.Relationships.Devices = &relationships
}
res := new(ProfileResponse)
resp, err := s.client.post(ctx, "profiles", newRequestBody(req), res)
return res, resp, err
}
// DeleteProfile deletes a provisioning profile that is used for app development or distribution.
//
// https://developer.apple.com/documentation/appstoreconnectapi/delete_a_profile
func (s *ProvisioningService) DeleteProfile(ctx context.Context, id string) (*Response, error) {
url := fmt.Sprintf("profiles/%s", id)
return s.client.delete(ctx, url, nil)
}
// ListProfiles finds and list provisioning profiles and download their data.
//
// https://developer.apple.com/documentation/appstoreconnectapi/list_and_download_profiles
func (s *ProvisioningService) ListProfiles(ctx context.Context, params *ListProfilesQuery) (*ProfilesResponse, *Response, error) {
res := new(ProfilesResponse)
resp, err := s.client.get(ctx, "profiles", params, res)
return res, resp, err
}
// GetProfile gets information for a specific provisioning profile and download its data.
//
// https://developer.apple.com/documentation/appstoreconnectapi/read_and_download_profile_information
func (s *ProvisioningService) GetProfile(ctx context.Context, id string, params *GetProfileQuery) (*ProfileResponse, *Response, error) {
url := fmt.Sprintf("profiles/%s", id)
res := new(ProfileResponse)
resp, err := s.client.get(ctx, url, params, res)
return res, resp, err
}
// GetBundleIDForProfile gets the bundle ID information for a specific provisioning profile.
//
// https://developer.apple.com/documentation/appstoreconnectapi/read_the_bundle_id_in_a_profile
func (s *ProvisioningService) GetBundleIDForProfile(ctx context.Context, id string, params *GetBundleIDForProfileQuery) (*BundleIDResponse, *Response, error) {
url := fmt.Sprintf("profiles/%s/bundleId", id)
res := new(BundleIDResponse)
resp, err := s.client.get(ctx, url, params, res)
return res, resp, err
}
// ListCertificatesInProfile gets a list of all certificates and their data for a specific provisioning profile.
//
// https://developer.apple.com/documentation/appstoreconnectapi/list_all_certificates_in_a_profile
func (s *ProvisioningService) ListCertificatesInProfile(ctx context.Context, id string, params *ListCertificatesForProfileQuery) (*CertificatesResponse, *Response, error) {
url := fmt.Sprintf("profiles/%s/certificates", id)
res := new(CertificatesResponse)
resp, err := s.client.get(ctx, url, params, res)
return res, resp, err
}
// ListDevicesInProfile gets a list of all devices for a specific provisioning profile.
//
// https://developer.apple.com/documentation/appstoreconnectapi/list_all_devices_in_a_profile
func (s *ProvisioningService) ListDevicesInProfile(ctx context.Context, id string, params *ListDevicesInProfileQuery) (*DevicesResponse, *Response, error) {
url := fmt.Sprintf("profiles/%s/devices", id)
res := new(DevicesResponse)
resp, err := s.client.get(ctx, url, params, res)
return res, resp, err
}
// UnmarshalJSON is a custom unmarshaller for the heterogenous data stored in ProfileResponseIncluded.
func (i *ProfileResponseIncluded) UnmarshalJSON(b []byte) error {
typeName, inner, err := unmarshalInclude(b)
i.Type = typeName
i.inner = inner
return err
}
// BundleID returns the BundleID stored within, if one is present.
func (i *ProfileResponseIncluded) BundleID() *BundleID {
return extractIncludedBundleID(i.inner)
}
// Device returns the Device stored within, if one is present.
func (i *ProfileResponseIncluded) Device() *Device {
return extractIncludedDevice(i.inner)
}
// Certificate returns the Certificate stored within, if one is present.
func (i *ProfileResponseIncluded) Certificate() *Certificate {
return extractIncludedCertificate(i.inner)
}