|
9 | 9 | from indykite_sdk.indykite.config.v1beta1 import model_pb2
|
10 | 10 | from indykite_sdk.model.token_status import ExternalTokenStatus
|
11 | 11 | from indykite_sdk.model.entity_matching_status import Status as EntityMatchingStatus
|
| 12 | +from indykite_sdk.model.trust_score_profile_dimension_name import Name as TrustScoreDimensionName |
| 13 | +from indykite_sdk.model.trust_score_profile_config import UpdateFrequency |
12 | 14 | from indykite_sdk.model.external_data_resolver_config_content_type import ContentType
|
13 | 15 | import indykite_sdk.utils.logger as logger
|
14 | 16 |
|
@@ -700,6 +702,150 @@ def entity_matching_pipeline_config_update(self, similarity_score_cutoff):
|
700 | 702 | return logger.logger_error(exception)
|
701 | 703 |
|
702 | 704 |
|
| 705 | +def trust_score_profile_config_create(self,node_classification, dimensions, schedule): |
| 706 | + """ |
| 707 | + create TrustScoreProfileConfig |
| 708 | + :param self: |
| 709 | + :param node_classification: string |
| 710 | + :param dimensions: array of TrustScoreDimension object |
| 711 | + :param schedule: TrustScoreProfileConfig.UpdateFrequency enum value |
| 712 | + :return: TrustScoreProfileConfig object |
| 713 | + """ |
| 714 | + sys.excepthook = logger.handle_excepthook |
| 715 | + try: |
| 716 | + schedule = self.validate_trust_score_profile_update_frequency(schedule) |
| 717 | + external_config = model_pb2.TrustScoreProfileConfig( |
| 718 | + node_classification=node_classification, |
| 719 | + dimensions=dimensions, |
| 720 | + schedule=schedule |
| 721 | + ) |
| 722 | + return external_config |
| 723 | + except Exception as exception: |
| 724 | + return logger.logger_error(exception) |
| 725 | + |
| 726 | + |
| 727 | +def trust_score_profile_config_update(self, dimensions, schedule): |
| 728 | + """ |
| 729 | + create TrustScoreProfileConfig |
| 730 | + :param self: |
| 731 | + :param dimensions: array of TrustScoreDimension object |
| 732 | + :param schedule: TrustScoreProfileConfig.UpdateFrequency enum value |
| 733 | + :return: TrustScoreProfileConfig object |
| 734 | + """ |
| 735 | + sys.excepthook = logger.handle_excepthook |
| 736 | + try: |
| 737 | + schedule = self.validate_trust_score_profile_update_frequency(schedule) |
| 738 | + external_config = model_pb2.TrustScoreProfileConfig( |
| 739 | + dimensions=dimensions, |
| 740 | + schedule=schedule |
| 741 | + ) |
| 742 | + return external_config |
| 743 | + except Exception as exception: |
| 744 | + return logger.logger_error(exception) |
| 745 | + |
| 746 | + |
| 747 | +def create_trust_score_profile_config_node(self, |
| 748 | + location, |
| 749 | + name, |
| 750 | + display_name, |
| 751 | + description, |
| 752 | + trust_score_profile_config): |
| 753 | + """ |
| 754 | + create trust score profile config node |
| 755 | + :param self: |
| 756 | + :param location: string gid id |
| 757 | + :param name: string pattern: ^[a-z](?:[-a-z0-9]{0,61}[a-z0-9])$ |
| 758 | + :param display_name: string |
| 759 | + :param description: string |
| 760 | + :param trust_score_profile_config: TrustScoreProfileConfig object |
| 761 | + :return: deserialized CreateConfigNode instance |
| 762 | + """ |
| 763 | + sys.excepthook = logger.handle_excepthook |
| 764 | + try: |
| 765 | + if trust_score_profile_config and not isinstance( |
| 766 | + trust_score_profile_config, |
| 767 | + model_pb2.TrustScoreProfileConfig): |
| 768 | + raise TypeError("TrustScoreProfileConfig must be an object") |
| 769 | + |
| 770 | + response = self.stub.CreateConfigNode( |
| 771 | + pb2.CreateConfigNodeRequest( |
| 772 | + location=location, |
| 773 | + name=name, |
| 774 | + display_name=wrappers.StringValue(value=display_name), |
| 775 | + description=wrappers.StringValue(value=description), |
| 776 | + trust_score_profile_config=trust_score_profile_config |
| 777 | + ) |
| 778 | + ) |
| 779 | + except Exception as exception: |
| 780 | + return logger.logger_error(exception) |
| 781 | + |
| 782 | + if not response: |
| 783 | + return None |
| 784 | + return CreateConfigNode.deserialize(response) |
| 785 | + |
| 786 | + |
| 787 | +def update_trust_score_profile_config_node(self, |
| 788 | + config_node_id, |
| 789 | + etag, |
| 790 | + display_name, |
| 791 | + description, |
| 792 | + trust_score_profile_config): |
| 793 | + """ |
| 794 | + update trust score profile |
| 795 | + :param self: |
| 796 | + :param config_node_id: string gid id |
| 797 | + :param etag: string |
| 798 | + :param display_name: string |
| 799 | + :param description: string |
| 800 | + :param trust_score_profile_config: TrustScoreProfileConfig object |
| 801 | + :return: deserialized UpdateConfigNode instance |
| 802 | + """ |
| 803 | + sys.excepthook = logger.handle_excepthook |
| 804 | + try: |
| 805 | + if trust_score_profile_config and not isinstance( |
| 806 | + trust_score_profile_config, |
| 807 | + model_pb2.TrustScoreProfileConfig): |
| 808 | + raise TypeError("TrustScoreProfileConfig must be an object") |
| 809 | + response = self.stub.UpdateConfigNode( |
| 810 | + pb2.UpdateConfigNodeRequest( |
| 811 | + id=config_node_id, |
| 812 | + etag=wrappers.StringValue(value=etag), |
| 813 | + display_name=wrappers.StringValue(value=display_name), |
| 814 | + description=wrappers.StringValue(value=description), |
| 815 | + trust_score_profile_config=trust_score_profile_config |
| 816 | + ) |
| 817 | + ) |
| 818 | + except Exception as exception: |
| 819 | + return logger.logger_error(exception) |
| 820 | + |
| 821 | + if not response: |
| 822 | + return None |
| 823 | + return UpdateConfigNode.deserialize(response) |
| 824 | + |
| 825 | + |
| 826 | +def trust_score_profile_config(self, node_classification, dimensions, schedule): |
| 827 | + |
| 828 | + """ |
| 829 | + create TrustScoreProfileConfig |
| 830 | + :param self: |
| 831 | + :param node_classification: string |
| 832 | + :param dimensions: array of TrustScoreDimension object |
| 833 | + :param schedule: TrustScoreProfileConfig.UpdateFrequency enum value |
| 834 | + :return: TrustScoreProfileConfig object |
| 835 | + """ |
| 836 | + sys.excepthook = logger.handle_excepthook |
| 837 | + try: |
| 838 | + schedule = self.validate_trust_score_profile_update_frequency(schedule) |
| 839 | + external_config = model_pb2.TrustScoreProfileConfig( |
| 840 | + node_classification=node_classification, |
| 841 | + dimensions=dimensions, |
| 842 | + schedule=schedule |
| 843 | + ) |
| 844 | + return external_config |
| 845 | + except Exception as exception: |
| 846 | + return logger.logger_error(exception) |
| 847 | + |
| 848 | + |
703 | 849 | def validate_data_points(self, data_points):
|
704 | 850 | """
|
705 | 851 | validate data_points requirement
|
@@ -795,6 +941,42 @@ def validate_entity_matching_status(self, status):
|
795 | 941 | return logger.logger_error(exception)
|
796 | 942 |
|
797 | 943 |
|
| 944 | +def validate_trust_score_profile_dimension(self, dimension): |
| 945 | + """ |
| 946 | + validate trust score profile dimension requirement |
| 947 | + :param self: |
| 948 | + :param dimension: number |
| 949 | + :return: dimension, none or error |
| 950 | + """ |
| 951 | + try: |
| 952 | + if not dimension: |
| 953 | + return None |
| 954 | + dimensions = [d.value for d in TrustScoreDimensionName] |
| 955 | + if dimension and dimension not in dimensions: |
| 956 | + raise TypeError("dimension must be a member of TrustScoreDimension.Name") |
| 957 | + return dimension |
| 958 | + except Exception as exception: |
| 959 | + return logger.logger_error(exception) |
| 960 | + |
| 961 | + |
| 962 | +def validate_trust_score_profile_update_frequency(self, update_frequency): |
| 963 | + """ |
| 964 | + validate trust score profile update_frequency requirement |
| 965 | + :param self: |
| 966 | + :param update_frequency: number |
| 967 | + :return: update_frequency, none or error |
| 968 | + """ |
| 969 | + try: |
| 970 | + if not update_frequency: |
| 971 | + return None |
| 972 | + update_frequencies = [d.value for d in UpdateFrequency] |
| 973 | + if update_frequency and update_frequency not in update_frequencies: |
| 974 | + raise TypeError("update_frequency must be a member of TrustScoreProfileConfig.UpdateFrequency") |
| 975 | + return update_frequency |
| 976 | + except Exception as exception: |
| 977 | + return logger.logger_error(exception) |
| 978 | + |
| 979 | + |
798 | 980 | def list_config_node_versions(self, id_config_node):
|
799 | 981 | """
|
800 | 982 | list config nodes versions of the specified config node
|
|
0 commit comments