Skip to content

Reference

The Config object defines clients and servers and their trust model.

Lookup and return the location of the certified-apis configuration directory.

Priority order is
  1. certified_config (if not None)
  2. $CERTIFIED_CONFIG (if CERTIFIED_CONFIG defined)
  3. $VIRTUAL_ENV/etc/certified (if VIRTUAL_ENV defined)
  4. /etc/certified
The return value of this function is cached,

so changes to environment variables have no effect after the first return from this function.

Parameters:

Name Type Description Default
certified_config Optional[Pstr]

if defined, this value is returned.

None
should_exist bool

require that the directory exist?

True

Raises:

Type Description
NotADirectoryError

Raised if the config does not point to a directory. If exists == False, this is only raised when the config exists, but is not a non-directory.

Source code in certified/layout.py
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
def config(certified_config: Optional[Pstr] = None,
        should_exist: bool = True) -> Path:
    """Lookup and return the location of the certified-apis
    configuration directory.

    Priority order is:
      1. certified_config (if not None)
      2. $CERTIFIED_CONFIG (if CERTIFIED_CONFIG defined)
      3. $VIRTUAL_ENV/etc/certified (if VIRTUAL_ENV defined)
      4. /etc/certified

    Note: The return value of this function is cached,
          so changes to environment variables have
          no effect after the first return from this function.

    Args:
      certified_config: if defined, this value is returned.
      should_exist: require that the directory exist?

    Raises:
      NotADirectoryError: Raised if the config does not point to a directory.
                          If exists == False, this is only raised
                          when the config exists,
                          but is not a non-directory.

    """
    if certified_config is None:
        try:
            certified_config = os.environ["CERTIFIED_CONFIG"]
        except KeyError:
            pre = os.environ.get("VIRTUAL_ENV", "/")
            certified_config = Path(pre)/"etc"/"certified"

    p = Path(certified_config)
    if should_exist:
        if not p.is_dir():
            raise NotADirectoryError(str(p))
    else:
        if p.exists() and not p.is_dir():
            raise NotADirectoryError(str(p))
    return p