How to use the mongoengine.DictField function in mongoengine

To help you get started, we’ve selected a few mongoengine examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wietze / bsides-ldn-2019 / app / engine / objects.py View on Github external
known_users = ListField(ReferenceField(ObservedUser), default=list)
    known_persistence = ListField(ReferenceField(ObservedPersistence), default=list)
    known_registry_keys = ListField(ReferenceField(ObservedRegKey), default=list)
    known_services = ListField(ReferenceField(ObservedService, default=list))
    known_processes = ListField(ReferenceField(ObservedProcess), default=list)
    known_trashed = ListField(ReferenceField(Trashed), default=list)
    known_os_versions = ListField(ReferenceField(ObservedOSVersion), default=list)
    known_software = ListField(ReferenceField(ObservedSoftware), default=list)
    clean_log = EmbeddedDocumentListField(ErrorLog, default=list)
    steps = ListField(StringField(), default=list)
    planner_facts = StringField()
    jobs = ListField(ReferenceField(Job), default=list)
    performed_steps = EmbeddedDocumentListField(PerformedStep, default=list)
    nonexistent_rats = ListField(ReferenceField(ObservedRat), default=list)
    ignored_rats = ListField(ReferenceField(Rat), default=list)
    object_references = DictField()
    cleanup_index = IntField(default=0)
    perform_cleanup = BooleanField(required=True)
    skip_cleanup = BooleanField()
    delay = IntField(required=True)
    jitter = IntField(required=True)
    precons = StringField()
    script = StringField()

    def delete(self, *args, **kwargs):
        try:
            self.log.delete()
        except (mongoengine.errors.DoesNotExist, mongoengine.errors.FieldDoesNotExist):
            pass

        delete_fields = ('known_credentials', 'known_domains', 'known_files', 'known_hosts', 'known_rats',
                         'known_schtasks', 'known_shares', 'known_timedeltas', 'known_users', 'known_persistence',
github wietze / bsides-ldn-2019 / app / engine / objects.py View on Github external
obj2 = ListField(StringField())


class CodedStep(ExtrovirtsDocument):
    name = StringField()
    display_name = StringField()
    coded_name = StringField()
    parameters = ListField(StringField())
    score = IntField()
    add = EmbeddedDocumentListField(Term)
    requirement_terms = EmbeddedDocumentListField(Term)
    requirement_comparisons = EmbeddedDocumentListField(Comparison)
    remove = EmbeddedDocumentListField(Term)
    deterministic = BooleanField()
    significant_parameters = ListField(IntField())
    bindings = DictField()
    source_hash = BinaryField()
    summary = StringField()
    mapping = EmbeddedDocumentListField('TechniqueMapping', default=list)
    default_mapping = EmbeddedDocumentListField('TechniqueMapping', default=list)
    footprint = BooleanField()
    cddl = StringField()


class ActiveConnection(ExtrovirtsDocument):
    ip = StringField() # remote host IP
    host = ReferenceField(Host)
    connections = IntField()
    local_ip = StringField()  # local server IP that ip is connected to so we can get specific local interface IP


class Adversary(ExtrovirtsDocument):
github yeti-platform / yeti / contrib / feeds / otx / otx.py View on Github external
}

# Some observable types are not yet supported by Yeti:
# IPv6
# URI
# FileHash-PEHASH
# FileHash-IMPHASH
# CIDR
# FilePath
# Mutex
# CVE


class OtxFeed(Feed):

    last_runs = DictField()

    default_values = {
        "frequency": timedelta(hours=1),
        "name": "OtxFeed",
        "description": "Parses events from a given OTX pulse",
        "source": "OTX"
    }

    def __init__(self, *args, **kwargs):
        super(OtxFeed, self).__init__(*args, **kwargs)
        self.otx = OTXv2(yeti_config.get('otx', 'key'))
        self.get_pulses()

    def get_pulses(self):
        self.pulses = {}
github pulp / pulp_rpm / plugins / pulp_rpm / plugins / db / models.py View on Github external
names.extend(self.mandatory_package_names)
        names.extend(self.default_package_names)
        names.extend(self.optional_package_names)
        # TODO: conditional package names
        return names


class PackageCategory(UnitMixin, ContentUnit):
    # TODO add docstring to this class
    package_category_id = mongoengine.StringField(required=True)
    repo_id = mongoengine.StringField(required=True)

    description = mongoengine.StringField()
    packagegroupids = mongoengine.ListField()
    translated_description = mongoengine.DictField()
    translated_name = mongoengine.DictField()
    display_order = mongoengine.IntField()
    name = mongoengine.StringField()

    # For backward compatibility
    _ns = mongoengine.StringField(default='units_package_category')
    _content_type_id = mongoengine.StringField(required=True, default='package_category')

    unit_key_fields = ('package_category_id', 'repo_id')
    unit_display_name = 'Package Category'
    unit_description = 'Yum Package category information'

    meta = {
        'indexes': [
            'package_category_id', 'repo_id', 'name', 'packagegroupids'
        ],
        'collection': 'units_package_category',
github fga-eps-mds / 2017.2-QueroCultura / museums_indicators / models.py View on Github external
    @total_museums_for_state.setter
    def total_museums_for_state(self, number):
        self._totalMuseumsForState = number

    @property
    def create_date(self):
        return self._createDate

    @create_date.setter
    def create_date(self, number):
        self._createDate = number


class PercentPublicOrPrivateMuseumsForState(Document):
    _totalPublicMuseumsForState = DictField(required=True)
    _totalPrivateMuseumsForState = DictField(required=True)
    _totalMuseumsForState = DictField(required=True)
    _createDate = DateTimeField(required=True)

    @property
    def total_public_museums_for_state(self):
        return self._totalPublicMuseumsForState

    @total_public_museums_for_state.setter
    def total_public_museums_for_state(self, number):
        self._totalPublicMuseumsForState = number

    @property
    def total_private_museums_for_state(self):
        return self._totalPrivateMuseumsForState

    @total_private_museums_for_state.setter
github fga-eps-mds / 2017.2-QueroCultura / agents_indicators / models.py View on Github external
    @total_agents_for_state.setter
    def total_agents_for_state(self, number):
        self._totalAgentsForState = number

    @property
    def create_date(self):
        return self._createDate

    @create_date.setter
    def create_date(self, number):
        self._createDate = number


class PercentIndividualAndCollectiveAgentForState(Document):
    _totalIndividualAgentForState = DictField(required=True)
    _totalCollectiveAgentForState = DictField(required=True)
    _totalAgentsForState = DictField(required=True)
    _createDate = DateTimeField(required=True)

    @property
    def total_individual_agent_for_state(self):
        return self._totalIndividualAgentForState

    @total_individual_agent_for_state.setter
    def total_individual_agent_for_state(self, number):
        self._totalIndividualAgentForState = number

    @property
    def total_collective_agent_for_state(self):
        return self._totalCollectiveAgentForState
github bluesky / databroker / metadataStore / odm_templates.py View on Github external
from mongoengine import Document
from mongoengine import DateTimeField, StringField, DictField, IntField, FloatField, ReferenceField, DENY
from getpass import getuser


class BeamlineConfig(Document):
    """
    Attributes
    ----------
    config_params: dict
        Custom configuration parameters for a given run. Avoid using '.' in field names.
        If you're interested in doing so, let me know @arkilic
        This has a one-to-many relationship with BeginRunEvent documents
    """
    config_params = DictField(required=False, unique=False)
    meta = {'indexes': ['-_id']}


class BeginRunEvent(Document):
    """ Provide a head for a sequence of events. Entry point for
    an experiment's run. BeamlineConfig is NOT required to create a BeginRunEvent
    The only prereq is an EventDescriptor that identifies the nature of event that is
    starting and

    Attributes
    ----------
    time : timestamp
        The date/time as found at the client side when an event is
        created.
    beamline_id: str
        Beamline String identifier. Not unique, just an indicator of
github beer-garden / beer-garden / src / app / beer_garden / db / mongo / models.py View on Github external
# MongoEngine needs all EmbeddedDocuments to be defined before any Documents that
# reference them. So Parameter must be defined before Command, and choices should be
# defined before Parameter


class Choices(MongoModel, EmbeddedDocument):
    brewtils_model = brewtils.models.Choices

    display = StringField(required=True, choices=brewtils.models.Choices.DISPLAYS)
    strict = BooleanField(required=True, default=True)
    type = StringField(
        required=True, default="static", choices=brewtils.models.Choices.TYPES
    )
    value = DynamicField(required=True)
    details = DictField()

    def __init__(self, *args, **kwargs):
        EmbeddedDocument.__init__(self, *args, **kwargs)

    def clean(self):
        if self.type == "static" and not isinstance(self.value, (list, dict)):
            raise ModelValidationError(
                f"Can not save choices '{self}': type is 'static' but the value is "
                f"not a list or dictionary"
            )
        elif self.type == "url" and not isinstance(self.value, six.string_types):
            raise ModelValidationError(
                f"Can not save choices '{self}': type is 'url' but the value is "
                f"not a string"
            )
        elif self.type == "command" and not isinstance(
github pulp / pulp / server / pulp / server / db / model / __init__.py View on Github external
:type finish_time: basestring
    :ivar group_id:    The id used to identify which  group of tasks a task belongs to
    :type group_id:    uuid.UUID
    :ivar result:      return value of the callable, if any
    :type result:      any
    :ivar exception:   Deprecated. This is always None.
    :type exception:   None
    :ivar traceback:   Deprecated. This is always None.
    :type traceback:   None
    """

    task_id = StringField(required=True)
    worker_name = StringField()
    tags = ListField(StringField())
    state = StringField(choices=constants.CALL_STATES, default=constants.CALL_WAITING_STATE)
    error = DictField(default=None)
    spawned_tasks = ListField(StringField())
    progress_report = DictField()
    task_type = StringField()
    start_time = ISO8601StringField()
    finish_time = ISO8601StringField()
    result = DynamicField()
    group_id = UUIDField(default=None)

    # These are deprecated, and will always be None
    exception = StringField()
    traceback = StringField()

    # For backward compatibility
    _ns = StringField(default='task_status')

    meta = {'collection': 'task_status',
github pulp / pulp / server / pulp / server / db / model / __init__.py View on Github external
# Used for reverse lookup of units to repositories
                    'fields': ['unit_id']
                }
            ],
            'queryset_class': RepositoryContentUnitQuerySet
            }


class Importer(AutoRetryDocument):
    """
    Defines schema for an Importer in the `repo_importers` collection.
    """
    repo_id = StringField(required=True)
    importer_type_id = StringField(required=True)
    config = DictField()
    scratchpad = DictField(default=None)
    last_sync = ISO8601StringField()
    last_updated = UTCDateTimeField()
    last_override_config = DictField()

    # For backward compatibility
    _ns = StringField(default='repo_importers')
    SERIALIZER = serializers.ImporterSerializer

    meta = {'collection': 'repo_importers',
            'allow_inheritance': False,
            'indexes': [{'fields': ['-repo_id', '-importer_type_id'], 'unique': True}],
            'queryset_class': CriteriaQuerySet}

    @classmethod
    def pre_delete(cls, sender, document, **kwargs):
        """