class Query(graphene.ObjectType): node = relay.Node.Field() user = graphene.Field( lambda: graphene.List(User), id=graphene.Int(required=False), name=graphene.String(required=False) ) todo = graphene.Field( lambda: graphene.List(Todo), id=graphene.Int(required=False), user_id=graphene.Int(required=False), title=graphene.String(required=False), description=graphene.String(required=False), deadline=graphene.DateTime(required=False) ) all_users = SQLAlchemyConnectionField(UserConnections) all_todos = SQLAlchemyConnectionField(TodoConnections, sort=None) def resolve_user(self, info, id=None, name=None): return fetch_user(id, name) def resolve_todo(self, info, id=None, user_id=None, title=None, description=None, deadline=None): return fetch_todo(id, user_id, title, description, deadline)
class NvtSeverity(graphene.ObjectType): """Severity info item of an NVT. """ date = graphene.DateTime() origin = graphene.String() score = graphene.Int() severity_type = graphene.String(name='type') vector = graphene.String( description='The CVSS Vector resposible for the Score.') def resolve_date(root, _info): return get_datetime_from_element(root, 'date') def resolve_origin(root, _info): return get_text_from_element(root, 'origin') def resolve_score(root, _info): return get_int_from_element(root, 'score') def resolve_severity_type(root, _info): return root.get('type') def resolve_vector(root, _info): return get_text_from_element(root, 'value')
class ResultOverride( graphene.ObjectType, UUIDObjectTypeMixin, CreationModifactionObjectTypeMixin ): active = graphene.Boolean(description='Whether the Override is active') severity = graphene.Field( SeverityType, description='Minimum severity of results the Override applies to', ) new_severity = graphene.Field( SeverityType, description='Severity level results are changed to by the Override', ) text = graphene.String(description='Text of the Override') end_time = graphene.DateTime( description='Override end time in case of limit, else empty.' ) @staticmethod def resolve_active(root, _info): return get_boolean_from_element(root, 'active') @staticmethod def resolve_severity(root, _info): return get_text_from_element(root, 'severity') @staticmethod def resolve_new_severity(root, _info): return get_text_from_element(root, 'new_severity') @staticmethod def resolve_text(root, _info): return get_text_from_element(root, 'text') @staticmethod def resolve_end_time(root, _info): return get_datetime_from_element(root, 'end_time')
class ReportFormat(EntityObjectType): """ReportFormat object type. Can be used in getReportFormat and getReportFormats queries. Please query in camelCase e.g. report_format_id => reportFormatId. """ summary = graphene.String() description = graphene.String() predefined = graphene.Boolean() trust = graphene.String() trust_time = graphene.DateTime() active = graphene.Boolean() extension = graphene.String() def resolve_summary(root, _info): return get_text_from_element(root, 'summary') def resolve_description(root, _info): return get_text_from_element(root, 'description') def resolve_trust(root, _info): return get_text_from_element(root, 'trust') def resolve_trust_time(root, _info): trust = root.find('trust') return get_datetime_from_element(trust, 'time') def resolve_predefined(root, _info): return get_boolean_from_element(root, 'predefined') def resolve_active(root, _info): return get_boolean_from_element(root, 'active') def resolve_extension(root, _info): return get_text_from_element(root, 'extension')
class Transaction(ModelObjectType): id = graphene.GlobalID(required=True) created = graphene.DateTime(required=True) payment = graphene.Field(lambda: Payment, required=True) token = graphene.String(required=True) kind = TransactionKindEnum(required=True) is_success = graphene.Boolean(required=True) error = graphene.String() gateway_response = JSONString(required=True) amount = graphene.Field(Money, description="Total amount of the transaction.") class Meta: description = "An object representing a single payment." interfaces = [relay.Node] model = models.Transaction @staticmethod def resolve_created(root: models.Transaction, _info): return root.created_at @staticmethod def resolve_amount(root: models.Transaction, _info): return root.get_amount()
class Table(graphene.ObjectType): """ CSV-list structure for floats Distribution """ class Meta: interfaces = (relay.Node, ) name = graphene.String(description="a name for the table") object_id = graphene.ID( description="ID of the object this data relates to", ) created = graphene.DateTime( description="When the task record was created", ) column_headers = graphene.List(graphene.String, description="column headings") column_types = graphene.List(RowItemType, description="column types") rows = graphene.List( graphene.List(graphene.String), description= "The table rows. Each row is a list of strings that can be coerced according to column_types." ) meta = graphene.List( KeyValuePair, required=False, description="additional meta data, as a list of Key Value pairs.") table_type = graphene.Field(TableType, description="table type") dimensions = graphene.List( KeyValueListPair, required=False, description="table dimensions, as a list of Key Value List pairs.") @classmethod def get_node(cls, info, _id): t0 = dt.utcnow() res = get_data_manager().table.get_one(_id) db_metrics.put_duration(__name__, 'Table.get_node', dt.utcnow() - t0) return res
class User(graphene.ObjectType): id = graphene.ID(default_value=str(uuid.uuid4())) username = graphene.String() created_at = graphene.DateTime(default_value=datetime.now())
class StatusQuery(): server_clock = graphene.DateTime(required=True, resolver=server_clock_resolver) ping = graphene.String(required=True, resolver=ping_resolver)
class UserSelf(UserBase, graphene.ObjectType): date_joined = graphene.DateTime() @staticmethod def resolve_last_name(user, *args, **kwargs): return user.date_joined
class Page(graphene.Interface): page_id = graphene.Int(required=True) content_type = graphene.String(required=True) title = graphene.String(required=True) slug = graphene.String(required=True) seo_title = graphene.String(required=True) search_description = graphene.String(required=True) last_published_at = graphene.DateTime(required=True) url_path = graphene.String(required=True) path = graphene.String(required=True) sub_pages = graphene.List(lambda: graphene.NonNull(AllPages), in_menu=graphene.Boolean(), required=True) sub_pages_generic = graphene.List(lambda: graphene.NonNull(GenericPage), in_menu=graphene.Boolean(), required=True) sibling_pages = graphene.List(lambda: graphene.NonNull(AllPages), in_menu=graphene.Boolean(), required=True) parent_page = graphene.Field(lambda: graphene.NonNull(AllPages)) ancestor_pages = graphene.List(lambda: graphene.NonNull(AllPages), in_menu=graphene.Boolean(), required=True) ancestor_pages_generic = graphene.List( lambda: graphene.NonNull(GenericPage), in_menu=graphene.Boolean(), required=True) closest_ancestor_of_type = graphene.Field(lambda: AllPages, content_type=graphene.String(), inclusive=graphene.Boolean()) closest_ancestor_of_type_generic = graphene.Field( lambda: GenericPage, content_type=graphene.String(), inclusive=graphene.Boolean()) def resolve_content_type(self, info): return self.__class__.__name__ def resolve_page_id(self, info): return self.id def resolve_title(self, info): return self.title def resolve_slug(self, info): return self.slug def resolve_seo_title(self, info): return self.seo_title def resolve_search_description(self, info): return self.search_description def resolve_last_published_at(self, info): return self.last_published_at def resolve_url_path(self, info): return self.url_path def resolve_path(self, info): if hasattr(self, 'public_path'): return self.public_path or '*' else: return get_public_path_for_page(self) or '*' def resolve_parent_page(self, info): return self.get_parent().specific def resolve_sub_pages(self, info, in_menu=None): q = self.get_children().specific().live() if in_menu is True: q = q.in_menu() return q def resolve_sub_pages_generic(self, info, in_menu=None): q = self.get_children().live() if in_menu is True: q = q.in_menu() return q def resolve_sibling_pages(self, info, in_menu=None): q = self.get_siblings().specific().live() if in_menu is True: q = q.in_menu() return q def resolve_ancestor_pages(self, info, in_menu=None): q = self.get_ancestors().specific().live() if in_menu is True: q = q.in_menu() return q def resolve_ancestor_pages_generic(self, info, in_menu=None): q = self.get_ancestors().live() if in_menu is True: q = q.in_menu() return q def resolve_closest_ancestor_of_type(self, info, content_type=None, inclusive=False): try: return self.get_ancestors(inclusive).specific().type( name_to_class_map[content_type]).last() except IndexError: return None def resolve_closest_ancestor_of_type_generic(self, info, content_type=None, inclusive=False): try: return self.get_ancestors(inclusive).type( name_to_class_map[content_type]).last() except IndexError: return None @classmethod def resolve_type(cls, instance, info): name = instance.__class__.__name__ if name in page_types_map: return page_types_map[name] return GenericPage
class AdvertDisplayInput(graphene.InputObjectType): user_id = graphene.String() advert_id = graphene.String() display_time = graphene.DateTime()
class PageInterface(graphene.Interface): id = graphene.ID() url = graphene.String() url_path = graphene.String() slug = graphene.String() depth = graphene.Int() page_type = graphene.String() title = graphene.String() seo_title = graphene.String() seo_description = graphene.String() show_in_menus = graphene.Boolean() content_type = graphene.String() tags = TagList() last_published_at = graphene.DateTime() parent = graphene.Field(lambda: PageInterface) children = QuerySetList(lambda: PageInterface, enable_search=True) siblings = QuerySetList(lambda: PageInterface, enable_search=True) next_siblings = QuerySetList(lambda: PageInterface, enable_search=True) previous_siblings = QuerySetList(lambda: PageInterface, enable_search=True) descendants = QuerySetList(lambda: PageInterface, enable_search=True) ancestors = QuerySetList(lambda: PageInterface, enable_search=True) def resolve_content_type(self, info: ResolveInfo): self.content_type = ContentType.objects.get_for_model(self) return (self.content_type.app_label + "." + self.content_type.model_class().__name__) @classmethod def resolve_type(cls, instance, info: ResolveInfo): """ If model has a custom Graphene Node type in registry then use it, otherwise use base page type. """ mdl = type(instance) if mdl in registry.pages: return registry.pages[mdl] else: return Page def resolve_parent(self, info, **kwargs): """ Resolves the parent node of current page node. Docs: http://docs.wagtail.io/en/v2.5.1/reference/pages/model_reference.html?highlight=get_parent#wagtail.core.models.Page.get_parent """ return resolve_queryset(self.get_parent().specific(), info, **kwargs) def resolve_children(self, info, **kwargs): """ Resolves a list of live children of this page with `show_in_menus` set. Docs: http://docs.wagtail.io/en/v2.5.1/reference/pages/queryset_reference.html#examples """ return resolve_queryset(self.get_children().specific(), info, **kwargs) def resolve_siblings(self, info, **kwargs): """ Resolves a list of sibling nodes to this page. Docs: http://docs.wagtail.io/en/v2.5.1/reference/pages/queryset_reference.html?highlight=get_siblings#wagtail.core.query.PageQuerySet.sibling_of """ return resolve_queryset( self.get_siblings().exclude(pk=self.pk).specific(), info, **kwargs) def resolve_next_siblings(self, info, **kwargs): """ Resolves a list of direct next siblings of this page. Similar to `resolve_siblings` with sorting. Source: https://github.com/wagtail/wagtail/blob/master/wagtail/core/models.py#L1384 """ return resolve_queryset( self.get_next_siblings().exclude(pk=self.pk).specific(), info, **kwargs) def resolve_prev_siblings(self, info, **kwargs): """ Resolves a list of direct prev siblings of this page. Similar to `resolve_siblings` with sorting. Source: https://github.com/wagtail/wagtail/blob/master/wagtail/core/models.py#L1387 """ return resolve_queryset( self.get_prev_siblings().exclude(pk=self.pk).specific(), info, **kwargs) def resolve_ancestors(self, info, **kwargs): """ Resolves a list of nodes pointing to the current page’s ancestors. Docs: https://docs.wagtail.io/en/v2.5.1/reference/pages/model_reference.html?highlight=get_ancestors#wagtail.core.models.Page.get_ancestors """ return resolve_queryset(self.get_ancestors().specific(), info, **kwargs) def resolve_seo_title(self, info): """ Get page's SEO title. Fallback to a normal page's title if absent. """ return self.seo_title or self.title
class CreateJob(graphene.Mutation): id = graphene.String() company = graphene.Field(CompanyType) location = graphene.Field(CityType) link = graphene.String() contact_email = graphene.Field(EmployerType) role = graphene.Field(RoleType) approved = graphene.Boolean() created_date = graphene.DateTime() class Arguments: company = graphene.String() location = graphene.String() link = graphene.String() contact_email = graphene.String() role = graphene.String() def mutate(self, info, **kwargs): try: if Employer.objects.filter( email=kwargs.get("contact_email")).exists(): _employer = Employer.objects.get( email=kwargs.get("contact_email")) else: _employer = Employer.objects.create( email=kwargs.get("contact_email")) if not _employer: raise Exception(ModelExceptionTypes.EMPLOYER) if Company.objects.filter(name=kwargs.get("company")).exists(): _company = Company.objects.get(name=kwargs.get("company")) else: _company = Company.objects.create(name=kwargs.get("company")) if not _company: raise Exception(ModelExceptionTypes.COMPANY) _city = City.objects.get(id=kwargs.get("location")) if not _city: raise Exception(ModelExceptionTypes.CITY) if Role.objects.filter(name=kwargs.get("role")).exists(): _role = Role.objects.get(name=kwargs.get("role")) else: _role = Role.objects.create(name=kwargs.get("role")) if not _role: raise Exception(ModelExceptionTypes.ROLE) _job = Job.objects.create( company=_company, location=_city, link_to_desc=kwargs.get("link"), contact_email=_employer, role=_role, approved=False, ) if not _job: raise Exception(ModelExceptionTypes.JOB) return CreateJob( id=_job.id, company=_job.company, location=_job.location, link=_job.link_to_desc, contact_email=_job.contact_email, role=_job.role, approved=_job.approved, created_date=_job.created_date, ) except Exception as error: if error == ModelExceptionTypes.EMPLOYER: raise Exception("Create 'Employer' failed") elif error == ModelExceptionTypes.COMPANY: raise Exception("Create 'Company' failed") elif error == ModelExceptionTypes.CITY: raise Exception("Create 'City' failed") elif error == ModelExceptionTypes.ROLE: raise Exception("Create 'Role' failed") elif error == ModelExceptionTypes.JOB: raise Exception("Create 'Job' failed") else: raise Exception("Created 'Other' failed | " + str(error))
class User(ModelObjectType): id = graphene.GlobalID(required=True) email = graphene.String(required=True) first_name = graphene.String(required=True) last_name = graphene.String(required=True) is_staff = graphene.Boolean(required=True) is_active = graphene.Boolean(required=True) addresses = NonNullList(Address, description="List of all user's addresses.") checkout = graphene.Field( Checkout, description="Returns the last open checkout of this user.", deprecation_reason=( f"{DEPRECATED_IN_3X_FIELD} " "Use the `checkoutTokens` field to fetch the user checkouts." ), ) checkout_tokens = NonNullList( UUID, description="Returns the checkout UUID's assigned to this user.", channel=graphene.String( description="Slug of a channel for which the data should be returned." ), deprecation_reason=(f"{DEPRECATED_IN_3X_FIELD} Use `checkoutIds` instead."), ) checkout_ids = NonNullList( graphene.ID, description="Returns the checkout ID's assigned to this user.", channel=graphene.String( description="Slug of a channel for which the data should be returned." ), ) gift_cards = ConnectionField( "saleor.graphql.giftcard.types.GiftCardCountableConnection", description="List of the user gift cards.", ) note = PermissionsField( graphene.String, description="A note about the customer.", permissions=[AccountPermissions.MANAGE_USERS, AccountPermissions.MANAGE_STAFF], ) orders = ConnectionField( "saleor.graphql.order.types.OrderCountableConnection", description=( "List of user's orders. Requires one of the following permissions: " f"{AccountPermissions.MANAGE_STAFF.name}, " f"{AuthorizationFilters.OWNER.name}." ), ) user_permissions = NonNullList( UserPermission, description="List of user's permissions." ) permission_groups = NonNullList( "saleor.graphql.account.types.Group", description="List of user's permission groups.", ) editable_groups = NonNullList( "saleor.graphql.account.types.Group", description="List of user's permission groups which user can manage.", ) avatar = graphene.Field(Image, size=graphene.Int(description="Size of the avatar.")) events = PermissionsField( NonNullList(CustomerEvent), description="List of events associated with the user.", permissions=[AccountPermissions.MANAGE_USERS, AccountPermissions.MANAGE_STAFF], ) stored_payment_sources = NonNullList( "saleor.graphql.payment.types.PaymentSource", description="List of stored payment sources.", channel=graphene.String( description="Slug of a channel for which the data should be returned." ), ) language_code = graphene.Field( LanguageCodeEnum, description="User language code.", required=True ) default_shipping_address = graphene.Field(Address) default_billing_address = graphene.Field(Address) last_login = graphene.DateTime() date_joined = graphene.DateTime(required=True) updated_at = graphene.DateTime(required=True) class Meta: description = "Represents user data." interfaces = [relay.Node, ObjectWithMetadata] model = get_user_model() @staticmethod def resolve_addresses(root: models.User, _info): return root.addresses.annotate_default(root).all() # type: ignore @staticmethod def resolve_checkout(root: models.User, _info): return get_user_checkout(root) @staticmethod @traced_resolver def resolve_checkout_tokens(root: models.User, info, channel=None): def return_checkout_tokens(checkouts): if not checkouts: return [] checkout_global_ids = [] for checkout in checkouts: checkout_global_ids.append(checkout.token) return checkout_global_ids if not channel: return ( CheckoutByUserLoader(info.context) .load(root.id) .then(return_checkout_tokens) ) return ( CheckoutByUserAndChannelLoader(info.context) .load((root.id, channel)) .then(return_checkout_tokens) ) @staticmethod @traced_resolver def resolve_checkout_ids(root: models.User, info, channel=None): def return_checkout_ids(checkouts): if not checkouts: return [] checkout_global_ids = [] for checkout in checkouts: checkout_global_ids.append(to_global_id_or_none(checkout)) return checkout_global_ids if not channel: return ( CheckoutByUserLoader(info.context) .load(root.id) .then(return_checkout_ids) ) return ( CheckoutByUserAndChannelLoader(info.context) .load((root.id, channel)) .then(return_checkout_ids) ) @staticmethod def resolve_gift_cards(root: models.User, info, **kwargs): from ..giftcard.types import GiftCardCountableConnection def _resolve_gift_cards(gift_cards): return create_connection_slice( gift_cards, info, kwargs, GiftCardCountableConnection ) return ( GiftCardsByUserLoader(info.context).load(root.id).then(_resolve_gift_cards) ) @staticmethod def resolve_user_permissions(root: models.User, _info): from .resolvers import resolve_permissions return resolve_permissions(root) @staticmethod def resolve_permission_groups(root: models.User, _info): return root.groups.all() @staticmethod def resolve_editable_groups(root: models.User, _info): return get_groups_which_user_can_manage(root) @staticmethod def resolve_note(root: models.User, info): return root.note @staticmethod def resolve_events(root: models.User, info): return CustomerEventsByUserLoader(info.context).load(root.id) @staticmethod def resolve_orders(root: models.User, info, **kwargs): from ..order.types import OrderCountableConnection def _resolve_orders(orders): requester = get_user_or_app_from_context(info.context) if not requester.has_perm(OrderPermissions.MANAGE_ORDERS): # allow fetch requestor orders (except drafts) if root == info.context.user: orders = [ order for order in orders if order.status != OrderStatus.DRAFT ] else: raise PermissionDenied( permissions=[ AuthorizationFilters.OWNER, OrderPermissions.MANAGE_ORDERS, ] ) return create_connection_slice( orders, info, kwargs, OrderCountableConnection ) return OrdersByUserLoader(info.context).load(root.id).then(_resolve_orders) @staticmethod def resolve_avatar(root: models.User, info, size=None): if root.avatar: return Image.get_adjusted( image=root.avatar, alt=None, size=size, rendition_key_set="user_avatars", info=info, ) @staticmethod def resolve_stored_payment_sources(root: models.User, info, channel=None): from .resolvers import resolve_payment_sources if root == info.context.user: return resolve_payment_sources(info, root, channel_slug=channel) raise PermissionDenied(permissions=[AuthorizationFilters.OWNER]) @staticmethod def resolve_language_code(root, _info): return LanguageCodeEnum[str_to_enum(root.language_code)] @staticmethod def __resolve_references(roots: List["User"], info): from .resolvers import resolve_users ids = set() emails = set() for root in roots: if root.id is not None: ids.add(root.id) else: emails.add(root.email) users = list(resolve_users(info, ids=ids, emails=emails)) users_by_id = {user.id: user for user in users} users_by_email = {user.email: user for user in users} results = [] for root in roots: if root.id is not None: _, user_id = from_global_id_or_error(root.id, User) results.append(users_by_id.get(int(user_id))) else: results.append(users_by_email.get(root.email)) return results
class Arguments: instructor_id = graphene.ID(name='instructor') start_datetime = graphene.DateTime(required=True) end_datetime = graphene.DateTime(required=True) description = graphene.String()
class Override(EntityObjectType): class Meta: default_resolver = find_resolver end_time = graphene.DateTime() active = graphene.Boolean() in_use = graphene.Boolean() orphan = graphene.Boolean() writable = graphene.Boolean() hosts = graphene.List(graphene.String) port = graphene.String() name = graphene.String() owner = graphene.String() text = graphene.String() severity = SeverityType() new_severity = SeverityType() nvt = graphene.Field(NVT) task = graphene.Field(Task) result = graphene.Field(Result) @staticmethod def resolve_name(root, _info): raise GraphQLError(f'Cannot query field "{_info.field_name}"' f' on type "{_info.parent_type}".') @staticmethod def resolve_end_time(root, _info): return get_datetime_from_element(root, 'end_time') @staticmethod def resolve_active(root, _info): return get_boolean_from_element(root, 'active') @staticmethod def resolve_orphan(root, _info): return get_boolean_from_element(root, 'orphan') @staticmethod def resolve_text(root, _info): return get_text_from_element(root, 'text') @staticmethod def resolve_hosts(root, _info): hosts = get_text_from_element(root, 'hosts') return csv_to_list(hosts) @staticmethod def resolve_port(root, _info): return get_text_from_element(root, 'port') @staticmethod def resolve_severity(root, _info): return get_text_from_element(root, 'severity') @staticmethod def resolve_new_severity(root, _info): return get_text_from_element(root, 'new_severity')
class ImageAttribute: filename = graphene.String(description="File name in image folder") id_recipe = graphene.ID(description="Global ID of associated recipe") date_added = graphene.DateTime(description="Date the image was added")
class TypeItem(graphene.ObjectType): model = models.lists.Item skin = graphene.Field(BaseTypeSkin) creation_date = graphene.DateTime()
class CVE(EntityObjectType): uuid = graphene.String(name='id') update_time = graphene.DateTime() score = graphene.Field(SeverityType) cvss_vector = graphene.String() cvss_v2_vector = graphene.Field(CVSSv2Vector) cvss_v3_vector = graphene.Field(CVSSv3Vector) description = graphene.String() products = graphene.List(graphene.String) refs = graphene.List(Refs) nvt_refs = graphene.List(NvtRef) cert_refs = graphene.List(CertRef) @staticmethod def resolve_uuid(root, _info): return root.get('id') @staticmethod def resolve_update_time(root, _info): return get_datetime_from_element(root, 'update_time') @staticmethod def resolve_cvss_vector(root, _info): cve = root.find('cve') if cve is not None: return get_text_from_element(cve, 'cvss_vector') return None @staticmethod def resolve_cvss_v2_vector(root, _info): entry = root.find('cve/raw_data/{*}entry') if entry is not None: return entry.find('{*}cvss/{*}base_metrics') return None @staticmethod def resolve_cvss_v3_vector(root, _info): entry = root.find('cve/raw_data/{*}entry') if entry is not None: return entry.find('{*}cvss3/{*}base_metrics') return None @staticmethod def resolve_score(root, _info): cve = root.find('cve') if cve is not None: return get_text_from_element(cve, 'score') return None @staticmethod def resolve_description(root, _info): return get_text_from_element(root.find('cve'), 'description') @staticmethod def resolve_products(root, _info): cve = root.find('cve') if cve is not None: products = get_text_from_element(cve, 'products') if products is not None: return products.rstrip().split(' ') return None @staticmethod def resolve_nvt_refs(root, _info): nvts = root.find('cve/nvts') if nvts is not None: return nvts.findall('nvt') return None @staticmethod def resolve_cert_refs(root, _info): cert = root.find('cve/cert') if cert is not None: return cert.findall('cert_ref') return None @staticmethod def resolve_refs(root, _info): entry = root.find('cve/raw_data/{*}entry') if entry is not None: refs = entry.findall('{*}references') if len(refs) > 0: return refs return None
class SpreadChartDataType(graphene.ObjectType): timestamp = graphene.DateTime() buy_spread = graphene.Float() sell_spread = graphene.Float() pair = graphene.Int()
class User(graphene.ObjectType): id=graphene.ID() username=graphene.String() last_login=graphene.DateTime(required=False)
def convert_field_to_datetime(field, registry=None): return graphene.DateTime(description=get_field_description( field, registry), required=field.required)
class NVT(EntityObjectType): """Definition of a secinfo NVT (API call: get_info/get_info_list)""" uuid = graphene.String(name='id', description='OID of the vulnerability') update_time = graphene.DateTime( description='Time stamp of the last update of the vulnerability') # Not sure if this is needed anymore cvss_base = graphene.Field(SeverityType) score = graphene.Int( description='Describes the severity of this vulnerability') family = graphene.String() tags = graphene.Field(NvtTags) category = graphene.Int() preference_count = graphene.Int() timeout = graphene.Int() default_timeout = graphene.Int() qod = graphene.Field(NvtDefinitionQod, description='Quality of detection for this NVT') severities = graphene.List( NvtSeverity, description='Severities List to related sec infos') reference_warning = graphene.String( description='Warning if the CERT DB is not available') other_references = graphene.List( NvtReference, description='Other references List to related sec infos') cve_references = graphene.List( NvtReference, description='CVE references List to related sec infos') bid_references = graphene.List( NvtReference, description='Bugtraq references List to related sec infos') cert_references = graphene.List( NvtReference, description='CERT references List to related sec infos') preferences = graphene.List(NvtPreference, description='List of preferences for this NVT') solution = graphene.Field(NvtSolution, description='Fix solution for this NVT') def resolve_uuid(root, _info): return root.get('id') def resolve_update_time(root, _info): return get_datetime_from_element(root, 'update_time') def resolve_family(root, _info): nvt = root.find('nvt') if nvt is not None: return get_text_from_element(nvt, 'family') return None def resolve_cvss_base(root, _info): nvt = root.find('nvt') if nvt is not None: return get_text_from_element(nvt, 'cvss_base') return None def resolve_score(root, _info): severities = root.find('nvt/severities') if severities is not None: return severities.get('score') def resolve_tags(root, _info): nvt = root.find('nvt') if nvt is not None: return nvt.find('tags') return None def resolve_category(root, _info): nvt = root.find('nvt') if nvt is not None: return get_int_from_element(nvt, 'category') def resolve_preference_count(root, _info): nvt = root.find('nvt') if nvt is not None: return get_int_from_element(nvt, 'preference_count') def resolve_timeout(root, _info): nvt = root.find('nvt') if nvt is not None: return get_int_from_element(nvt, 'timeout') def resolve_default_timeout(root, _info): nvt = root.find('nvt') if nvt is not None: return get_int_from_element(nvt, 'default_timeout') def resolve_qod(root, _info): nvt = root.find('nvt') if nvt is not None: return nvt.find('qod') def resolve_severities(root, _info): severities = root.find('nvt/severities') if severities is not None: return severities.findall('severity') def resolve_other_references(root, _info): refs = root.find('nvt/refs') if refs is not None: return [ ref for ref in refs.findall('ref') if ref.get('type') == 'url' ] def resolve_cert_references(root, _info): refs = root.find('nvt/refs') if refs is not None: return [ ref for ref in refs.findall('ref') if (ref.get('type') == 'dfn-cert' or ref.get('type') == 'cert-bund') ] def resolve_bid_references(root, _info): refs = root.find('nvt/refs') if refs is not None: return [ ref for ref in refs.findall('ref') if (ref.get('type') == 'bid' or ref.get('type') == 'bugtraq_id' ) ] def resolve_cve_references(root, _info): refs = root.find('nvt/refs') if refs is not None: return [ ref for ref in refs.findall('ref') if (ref.get('type') == 'cve' or ref.get('type') == 'cve_id') ] def resolve_reference_warning(root, _info): refs = root.find('nvt/refs') if refs is not None: return get_text_from_element(refs, 'warning') def resolve_preferences(root, _info): preferences = root.find('nvt/preferences') if preferences is not None: return preferences.findall('preference') def resolve_solution(root, _info): nvt = root.find('nvt') if nvt is not None: return nvt.find('solution')
class Arguments: id = graphene.ID(required=True) title = graphene.String(required=False) description = graphene.String(required=False) author = graphene.String(required=False) created_at = graphene.DateTime(required=False)
class DateTimeRangeInput(graphene.InputObjectType): gte = graphene.DateTime(description="Start date.", required=False) lte = graphene.DateTime(description="End date.", required=False)
class Arguments: name = graphene.String(required=True) deadline = graphene.DateTime(required=False) taskcard = graphene.Int(required=True)
class User(graphene.ObjectType): id = graphene.ID() username = graphene.String() created_at = graphene.DateTime()
class Arguments: id = graphene.Int(required=True) card_id = graphene.Int(required=True) name = graphene.String(required=False) deadline = graphene.DateTime(required=False) done = graphene.Boolean(required=False)
class HostIdentifier(BaseObjectType): value = graphene.String() creation_time = graphene.DateTime() modification_time = graphene.DateTime() source_id = graphene.String() source_name = graphene.String() source_type = graphene.String() source_data = graphene.String() source_deleted = graphene.Boolean() os_id = graphene.String() os_title = graphene.String() def resolve_value(root, _info): return get_text_from_element(root, 'value') def resolve_creation_time(root, _info): return get_datetime_from_element(root, 'creation_time') def resolve_modification_time(root, _info): return get_datetime_from_element(root, 'creation_time') def resolve_source_id(root, _info): source = root.find('source') if source is not None: return parse_uuid(source.get('id')) return None def resolve_source_name(root, _info): source = root.find('source') if source is not None: return get_text_from_element(source, 'name') return None def resolve_source_type(root, _info): source = root.find('source') if source is not None: return get_text_from_element(source, 'type') return None def resolve_source_data(root, _info): source = root.find('source') if source is not None: return get_text_from_element(source, 'data') return None def resolve_source_deleted(root, _info): source = root.find('source') if source is not None: return get_boolean_from_element(source, 'deleted') return None def resolve_os_id(root, _info): os = root.find('os') if os is not None: return parse_uuid(os.get('id')) return None def resolve_os_title(root, _info): os = root.find('os') if os is not None: return get_text_from_element(os, 'title') return None
class MessageChatType(graphene.ObjectType): id = graphene.String(description="Id") sender_id = graphene.String(description="Sender id") content = graphene.String(description="Content") created_at = graphene.DateTime(description="Create ad") media_data = graphene.List(MediaChatType, description="list of media")