|
29 | 29 |
|
30 | 30 | log = logging.getLogger(__name__) |
31 | 31 |
|
32 | | -# Define the module's virtual name |
| 32 | +try: |
| 33 | + import gnupg |
| 34 | + |
| 35 | + HAS_GPG_BINDINGS = True |
| 36 | +except ImportError: |
| 37 | + HAS_GPG_BINDINGS = False |
| 38 | + |
| 39 | + |
33 | 40 | __virtualname__ = "gpg" |
34 | 41 |
|
| 42 | +# Map of letters indicating key validity to pretty string (for display) |
35 | 43 | LETTER_TRUST_DICT = immutabletypes.freeze( |
36 | 44 | { |
37 | 45 | "e": "Expired", |
|
45 | 53 | } |
46 | 54 | ) |
47 | 55 |
|
| 56 | + |
| 57 | +# Map of allowed `trust_level` param values in `trust_key` |
| 58 | +# to trust parameter for python-gnupg trust_keys (to manage owner trust) |
| 59 | +TRUST_KEYS_TRUST_LEVELS = immutabletypes.freeze( |
| 60 | + { |
| 61 | + "expired": "TRUST_EXPIRED", |
| 62 | + "unknown": "TRUST_UNDEFINED", |
| 63 | + "not_trusted": "TRUST_NEVER", |
| 64 | + "marginally": "TRUST_MARGINAL", |
| 65 | + "fully": "TRUST_FULLY", |
| 66 | + "ultimately": "TRUST_ULTIMATE", |
| 67 | + } |
| 68 | +) |
| 69 | + |
| 70 | +# Map of allowed `trust_level` param values in `trust_key` |
| 71 | +# to owner trust numeric values |
48 | 72 | NUM_TRUST_DICT = immutabletypes.freeze( |
49 | 73 | { |
50 | 74 | "expired": "1", |
|
56 | 80 | } |
57 | 81 | ) |
58 | 82 |
|
| 83 | +# Map of owner trust numeric values to pretty string (for display) |
59 | 84 | INV_NUM_TRUST_DICT = immutabletypes.freeze( |
60 | 85 | { |
61 | 86 | "1": "Expired", |
|
67 | 92 | } |
68 | 93 | ) |
69 | 94 |
|
70 | | -VERIFY_TRUST_LEVELS = immutabletypes.freeze( |
71 | | - { |
72 | | - "0": "Undefined", |
73 | | - "1": "Never", |
74 | | - "2": "Marginal", |
75 | | - "3": "Fully", |
76 | | - "4": "Ultimate", |
77 | | - } |
78 | | -) |
79 | | - |
80 | | -TRUST_KEYS_TRUST_LEVELS = immutabletypes.freeze( |
81 | | - { |
82 | | - "expired": "TRUST_EXPIRED", |
83 | | - "unknown": "TRUST_UNDEFINED", |
84 | | - "never": "TRUST_NEVER", |
85 | | - "marginally": "TRUST_MARGINAL", |
86 | | - "fully": "TRUST_FULLY", |
87 | | - "ultimately": "TRUST_ULTIMATE", |
88 | | - } |
89 | | -) |
| 95 | +# Map of signature validity numeric values to pretty string (for display) |
| 96 | +if not HAS_GPG_BINDINGS: |
| 97 | + VERIFY_TRUST_LEVELS = {} |
| 98 | +elif salt.utils.versions.version_cmp(gnupg.__version__, "0.5.1") >= 0: |
| 99 | + VERIFY_TRUST_LEVELS = immutabletypes.freeze( |
| 100 | + { |
| 101 | + "0": "Expired", |
| 102 | + "1": "Undefined", |
| 103 | + "2": "Never", |
| 104 | + "3": "Marginal", |
| 105 | + "4": "Fully", |
| 106 | + "5": "Ultimate", |
| 107 | + } |
| 108 | + ) |
| 109 | +else: |
| 110 | + VERIFY_TRUST_LEVELS = immutabletypes.freeze( |
| 111 | + { |
| 112 | + "0": "Undefined", |
| 113 | + "1": "Never", |
| 114 | + "2": "Marginal", |
| 115 | + "3": "Fully", |
| 116 | + "4": "Ultimate", |
| 117 | + } |
| 118 | + ) |
90 | 119 |
|
91 | 120 | _DEFAULT_KEY_SERVER = "keys.openpgp.org" |
92 | 121 |
|
93 | | -try: |
94 | | - import gnupg |
95 | | - |
96 | | - HAS_GPG_BINDINGS = True |
97 | | -except ImportError: |
98 | | - HAS_GPG_BINDINGS = False |
99 | | - |
100 | 122 |
|
101 | 123 | def _gpg(): |
102 | 124 | """ |
|
0 commit comments