def add_managed_app_bundle()

in partnercenter/azext_partnercenter/clients/plan_technicalconfiguration_client.py [0:0]


    def add_managed_app_bundle(self, offer_external_id, plan_external_id, package_path, public_azure_tenant_id, public_azure_authorization_principal, public_azure_authorization_role):
        variant_package_branch = self._get_variant_package_branch(offer_external_id, plan_external_id)
        offer_durable_id = variant_package_branch.product.id
        current_draft_instance_id = variant_package_branch.current_draft_instance_id

        file_name = os.path.basename(package_path)

        input_package = MicrosoftIngestionApiModelsPackagesAzurePackage(
            resource_type='AzureApplicationPackage',
            file_name=file_name
        )

        output_package = self._sdk.package_client.products_product_id_packages_post(
            offer_durable_id,
            self._get_access_token(),
            microsoft_ingestion_api_models_packages_azure_package=input_package)

        upload_result = upload_media(package_path, output_package.file_sas_uri)
        if upload_result is None:
            raise CLIError(f'There was an error uploading "{package_path}"')

        output_package.state = "Uploaded"

        updated_package = self._sdk.package_client.products_product_id_packages_package_id_put(
            offer_durable_id,
            output_package.id,
            self._get_access_token(),
            microsoft_ingestion_api_models_packages_azure_package=output_package
        )

        package_id = updated_package.id

        # wait for the package to be processed

        # get package configuration by draft instance id
        package_configuration = self._sdk.package_configuration_client.products_product_id_package_configurations_get_by_instance_id_instance_i_dinstance_id_get(
            offer_durable_id,
            current_draft_instance_id,
            self._get_access_token()
        )

        package_config_data = package_configuration['value'][0]

        # Create a dictionary with the relevant data
        package_config_dict = {
            'resource_type': package_config_data['resourceType'],
            'id': package_config_data['id'],
            'odata_etag': package_config_data['@odata.etag'],
            'allow_jit_access': package_config_data['allowJitAccess'],
            'can_enable_customer_actions': True,
            'allowed_customer_actions': [
                "Microsoft.Resources/*"
            ],
            'azure_government_authorizations': package_config_data['azureGovernmentAuthorizations'],
            'package_references': [
                {
                    "type": "AzureApplicationPackage",
                    "value": package_id
                }
            ],
            'publisher_management_mode': package_config_data['publisherManagementMode'],
            'customer_access_enable_state': package_config_data['customerAccessEnableState'],
            'DeploymentMode': 'Incremental',
            'public_azure_tenant_id': public_azure_tenant_id,
            'version': "1.0.0",
            'public_azure_authorizations': [
                {
                    "principalID": public_azure_authorization_principal,
                    "roleDefinitionID": public_azure_authorization_role
                }
            ]
        }

        updated_package_config = ProductsProductIDPackageconfigurationsPackageConfigurationIDGet200Response(**package_config_dict)
        package_config = package_configuration['value'][0]
        package_configuration_id = package_config['id']

        package_config_update = self._sdk.package_configuration_client.products_product_id_packageconfigurations_package_configuration_id_put(
            offer_durable_id,
            package_configuration_id,
            self._get_access_token(),
            products_product_id_packageconfigurations_package_configuration_id_get200_response=updated_package_config
        )

        mapped_config = self._map_package_configuration(package_config_update)
        return mapped_config