You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.5 KiB
Python
57 lines
1.5 KiB
Python
import deprecation
|
|
from enum import Enum
|
|
from typing import List, TypedDict
|
|
from inflection import underscore
|
|
import deprecation
|
|
from .common import (
|
|
Validateable,
|
|
)
|
|
|
|
|
|
class GopassType(Enum):
|
|
FIELD = 0
|
|
PASSWORD = 1
|
|
|
|
|
|
class CredentialMapping(Validateable):
|
|
def __init__(self, mapping: dict):
|
|
self.name = mapping.get("name", None)
|
|
self.gopass_field = mapping.get("gopass_field", None)
|
|
self.gopass_path = mapping.get("gopass_path", None)
|
|
|
|
def validate(self) -> List[str]:
|
|
result = []
|
|
result += self.__validate_is_not_empty__("gopass_path")
|
|
if not self.name and not self.gopass_field:
|
|
result.append(f"Either name or gopass field has to be defined.")
|
|
return result
|
|
|
|
def gopass_type(self):
|
|
if self.gopass_field:
|
|
return GopassType.FIELD
|
|
else:
|
|
return GopassType.PASSWORD
|
|
|
|
def name_for_input(self):
|
|
if self.name:
|
|
return self.name
|
|
else:
|
|
return underscore(self.gopass_field)
|
|
|
|
def name_for_environment(self):
|
|
return self.name_for_input().upper()
|
|
|
|
|
|
class Credentials(Validateable):
|
|
def __init__(self, input: dict):
|
|
input_mappings = input.get("credentials_mapping", [])
|
|
self.mappings = []
|
|
for input_mapping in input_mappings:
|
|
self.mappings.append(CredentialMapping(input_mapping))
|
|
|
|
def validate(self) -> List[str]:
|
|
result = []
|
|
for mapping in self.mappings:
|
|
result += mapping.validate()
|
|
return result
|