def validate_promise(self, promiser, attributes): if type(promiser) != str: raise ValidationError("Promiser must be of type string") if not "string" in attributes: raise ValidationError("Missing attribute 'string'") if type(attributes["string"]) != str: raise ValidationError("Attribute 'string' must be of type string")
def validate_promise(self, promiser, attributes): if not promiser.startswith("/"): raise ValidationError(f"File path '{promiser}' must be absolute") for name, value in attributes.items(): if name != "repo": raise ValidationError(f"Unknown attribute '{name}' for git promises") if name == "repo" and type(value) is not str: raise ValidationError(f"'repo' must be string for git promise types")
def validate_promise(self, promiser, attributes): if not promiser.startswith("/"): raise ValidationError( f"Promiser '{promiser}' for 'gpg_keys' promise must be an absolute path" ) if not "keylist" in attributes: raise ValidationError( f"Required attribute 'keylist' missing for 'gpg_keys' promise" )
def validate_promise(self, promiser, attributes): if type(promiser) != str: raise ValidationError("Promiser must be of type string") if not "string" in attributes: raise ValidationError("Missing attribute 'string'") if type(attributes["string"]) != str: raise ValidationError("Attribute 'string' must be of type string") if "always" in attributes and attributes["always"] not in ("true", "false"): raise ValidationError( "Attribute 'always' must be either 'true' or 'false'")
def validate_promise(self, promiser: str, attributes: Dict): attributes.setdefault("destination", promiser) try: GitPromiseTypeModel(**attributes) except PydanticValidationError as e: errors = [ ".".join(map(str, err["loc"])) + ": " + err["msg"] for err in e.errors() ] raise ValidationError(", ".join(errors))
def evaluate_promise(self, promiser, attributes): if not promiser.startswith("/"): raise ValidationError("File path must be absolute") folder = promiser url = attributes["repo"] if os.path.exists(folder): self.promise_kept() return self.log_info(f"Cloning '{url}' -> '{folder}'...") os.system(f"git clone {url} {folder} 2>/dev/null") if os.path.exists(folder): self.log_info(f"Successfully cloned '{url}' -> '{folder}'") self.promise_repaired() else: self.log_error(f"Failed to clone '{url}' -> '{folder}'") self.promise_not_kept()
def validate_promise(self, promiser, attributes): # check promiser type if type(promiser) is not str: raise ValidationError("invalid type for promiser: expected string") # check that promiser is a valid file path if not self._is_unix_file(promiser) and not self._is_win_file( promiser): raise ValidationError( f"invalid value '{promiser}' for promiser: must be a filepath") # check that required attribute feed is present if "feed" not in attributes: raise ValidationError("Missing required attribute feed") # check that attribute feed has a valid type feed = attributes['feed'] if type(feed) is not str: raise ValidationError( "Invalid type for attribute feed: expected string") # check that attribute feed is a valid file path or url if not (self._is_unix_file(feed) or self._is_win_file(feed) or self._is_url(feed)): raise ValidationError( f"Invalid value '{feed}' for attribute feed: must be a file path or url" ) # additional checks if optional attribute select is present if "select" in attributes: select = attributes['select'] # check that attribute select has a valid type if type(select) is not str: raise ValidationError( f"Invalid type for attribute select: expected string") # check that attribute select has a valid value if select != 'newest' and select != 'oldest' and select != 'random': raise ValidationError( f"Invalid value '{select}' for attribute select: must be newest, oldest or random" )
def validate_promise(self, promiser, attributes): if "outcome" in attributes and type(attributes["outcome"]) != str: raise ValidationError( "Attribute 'outcome' for promiser '%d' must be of type string" % promiser)
def validate_promise(self, promiser, attributes): if ("json_data" not in attributes or type(attributes["json_data"]) != dict): raise ValidationError( "'json_data' attribute of type data required")
def validate_promise(self, promiser, attributes): # check promiser type if type(promiser) is not str: raise ValidationError("Invalid type for promiser: expected string") # check promiser value if self._name_regex.match(promiser) is None: self.log_warning(f"Promiser groupname '{promiser}' should match regular expression '[a-z_][a-z0-9_-]*[$]?'") # check promiser length not too long if len(promiser) > self._name_maxlen: raise ValidationError(f"Promiser '{promiser}' is too long: ({len(promiser)} > {self._name_maxlen})") # check attribute policy if present if "policy" in attributes: policy = attributes["policy"] # check attribute policy type if type(policy) is not str: raise ValidationError("Invalid type for attribute policy: expected string") # check attribute policy value if policy not in ("present", "absent"): raise ValidationError(f"Invalid value '{policy}' for attribute policy: must be 'present' or 'absent'") # check attributes gid and members are not used with policy absent if policy == "absent": if "gid" in attributes: self.log_warning(f"Cannot assign gid to absent group '{promiser}'") if "members" in attributes: self.log_warning(f"Cannot assign members to absent group '{promiser}'") # check attribute gid if present if "gid" in attributes: gid = attributes["gid"] # check attribute gid type if type(gid) not in (str, int): raise ValidationError("Invalid type for attribute gid: expected string or int") # check attribute gid value if type(gid) == str: try: int(gid) except ValueError: raise ValidationError(f"Invalid value '{gid}' for attribute gid: expected integer literal") # check attribute members if present if "members" in attributes: # remove escape chars followed by parsing json members = json.loads(json.loads('"' + attributes["members"] + '"')) attributes["members"] = members # check attribute only not used with attributes include or exclude if "only" in members and ("include" in members or "exclude" in members): raise ValidationError("Attribute 'only' may not be used with attributes 'include' or 'exclude'") # check attributes of attibutes in members for attr in members: if attr not in ("only", "include", "exclude"): raise ValidationError(f"Invalid value '{attr}' in attribute members: must be 'only', 'exclude' or 'include'") # make sure users aren't both included and excluded if "include" in members and "exclude" in members: duplicates = set(members["include"]).intersection(set(members["exclude"])) if duplicates != set(): raise ValidationError(f"Users {duplicates} both included and excluded from group '{promiser}'")
def validate_promise(self, promiser, attributes): if not promiser.startswith("/"): raise ValidationError( f"Certificate path '{promiser}' must be absolute")
def validate_promise(self, promiser, attributes): if not self.is_url_valid(promiser): raise ValidationError(f"URL '{promiser}' is invalid")
def validate_promise(self, promiser, attributes): if ("lines" not in attributes or type(attributes["lines"]) not in (list, tuple) or any(type(item) != str for item in attributes["lines"])): raise ValidationError("'lines' attribute of type slist required")