Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sdk update #428

Closed
wants to merge 5 commits into from
Closed

Sdk update #428

wants to merge 5 commits into from

Conversation

duboyal
Copy link

@duboyal duboyal commented Feb 23, 2024

Description

this allows nodes to be changed and saved based off the deep diff registry of changes

I will be updating the description on a more technical basis before merging

Changes

Known Issues

Notes

Checklist

  • My name is on the list of contributors (CONTRIBUTORS.md) in the pull request source branch.
  • I have updated the documentation to reflect my changes.
  • My code changes have been verified by automated tests and pass all relevant test scenarios.

Copy link

trunk-io bot commented Feb 23, 2024

Merging to develop in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

@duboyal duboyal changed the base branch from main to develop February 23, 2024 16:58
script_cript.py Outdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should not be part of the of the PR

from cript.nodes.primary_nodes.project import Project
from deepdiff import DeepDiff
import cript
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can't import cript here.
That's a circular import.

Be specific and import exactly what you need.

@@ -48,6 +56,16 @@ def _get_global_cached_api():
return _global_cached_api


# load from .env
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a good idea, this should be the API class.

@@ -484,6 +502,404 @@ def _check_initial_host_connection(self) -> None:
except Exception as exc:
raise CRIPTConnectionError(self.host, self._api_token) from exc

# ================ helpers ==============
@classmethod
def object_exists(cls, node: str, name: str):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use the api.search function to see if an object exist

return False, None

@staticmethod
def fetch_object_data(object_type: str, uuid: str):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be through paginator and search.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize, that this comment is not helpful at the moment, because I am refactoring the paginator.
but eventually, we should strive to not duplicate code paths that essentially do the same thing....

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@InnocentBug could you give a quick example where the call to the paginator would look like to retrieve an already existing node?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.

import cript

with cript.API() as cript_api: # Assumes you have the host and token in the environment.
    # If you know its uuid
    uuid_paginator = cript_api.search(node_type=cript.Project, search_mode=cript.SearchModes.UUID, value_to_search="e7381525-64b9-4849-a416-57aa1e09044f")
    project = next(uuid_paginator)
    print(project)

    # if you know its name
    exact_name_paginator = cript_api.search(node_type=cript.Material, search_mode=cript.SearchModes.EXACT_NAME, value_to_search="Sodium polystyrene sulfonate")
    material = next(exact_name_paginator)
    print(material)

return remaining_items

@staticmethod
def send_patch_request_for_node(parent_node=None, payload=None): # (self, base_url, entity_uuid, data, auth_token=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should not be a public function.
Users should never call this function.

Also, shouldn't be a static function, host, header etc. should be loaded from api class.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think here i will implement the capsule to resolve this

return response

@staticmethod
def send_delete_request_for_node(parent_node=None, payload=None): # (self, base_url, entity_uuid, data, auth_token=None):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be delete function of API.

Also not a static function.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here - implement capsule

return response

@staticmethod
def find_uuid_by_name_and_type(name, node_type):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use search and paginator.

return None

@classmethod
def create_node(cls, node_type, data):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should not be public.
Maybe and should be capsuled in api.save

response = requests.post(url, json=data, headers=headers)
return response

@classmethod
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a pulic API class.
Maybe in api.utils as private function if needed.

@duboyal duboyal closed this Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants