Debian Codegraph @

ansible_collections/community/docker/plugins/module_utils/_api/credentials/errors.py

raw
1 # This code is part of the Ansible collection community.docker, but is an independent component.
2 # This particular file, and this file only, is based on the Docker SDK for Python (https://github.com/docker/docker-py/)
3 #
4 # Copyright (c) 2016-2022 Docker, Inc.
5 #
6 # It is licensed under the Apache 2.0 license (see LICENSES/Apache-2.0.txt in this collection)
7 # SPDX-License-Identifier: Apache-2.0
8
9 # Note that this module util is **PRIVATE** to the collection. It can have breaking changes at any time.
10 # Do not use this from other collections or standalone plugins/modules!
11
12 from __future__ import annotations
13
14 import typing as t
15
16 if t.TYPE_CHECKING:
17 from subprocess import CalledProcessError
18
19
20 class StoreError(RuntimeError):
21 pass
22
23
24 class CredentialsNotFound(StoreError):
25 pass
26
27
28 class InitializationError(StoreError):
29 pass
30
31
32 def process_store_error(cpe: CalledProcessError, program: str) -> StoreError:
33 message = cpe.output.decode("utf-8")
34 if "credentials not found in native keychain" in message:
35 return CredentialsNotFound(f"No matching credentials in {program}")
36 return StoreError(
37 f'Credentials store {program} exited with "{cpe.output.decode("utf-8").strip()}".'
38 )