@@ -756,6 +756,91 @@ def __repr__(self) -> str:
756
756
)
757
757
758
758
759
+ class TokenType (str , Enum ):
760
+ PERSONAL_ACCESS_TOKEN = "personal_access_token"
761
+ SERVICE_ACCOUNT = "service_account"
762
+
763
+
764
+ class TokenStatus (str , Enum ):
765
+ ACTIVE = "active"
766
+ EXPIRED = "expired"
767
+ REVOKED = "revoked"
768
+
769
+
770
+ class TokenScopes (str , Enum ):
771
+ SCAN = "scan"
772
+ INCIDENTS_READ = "incidents:read"
773
+ INCIDENTS_WRITE = "incidents:write"
774
+ INCIDENTS_SHARE = "incidents:share"
775
+ MEMBERS_READ = "members:read"
776
+ MEMBERS_WRITE = "members:write"
777
+ TEAMS_READ = "teams:read"
778
+ TEAMS_WRITE = "teams:write"
779
+ AUDIT_LOGS_READ = "audit_logs:read"
780
+ HONEYTOKENS_READ = "honeytokens:read"
781
+ HONEYTOKENS_WRITE = "honeytokens:write"
782
+ API_TOKENS_READ = "api_tokens:read"
783
+ API_TOKENS_WRITE = "api_tokens:write"
784
+ IP_ALLOWLIST_READ = "ip_allowlist:read"
785
+ IP_ALLOWLIST_WRITE = "ip_allowlist:write"
786
+ SOURCES_READ = "sources:read"
787
+ SOURCES_WRITE = "sources:write"
788
+ NHI_WRITE = "nhi:write"
789
+
790
+
791
+ class ApiTokensResponseSchema (BaseSchema ):
792
+ id = fields .UUID (required = True )
793
+ name = fields .String (required = True )
794
+ workspace_id = fields .Int (required = True )
795
+ type = fields .Enum (TokenType , by_value = True , required = True )
796
+ status = fields .Enum (TokenStatus , by_value = True , required = True )
797
+ created_at = fields .AwareDateTime (required = True )
798
+ last_used_at = fields .AwareDateTime (allow_none = True )
799
+ expire_at = fields .AwareDateTime (allow_none = True )
800
+ revoked_at = fields .AwareDateTime (allow_none = True )
801
+ member_id = fields .Int (allow_none = True )
802
+ creator_id = fields .Int (allow_none = True )
803
+ scopes = fields .List (fields .Enum (TokenScopes , by_value = True ), required = False )
804
+
805
+ @post_load
806
+ def make_api_tokens_response (
807
+ self , data : Dict [str , Any ], ** kwargs : Any
808
+ ) -> "ApiTokensResponse" :
809
+ return ApiTokensResponse (** data )
810
+
811
+
812
+ class ApiTokensResponse (Base , FromDictMixin ):
813
+ SCHEMA = ApiTokensResponseSchema ()
814
+
815
+ def __init__ (
816
+ self ,
817
+ id : UUID ,
818
+ name : str ,
819
+ workspace_id : int ,
820
+ type : TokenType ,
821
+ status : TokenStatus ,
822
+ created_at : datetime ,
823
+ last_used_at : Optional [datetime ] = None ,
824
+ expire_at : Optional [datetime ] = None ,
825
+ revoked_at : Optional [datetime ] = None ,
826
+ member_id : Optional [int ] = None ,
827
+ creator_id : Optional [int ] = None ,
828
+ scopes : Optional [List [TokenScopes ]] = None ,
829
+ ):
830
+ self .id = id
831
+ self .name = name
832
+ self .workspace_id = workspace_id
833
+ self .type = type
834
+ self .status = status
835
+ self .created_at = created_at
836
+ self .last_used_at = last_used_at
837
+ self .expire_at = expire_at
838
+ self .revoked_at = revoked_at
839
+ self .member_id = member_id
840
+ self .creator_id = creator_id
841
+ self .scopes = scopes or []
842
+
843
+
759
844
@dataclass
760
845
class SecretScanPreferences :
761
846
maximum_document_size : int = DOCUMENT_SIZE_THRESHOLD_BYTES
0 commit comments