client-python icon indicating copy to clipboard operation
client-python copied to clipboard

Methods' arguments are not consistent (**kwargs)

Open axelfahy opened this issue 2 years ago • 1 comments

Description

Lots of methods in the pycti library uses a variable number of keyword arguments (**kwargs). However, some of those arguments are in snake_case and others in camelCase, making it really error-prone. Let's take, for example, the create method of the Identity class (opencti_identity.py file):

    def create(self, **kwargs):
        type = kwargs.get("type", None)
        stix_id = kwargs.get("stix_id", None)
        created_by = kwargs.get("createdBy", None)
        object_marking = kwargs.get("objectMarking", None)
        object_label = kwargs.get("objectLabel", None)
        external_references = kwargs.get("externalReferences", None)
        revoked = kwargs.get("revoked", None)
        confidence = kwargs.get("confidence", None)
        lang = kwargs.get("lang", None)
        created = kwargs.get("created", None)
        modified = kwargs.get("modified", None)
        name = kwargs.get("name", None)
        description = kwargs.get("description", "")
        contact_information = kwargs.get("contact_information", None)
        roles = kwargs.get("roles", None)
        x_opencti_aliases = kwargs.get("x_opencti_aliases", None)
        x_opencti_organization_type = kwargs.get("x_opencti_organization_type", None)
        x_opencti_reliability = kwargs.get("x_opencti_reliability", None)
        x_opencti_firstname = kwargs.get("x_opencti_firstname", None)
        x_opencti_lastname = kwargs.get("x_opencti_lastname", None)
        x_opencti_stix_ids = kwargs.get("x_opencti_stix_ids", None)
        update = kwargs.get("update", False)

For example, stix_id is snake_case, but createdBy is camelCase. Is there a specific reason for having some of the arguements in camelCase (Python naming style from pep8 does not use camelCase for variable names)?

It is interesting to note that even if an argument is camelCase, it is assigned to a variable being snake_case when retrieving the keyword argument.

This inconsistency is visible in most of the files of the pycti library.

Environment

  1. OS (where OpenCTI server runs): not relevant
  2. OpenCTI version: pycti 5.5.2
  3. Other environment details:

axelfahy avatar Jan 17 '23 15:01 axelfahy

@SamuelHassine I'm not to deep into the python lib but has the reason something to do with generation or that some kwargs are directly used in the graphql api as input? By convention python uses snake as you probably know, but I think if the kwargs are directly used as input also camelcase can be used. But from a project perspective it would be good to have 1 style, at least for kwargs in the api. Further it would be really nice if the api would be documented, because it is really terrible to find it out for yourself if you have no idea. The examples are mostly more helpful then the current docs.

iFrozenPhoenix avatar Apr 05 '24 15:04 iFrozenPhoenix