Exemple #1
0
 def test_repo_to_source_json_v1(self):
     """Test serializing repo_to_source results API v1"""
     self.assertEqual(
         repo_to_source(self.dbo.repos.get("single-repo"), False, 1),
         singlerepo_v1())
Exemple #2
0
 def test_repo_to_source_proxy_v1(self):
     """Test a repo with a proxy API v1"""
     self.assertEqual(
         repo_to_source(self.dbo.repos.get("fake-repo-proxy"), False, 1),
         fakerepo_proxy_v1())
Exemple #3
0
 def test_repo_to_source_gpgkey_v1(self):
     """Test a repo with a GPG key API v1"""
     self.assertEqual(
         repo_to_source(self.dbo.repos.get("fake-repo-gpgkey"), False, 1),
         fakerepo_gpgkey_v1())
Exemple #4
0
 def test_repo_to_source_metalink_v1(self):
     """Test a repo with a metalink API v1"""
     self.assertEqual(
         repo_to_source(self.dbo.repos.get("fake-repo-metalink"), False, 1),
         fakerepo_metalink_v1())
Exemple #5
0
 def test_repo_to_source_mirrorlist_v1(self):
     """Test a repo with a mirrorlist API v1"""
     self.assertEqual(
         repo_to_source(self.dbo.repos.get("fake-repo-mirrorlist"), False,
                        1), fakerepo_mirrorlist_v1())
Exemple #6
0
 def test_repo_to_source_baseurl_v1(self):
     """Test a repo with a baseurl API v1"""
     self.assertEqual(
         repo_to_source(self.dbo.repos.get("fake-repo-baseurl"), False, 1),
         fakerepo_baseurl_v1())
Exemple #7
0
 def test_system_repo_v1(self):
     """Test a system repo with a baseurl API v1"""
     self.assertEqual(
         repo_to_source(self.dbo.repos.get("fake-repo-baseurl"), True, 1),
         fakesystem_repo_v1())
Exemple #8
0
 def test_repo_to_source_gpgkey(self):
     """Test a repo with a GPG key"""
     self.assertEqual(repo_to_source(FakeRepoGPGKey(), False),
                      fakerepo_gpgkey())
Exemple #9
0
def v1_projects_source_info(source_ids):
    """Return detailed info about the list of sources

    **/api/v1/projects/source/info/<source-ids>**

      Return information about the comma-separated list of source ids. Or all of the
      sources if '*' is passed. Note that general globbing is not supported, only '*'.

      Immutable system sources will have the "system" field set to true. User added sources
      will have it set to false. System sources cannot be changed or deleted.

      Example::

          {
            "errors": [],
            "sources": {
              "fedora": {
                "check_gpg": true,
                "check_ssl": true,
                "gpgkey_urls": [
                  "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-28-x86_64"
                ],
                "id": "fedora",
                "name": "Fedora $releasever - $basearch",
                "proxy": "http://proxy.brianlane.com:8123",
                "system": true,
                "type": "yum-metalink",
                "url": "https://mirrors.fedoraproject.org/metalink?repo=fedora-28&arch=x86_64"
              }
            }
          }

    In v0 the ``name`` field was used for the id (a short name for the repo). In v1 ``name`` changed
    to ``id`` and ``name`` is now used for the longer descriptive name of the repository.
    """
    if VALID_API_STRING.match(source_ids) is None:
        return jsonify(status=False,
                       errors=[{
                           "id": INVALID_CHARS,
                           "msg": "Invalid characters in API path"
                       }]), 400

    out_fmt = request.args.get("format", "json")
    if VALID_API_STRING.match(out_fmt) is None:
        return jsonify(status=False,
                       errors=[{
                           "id": INVALID_CHARS,
                           "msg": "Invalid characters in format argument"
                       }]), 400

    # Return info on all of the sources
    if source_ids == "*":
        with api.config["DNFLOCK"].lock:
            source_ids = ",".join(
                r.id for r in api.config["DNFLOCK"].dbo.repos.iter_enabled())

    sources = {}
    errors = []
    system_sources = get_repo_sources("/etc/yum.repos.d/*.repo")
    for source in source_ids.split(","):
        with api.config["DNFLOCK"].lock:
            repo = api.config["DNFLOCK"].dbo.repos.get(source, None)
        if not repo:
            errors.append({
                "id": UNKNOWN_SOURCE,
                "msg": "%s is not a valid source" % source
            })
            continue
        sources[repo.id] = repo_to_source(repo,
                                          repo.id in system_sources,
                                          api=1)

    if out_fmt == "toml" and not errors:
        # With TOML output we just want to dump the raw sources, skipping the errors
        return toml.dumps(sources)
    elif out_fmt == "toml" and errors:
        # TOML requested, but there was an error
        return jsonify(status=False, errors=errors), 400
    else:
        return jsonify(sources=sources, errors=errors)
Exemple #10
0
 def test_repo_to_source_proxy(self):
     """Test a repo with a proxy"""
     self.assertEqual(repo_to_source(FakeRepoProxy(), False),
                      fakerepo_proxy())
Exemple #11
0
 def test_repo_to_source_mirrorlist(self):
     """Test a repo with a mirrorlist"""
     self.assertEqual(repo_to_source(FakeRepoMirrorlist(), False),
                      fakerepo_mirrorlist())
Exemple #12
0
 def test_repo_to_source_metalink(self):
     """Test a repo with a metalink"""
     self.assertEqual(repo_to_source(FakeRepoMetalink(), False),
                      fakerepo_metalink())
Exemple #13
0
 def test_system_repo(self):
     """Test a system repo with a baseurl"""
     self.assertEqual(repo_to_source(FakeSystemRepo(), True),
                      fakesystem_repo())
Exemple #14
0
 def test_repo_to_source_baseurl(self):
     """Test a repo with a baseurl"""
     self.assertEqual(repo_to_source(FakeRepoBaseUrl(), False),
                      fakerepo_baseurl())