def read(self, profile: Union[LinkedResourceData, ResourceId]) -> Profile: """ https://developer.apple.com/documentation/appstoreconnectapi/read_and_download_profile_information """ profile_id = self._get_resource_id(profile) response = self.client.session.get( f'{self.client.API_URL}/profiles/{profile_id}').json() return Profile(response['data'])
def test_resource_tabular_formatting(api_profile): expected_format = \ 'Id: 253YPL8VY6\n' \ 'Type: profiles\n' \ 'Name: test profile\n' \ 'Platform: IOS\n' \ 'Uuid: 55b8fdb4-b7d2-402d-b48b-2523f7b9c384\n' \ 'Created date: 2019-11-29 13:56:50.220000+00:00\n' \ 'State: ACTIVE\n' \ 'Type: IOS_APP_DEVELOPMENT\n' \ 'Expiration date: 2020-11-28 13:56:50.220000+00:00\n' \ 'Content: "..."' assert str(Profile(api_profile)) == expected_format
def list(self, resource_filter: Filter = Filter(), ordering=Ordering.NAME, reverse=False) -> List[Profile]: """ https://developer.apple.com/documentation/appstoreconnectapi/list_and_download_profiles """ params = { 'sort': ordering.as_param(reverse), **resource_filter.as_query_params() } profiles = self.client.paginate(f'{self.client.API_URL}/profiles', params=params) return [Profile(profile) for profile in profiles]
def list_profiles(self, bundle_id: Union[BundleId, ResourceId], resource_filter: Optional[Profiles.Filter] = None) -> List[Profile]: """ https://developer.apple.com/documentation/appstoreconnectapi/list_all_profiles_for_a_bundle_id """ if isinstance(bundle_id, BundleId): url = bundle_id.relationships.profiles.links.related else: url = f'{self.client.API_URL}/bundleIds/{bundle_id}/profiles' profiles = [Profile(profile) for profile in self.client.paginate(url)] if resource_filter: return [profile for profile in profiles if resource_filter.matches(profile)] return profiles
def create( self, name: str, profile_type: ProfileType, bundle_id: Union[ResourceId, BundleId], certificates: Union[Sequence[ResourceId], Sequence[SigningCertificate]], devices: Union[Sequence[ResourceId], Sequence[Device]]) -> Profile: """ https://developer.apple.com/documentation/appstoreconnectapi/create_a_profile """ if profile_type.devices_not_allowed() and devices: raise ValueError( f'Cannot assign devices to profile with type {profile_type}') if devices is None: devices = [] attributes = { 'name': name, 'profileType': profile_type.value, } relationships = { 'bundleId': { 'data': self._get_attribute_data(bundle_id, ResourceType.BUNDLE_ID), }, 'certificates': { 'data': [ self._get_attribute_data(c, ResourceType.CERTIFICATES) for c in certificates ], }, 'devices': { 'data': [ self._get_attribute_data(d, ResourceType.DEVICES) for d in devices ], }, } payload = self._get_create_payload(ResourceType.PROFILES, attributes=attributes, relationships=relationships) response = self.client.session.post(f'{self.client.API_URL}/profiles', json=payload).json() return Profile(response['data'], created=True)
def test_profile_initialization(api_profile): profile = Profile(api_profile) assert profile.dict() == api_profile assert profile.relationships.devices.data[0].id == '8UCFZA68RK'