• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ansible / awx-plugins / 22356707979

24 Feb 2026 03:05PM UTC coverage: 72.473% (+0.2%) from 72.308%
22356707979

Pull #160

github

web-flow
Merge de903295d into 80291c0b7
Pull Request #160: ⛓🔒 Bump transitive deps in pip-tools-managed lockfiles

37 of 37 branches covered (100.0%)

Branch coverage included in aggregate %.

2372 of 3287 relevant lines covered (72.16%)

2.16 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

54.29
/src/awx_plugins/credentials/plugin.py
1
# FIXME: the following violations must be addressed gradually and unignored
2
# mypy: disable-error-code="no-untyped-def"
3

4
import os
3✔
5
import tempfile
3✔
6
import typing
3✔
7

8
from requests.exceptions import HTTPError
3✔
9

10
from . import _types
3✔
11

12

13
class CredentialPlugin(typing.NamedTuple):
3✔
14
    """Schema for credential plugins."""
15

16
    name: str
3✔
17
    inputs: _types.PluginInputs
3✔
18
    backend: object
3✔
19

20

21
def raise_for_status(resp):
×
22
    resp.raise_for_status()
×
23
    if resp.status_code >= 300:
×
24
        exc = HTTPError()
3✔
25
        setattr(exc, 'response', resp)
×
26
        raise exc
3✔
27

28

29
class CertFiles:
3✔
30
    """A context manager used for writing a certificate and (optional) key to
31
    $TMPDIR, and cleaning up afterwards.
32

33
    This is particularly useful as a shared resource for credential plugins
34
    that want to pull cert/key data out of the database and persist it
35
    temporarily to the file system so that it can loaded into the OpenSSL
36
    certificate chain (generally, for HTTPS requests plugins make via the
37
    Python requests library)
38

39
    with CertFiles(cert_data, key_data) as cert:
40
        # cert is string representing a path to the certificate or PEM file
41
        # temporarily written to disk
42
        requests.post(..., cert=cert)
43
    """
44

45
    certfile: typing.IO[bytes] | None = None
3✔
46

47
    def __init__(self, cert, key=None):
×
48
        self.cert = cert
×
49
        self.key = key
×
50

51
    def __enter__(self):
×
52
        if not self.cert:
×
53
            return None
×
54
        self.certfile = tempfile.NamedTemporaryFile('wb', delete=False)
×
55
        self.certfile.write(self.cert.encode())
×
56
        if self.key:
×
57
            self.certfile.write(b'\n')
×
58
            self.certfile.write(self.key.encode())
×
59
        self.certfile.flush()
3✔
60
        return str(self.certfile.name)
3✔
61

62
    def __exit__(self, *args):
×
63
        if self.certfile and os.path.exists(self.certfile.name):
3✔
64
            os.remove(self.certfile.name)
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc