Mercurial > p > roundup > code
comparison roundup/configuration.py @ 7844:b95474b23440
chore(lint): whitespace fixes, double space between class stanzas
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sat, 30 Mar 2024 21:40:02 -0400 |
| parents | ecc34b7917e2 |
| children | 0c71ac9cdcd0 |
comparison
equal
deleted
inserted
replaced
| 7843:3f2d743824e9 | 7844:b95474b23440 |
|---|---|
| 815 class SecretNullableOption(NullableOption, SecretOption): | 815 class SecretNullableOption(NullableOption, SecretOption): |
| 816 # use get from SecretOption and rest from NullableOption | 816 # use get from SecretOption and rest from NullableOption |
| 817 get = SecretOption.get | 817 get = SecretOption.get |
| 818 class_description = SecretOption.class_description | 818 class_description = SecretOption.class_description |
| 819 | 819 |
| 820 | |
| 820 class ListSecretOption(SecretOption): | 821 class ListSecretOption(SecretOption): |
| 821 # use get from SecretOption | 822 # use get from SecretOption |
| 822 def get(self): | 823 def get(self): |
| 823 value = SecretOption.get(self) | 824 value = SecretOption.get(self) |
| 824 return [x.lstrip() for x in value.split(',')] | 825 return [x.lstrip() for x in value.split(',')] |
| 826 class_description = SecretOption.class_description | 827 class_description = SecretOption.class_description |
| 827 | 828 |
| 828 def validate(self, options): # noqa: ARG002 -- options unused | 829 def validate(self, options): # noqa: ARG002 -- options unused |
| 829 if self.name == "WEB_JWT_SECRET": | 830 if self.name == "WEB_JWT_SECRET": |
| 830 secrets = self.get() | 831 secrets = self.get() |
| 831 invalid_secrets = [ x for x in secrets[1:] if len(x) < 32] | 832 invalid_secrets = [x for x in secrets[1:] if len(x) < 32] |
| 832 if invalid_secrets: | 833 if invalid_secrets: |
| 833 raise OptionValueError( | 834 raise OptionValueError( |
| 834 self, ", ".join(secrets), | 835 self, ", ".join(secrets), |
| 835 "One or more secrets less then 32 characters in length\n" | 836 "One or more secrets less then 32 characters in length\n" |
| 836 "found: %s" % ', '.join(invalid_secrets)) | 837 "found: %s" % ', '.join(invalid_secrets)) |
| 837 else: | 838 else: |
| 838 self.get() | 839 self.get() |
| 840 | |
| 839 | 841 |
| 840 class RedisUrlOption(SecretNullableOption): | 842 class RedisUrlOption(SecretNullableOption): |
| 841 """Do required check to make sure known bad parameters are not | 843 """Do required check to make sure known bad parameters are not |
| 842 put in the url. | 844 put in the url. |
| 843 | 845 |
| 982 value.decode("ascii") | 984 value.decode("ascii") |
| 983 except UnicodeError: | 985 except UnicodeError: |
| 984 value = value.decode("utf-8") | 986 value = value.decode("utf-8") |
| 985 return re.compile(value, self.flags) | 987 return re.compile(value, self.flags) |
| 986 | 988 |
| 989 | |
| 987 class LogLevelOption(Option): | 990 class LogLevelOption(Option): |
| 988 | |
| 989 """A log level, one of none, debug, info, warning, error, critical""" | 991 """A log level, one of none, debug, info, warning, error, critical""" |
| 990 | 992 |
| 991 values = "none debug info warning error critical".split () | 993 values = "none debug info warning error critical".split() |
| 992 class_description = "Allowed values: %s" % (', '.join (values)) | 994 class_description = "Allowed values: %s" % (', '.join(values)) |
| 993 | 995 |
| 994 def str2value(self, value): | 996 def str2value(self, value): |
| 995 _val = value.lower() | 997 _val = value.lower() |
| 996 if _val in self.values: | 998 if _val in self.values: |
| 997 return _val | 999 return _val |
| 998 else: | 1000 else: |
| 999 raise OptionValueError(self, value, self.class_description) | 1001 raise OptionValueError(self, value, self.class_description) |
| 1002 | |
| 1000 | 1003 |
| 1001 try: | 1004 try: |
| 1002 import jinja2 # noqa: F401 | 1005 import jinja2 # noqa: F401 |
| 1003 jinja2_avail = "Available found" | 1006 jinja2_avail = "Available found" |
| 1004 except ImportError: | 1007 except ImportError: |
