def _install_dependency(self, dependency):
        package_zip = None

        zip_src = None
        if "zip_url" in dependency:
            self.logger.info(
                "Deploying unmanaged metadata from /{} of {}".format(
                    dependency.get("subfolder") or "", dependency["zip_url"]))
            zip_src = self._download_extract_zip(
                dependency["zip_url"], subfolder=dependency.get("subfolder"))
        elif "repo_name" in dependency:
            self.logger.info(
                "Deploying unmanaged metadata from /{} of {}/{}".format(
                    dependency["subfolder"],
                    dependency["repo_owner"],
                    dependency["repo_name"],
                ))
            gh_for_repo = self.project_config.get_github_api(
                dependency["repo_owner"], dependency["repo_name"])
            zip_src = self._download_extract_github(
                gh_for_repo,
                dependency["repo_owner"],
                dependency["repo_name"],
                dependency["subfolder"],
                ref=dependency.get("ref"),
            )

        if zip_src:
            # determine whether to inject namespace prefixes or not
            options = dependency.copy()
            if "unmanaged" not in options:
                namespace = options.get("namespace_inject")
                options["unmanaged"] = (
                    not namespace
                ) or namespace not in self.org_config.installed_packages

            package_zip = MetadataPackageZipBuilder.from_zipfile(
                zip_src, options=options, logger=self.logger).as_base64()
        elif "namespace" in dependency:
            self.logger.info("Installing {} version {}".format(
                dependency["namespace"], dependency["version"]))
            package_zip = InstallPackageZipBuilder(
                dependency["namespace"],
                dependency["version"],
                securityType=self.options["security_type"],
            )()

        if package_zip:
            api = self.api_class(
                self,
                package_zip,
                purge_on_delete=self.options["purge_on_delete"])
            return api()
        elif "version_id" in dependency:
            self.logger.info(f"Installing {dependency['version_id']}")
            install_package_version(self.project_config, self.org_config,
                                    dependency)
        else:
            raise TaskOptionsError(f"Could not find package for {dependency}")
 def _get_api(self, path=None):
     package_zip = InstallPackageZipBuilder(
         namespace=self.options["namespace"],
         version=self.options["version"],
         activateRSS=self.options["activateRSS"],
         password=self.options.get("password"),
     )
     return self.api_class(self, package_zip(), purge_on_delete=False)
    def _install_dependency(self, dependency):
        if 'zip_url' in dependency:
            self.logger.info(
                'Deploying unmanaged metadata from /{} of {}'.format(
                    dependency['subfolder'],
                    dependency['zip_url'],
                ))
            package_zip = download_extract_zip(
                dependency['zip_url'],
                subfolder=dependency.get('subfolder'),
                headers=dependency.get('headers', {}),
            )
            if dependency.get('namespace_tokenize'):
                self.logger.info(
                    'Replacing namespace prefix {}__ in files and filenames with namespace token strings'
                    .format('{}__'.format(dependency['namespace_tokenize']), ))
                package_zip = zip_tokenize_namespace(
                    package_zip,
                    namespace=dependency['namespace_tokenize'],
                    logger=self.logger,
                )

            if dependency.get('namespace_inject'):
                self.logger.info('Replacing namespace tokens with {}'.format(
                    '{}__'.format(dependency['namespace_inject']), ))
                package_zip = zip_inject_namespace(
                    package_zip,
                    namespace=dependency['namespace_inject'],
                    managed=not dependency.get('unmanaged'),
                    namespaced_org=self.options['namespaced_org'],
                    logger=self.logger,
                )

            if dependency.get('namespace_strip'):
                self.logger.info(
                    'Removing namespace prefix {}__ from all files and filenames'
                    .format('{}__'.format(dependency['namespace_strip']), ))
                package_zip = zip_strip_namespace(
                    package_zip,
                    namespace=dependency['namespace_strip'],
                    logger=self.logger,
                )

            package_zip = ZipfilePackageZipBuilder(package_zip)()

        elif 'namespace' in dependency:
            self.logger.info('Installing {} version {}'.format(
                dependency['namespace'],
                dependency['version'],
            ))
            package_zip = InstallPackageZipBuilder(dependency['namespace'],
                                                   dependency['version'])()

        api = self.api_class(self,
                             package_zip,
                             purge_on_delete=self.options['purge_on_delete'])
        return api()
 def test_process_response_zipstr_one_package(self):
     task = self._create_task()
     api = self._create_instance(task)
     response = DummyResponse()
     response.status_code = 200
     response.text = retrieve_result.format(zip=InstallPackageZipBuilder(
         "foo", "1.1")(),
                                            extra="")
     resp = api._process_response(response)
     self.assertEqual(resp, {"foo": "1.1"})
    def _install_dependency(self, dependency):
        if "zip_url" in dependency:
            self.logger.info(
                "Deploying unmanaged metadata from /{} of {}".format(
                    dependency["subfolder"], dependency["zip_url"]))
            package_zip = download_extract_zip(
                dependency["zip_url"],
                subfolder=dependency.get("subfolder"),
                headers=dependency.get("headers", {}),
            )
            if dependency.get("namespace_tokenize"):
                self.logger.info(
                    "Replacing namespace prefix {}__ in files and filenames with namespace token strings"
                    .format("{}__".format(dependency["namespace_tokenize"])))
                package_zip = zip_tokenize_namespace(
                    package_zip,
                    namespace=dependency["namespace_tokenize"],
                    logger=self.logger,
                )

            if dependency.get("namespace_inject"):
                self.logger.info("Replacing namespace tokens with {}".format(
                    "{}__".format(dependency["namespace_inject"])))
                package_zip = zip_inject_namespace(
                    package_zip,
                    namespace=dependency["namespace_inject"],
                    managed=not dependency.get("unmanaged"),
                    namespaced_org=self.options["namespaced_org"],
                    logger=self.logger,
                )

            if dependency.get("namespace_strip"):
                self.logger.info(
                    "Removing namespace prefix {}__ from all files and filenames"
                    .format("{}__".format(dependency["namespace_strip"])))
                package_zip = zip_strip_namespace(
                    package_zip,
                    namespace=dependency["namespace_strip"],
                    logger=self.logger,
                )

            package_zip = ZipfilePackageZipBuilder(package_zip)()

        elif "namespace" in dependency:
            self.logger.info("Installing {} version {}".format(
                dependency["namespace"], dependency["version"]))
            package_zip = InstallPackageZipBuilder(dependency["namespace"],
                                                   dependency["version"])()

        api = self.api_class(self,
                             package_zip,
                             purge_on_delete=self.options["purge_on_delete"])
        return api()
 def _process_response_zipstr_one_package(self):
     task = self._create_task()
     api = self._create_instance(task)
     response = DummyResponse
     response.status_code = 200
     response.content = deploy_result.format(
         zip = InstallPackageZipBuilder('foo', '1.1'),
         extra = '',
     )
     resp = api._process_response(response)
     self.assertEquals(
         resp,
         {'foo': '1.1'},
     )
Exemple #7
0
 def _get_api(self, path=None):
     package_zip = InstallPackageZipBuilder(self.options["namespace"],
                                            self.options["version"])
     return self.api_class(self, package_zip(), purge_on_delete=False)
    def _install_dependency(self, dependency):
        if "zip_url" or "repo_name" in dependency:
            package_zip = None
            if "zip_url" in dependency:
                self.logger.info(
                    "Deploying unmanaged metadata from /{} of {}".format(
                        dependency["subfolder"], dependency["zip_url"]))
                package_zip = self._download_extract_zip(
                    dependency["zip_url"],
                    subfolder=dependency.get("subfolder"))
            elif "repo_name" in dependency:
                self.logger.info(
                    "Deploying unmanaged metadata from /{} of {}/{}".format(
                        dependency["subfolder"],
                        dependency["repo_owner"],
                        dependency["repo_name"],
                    ))
                gh_for_repo = self.project_config.get_github_api(
                    dependency["repo_owner"], dependency["repo_name"])
                package_zip = self._download_extract_github(
                    gh_for_repo,
                    dependency["repo_owner"],
                    dependency["repo_name"],
                    dependency["subfolder"],
                    ref=dependency.get("ref"),
                )

            if package_zip:
                if dependency.get("namespace_tokenize"):
                    self.logger.info(
                        "Replacing namespace prefix {}__ in files and filenames with namespace token strings"
                        .format("{}__".format(
                            dependency["namespace_tokenize"])))
                    package_zip = process_text_in_zipfile(
                        package_zip,
                        functools.partial(
                            tokenize_namespace,
                            namespace=dependency["namespace_tokenize"],
                            logger=self.logger,
                        ),
                    )

                if dependency.get("namespace_inject"):
                    self.logger.info(
                        "Replacing namespace tokens with {}".format(
                            "{}__".format(dependency["namespace_inject"])))
                    package_zip = process_text_in_zipfile(
                        package_zip,
                        functools.partial(
                            inject_namespace,
                            namespace=dependency["namespace_inject"],
                            managed=not dependency.get("unmanaged"),
                            namespaced_org=self.options["namespaced_org"],
                            logger=self.logger,
                        ),
                    )

                if dependency.get("namespace_strip"):
                    self.logger.info(
                        "Removing namespace prefix {}__ from all files and filenames"
                        .format("{}__".format(dependency["namespace_strip"])))
                    package_zip = process_text_in_zipfile(
                        package_zip,
                        functools.partial(
                            strip_namespace,
                            namespace=dependency["namespace_strip"],
                            logger=self.logger,
                        ),
                    )

                package_zip = ZipfilePackageZipBuilder(package_zip)()

            elif "namespace" in dependency:
                self.logger.info("Installing {} version {}".format(
                    dependency["namespace"], dependency["version"]))
                package_zip = InstallPackageZipBuilder(
                    dependency["namespace"],
                    dependency["version"],
                    securityType=self.options["security_type"],
                )()

        api = self.api_class(self,
                             package_zip,
                             purge_on_delete=self.options["purge_on_delete"])
        return api()
 def test_init__missing_version(self):
     with self.assertRaises(ValueError):
         InstallPackageZipBuilder("testns", None)
 def test_init__missing_namespace(self):
     with self.assertRaises(ValueError):
         InstallPackageZipBuilder(None, "1.0")