This file is indexed.

/usr/lib/python2.7/dist-packages/jenkinsapi/fingerprint.py is in python-jenkinsapi 0.2.16-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 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
"""
Module for jenkinsapi Fingerprint
"""

from jenkinsapi.jenkinsbase import JenkinsBase
from jenkinsapi.custom_exceptions import ArtifactBroken

import urllib2
import re

import logging

log = logging.getLogger(__name__)


class Fingerprint(JenkinsBase):
    """
    Represents a jenkins fingerprint on a single artifact file ??
    """
    RE_MD5 = re.compile("^([0-9a-z]{32})$")

    def __init__(self, baseurl, id_, jenkins_obj):
        logging.basicConfig()
        self.jenkins_obj = jenkins_obj
        assert self.RE_MD5.search(id_), "%s does not look like a valid id" % id_
        url = "%s/fingerprint/%s/" % (baseurl, id_)
        JenkinsBase.__init__(self, url, poll=False)
        self.id_ = id_
        self.unknown = False  # Previously uninitialized in ctor

    def get_jenkins_obj(self):
        return self.jenkins_obj

    def __str__(self):
        return self.id_

    def valid(self):
        """
        Return True / False if valid. If returns True, self.unknown is
        set to either True or False, and can be checked if we have
        positive validity (fingerprint known at server) or negative
        validity (fingerprint not known at server, but not really an
        error).
        """
        try:
            self.poll()
            self.unknown = False
        except urllib2.HTTPError as err:
            # We can't really say anything about the validity of
            # fingerprints not found -- but the artifact can still
            # exist, so it is not possible to definitely say they are
            # valid or not.
            if err.code == 404:
                self.unknown = True
                return True

            return False
        return True

    def validate_for_build(self, filename, job, build):
        if not self.valid():
            log.info("Unknown to jenkins.")
            return False
        if self.unknown:
            # not request error, but unknown to jenkins
            return True
        if not self._data["original"] is None:
            if self._data["original"]["name"] == job:
                if self._data["original"]["number"] == build:
                    return True
        if self._data["fileName"] != filename:
            log.info(msg="Filename from jenkins (%s) did not match provided (%s)" % (self._data["fileName"], filename))
            return False
        for usage_item in self._data["usage"]:
            if usage_item["name"] == job:
                for range_ in usage_item["ranges"]["ranges"]:
                    if range_["start"] <= build <= range_["end"]:
                        msg = "This artifact was generated by %s between build %i and %i" % \
                              (job, range_["start"], range_["end"])
                        log.info(msg=msg)
                        return True
        return False

    def validate(self):
        try:
            assert self.valid()
        except AssertionError:
            raise ArtifactBroken("Artifact %s seems to be broken, check %s" % (self.id_, self.baseurl))
        except urllib2.HTTPError:
            raise ArtifactBroken("Unable to validate artifact id %s using %s" % (self.id_, self.baseurl))
        return True

    def get_info(self):
        """
        Returns a tuple of build-name, build# and artifiact filename for a good build.
        """
        self.poll()
        return self._data["original"]["name"], self._data["original"]["number"], self._data["fileName"]