<s> """<STR_LIT>""" <EOL> import re <EOL> from os import path <EOL> from json import dumps as dict_to_str , loads as str_to_dict <EOL> from cafe . engine . models . base import AutoMarshallingModel <EOL> class Secret ( AutoMarshallingModel ) : <EOL> def __init__ ( self , name = None , expiration = None , algorithm = None , <EOL> bit_length = None , mode = None , payload_content_type = None , <EOL> payload = None , content_types = None , <EOL> payload_content_encoding = None ) : <EOL> super ( Secret , self ) . __init__ ( ) <EOL> self . name = name <EOL> self . payload_content_type = payload_content_type <EOL> self . expiration = expiration <EOL> self . algorithm = algorithm <EOL> self . bit_length = bit_length <EOL> self . mode = mode <EOL> self . payload = payload <EOL> self . content_types = content_types <EOL> self . payload_content_encoding = payload_content_encoding <EOL> def _obj_to_json ( self ) : <EOL> return dict_to_str ( self . _obj_to_dict ( ) ) <EOL> def _obj_to_dict ( self ) : <EOL> """<STR_LIT>""" <EOL> converted = { } <EOL> if self . name is not None : <EOL> converted [ '<STR_LIT:name>' ] = self . name <EOL> if self . payload_content_type is not None : <EOL> converted [ '<STR_LIT>' ] = self . payload_content_type <EOL> if self . expiration is not None : <EOL> converted [ '<STR_LIT>' ] = self . expiration <EOL> if self . algorithm is not None : <EOL> converted [ '<STR_LIT>' ] = self . algorithm <EOL> if self . bit_length is not None : <EOL> converted [ '<STR_LIT>' ] = self . bit_length <EOL> if self . mode is not None : <EOL> converted [ '<STR_LIT>' ] = self . mode <EOL> if self . payload is not None : <EOL> converted [ '<STR_LIT>' ] = self . payload <EOL> if self . content_types is not None : <EOL> converted [ '<STR_LIT>' ] = self . content_types <EOL> if self . payload_content_encoding is not None : <EOL> converted [ '<STR_LIT>' ] = self . payload_content_encoding <EOL> return converted <EOL> @ classmethod <EOL> def _json_to_obj ( cls , serialized_str ) : <EOL> json_dict = str_to_dict ( serialized_str ) <EOL> return cls . _dict_to_obj ( json_dict ) <EOL> @ classmethod <EOL> def _dict_to_obj ( cls , json_dict ) : <EOL> """<STR_LIT>""" <EOL> return Secret ( ** json_dict ) <EOL> class SecretMetadata ( Secret ) : <EOL> def __init__ ( self , name , expiration , algorithm , bit_length , mode , <EOL> payload_content_type = None , payload = None , status = None , <EOL> updated = None , created = None , secret_ref = None , <EOL> content_types = None , content_encodings = None ) : <EOL> super ( SecretMetadata , self ) . __init__ ( name , expiration , algorithm , <EOL> bit_length , mode , <EOL> payload_content_type , <EOL> payload , content_types , <EOL> content_encodings ) <EOL> self . status = status <EOL> self . updated = updated <EOL> self . created = created <EOL> self . secret_ref = secret_ref <EOL> def __eq__ ( self , other ) : <EOL> return other . secret_ref == self . secret_ref <EOL> def __ne__ ( self , other ) : <EOL> return not self == other <EOL> def get_id ( self ) : <EOL> """<STR_LIT>""" <EOL> ref_id = None <EOL> if self . secret_ref is not None and len ( self . secret_ref ) > <NUM_LIT:0> : <EOL> ref_id = path . split ( self . secret_ref ) [ <NUM_LIT:1> ] <EOL> return ref_id <EOL> def _obj_to_dict ( self ) : <EOL> converted = super ( SecretMetadata , self ) . _obj_to_dict ( ) <EOL> if self . status is not None : <EOL> converted [ '<STR_LIT:status>' ] = self . status <EOL> if self . updated is not None : <EOL> converted [ '<STR_LIT>' ] = self . status <EOL> if self . created is not None : <EOL> converted [ '<STR_LIT>' ] = self . status <EOL> if self . secret_ref is not None : <EOL> converted [ '<STR_LIT>' ] = self . status <EOL> return converted <EOL> @ classmethod <EOL> def _dict_to_obj ( cls , json_dict ) : <EOL> return SecretMetadata ( ** json_dict ) <EOL> class SecretRef ( AutoMarshallingModel ) : <EOL> def __init__ ( self , reference ) : <EOL> super ( SecretRef , self ) . __init__ ( ) <EOL> self . reference = reference <EOL> @ classmethod <EOL> def _json_to_obj ( cls , serialized_str ) : <EOL> json_dict = str_to_dict ( serialized_str ) <EOL> return cls . _dict_to_obj ( json_dict ) <EOL> @ classmethod <EOL> def _dict_to_obj ( cls , json_dict ) : <EOL> return SecretRef ( reference = json_dict . get ( '<STR_LIT>' ) ) <EOL> class UpdateSecret ( AutoMarshallingModel ) : <EOL> def __init__ ( self , payload ) : <EOL> super ( UpdateSecret , self ) . __init__ ( ) <EOL> self . payload = payload <EOL> def _obj_to_json ( self ) : <EOL> return dict_to_str ( self . _obj_to_dict ( ) ) <EOL> def _obj_to_dict ( self ) : <EOL> return { '<STR_LIT>' : self . payload } <EOL> class SecretGroup ( AutoMarshallingModel ) : <EOL> def __init__ ( self , secrets , next_list = None , previous_list = None ) : <EOL> super ( SecretGroup , self ) . __init__ ( ) <EOL> self . secrets = secrets <EOL> self . next = next_list <EOL> self . previous = previous_list <EOL> def get_ids ( self ) : <EOL> return [ sec . get_id ( ) for sec in self . secrets ] <EOL> def get_next_query_data ( self ) : <EOL> matches = re . search ( '<STR_LIT>' , self . next ) <EOL> return { <EOL> '<STR_LIT>' : matches . group ( <NUM_LIT:2> ) , <EOL> '<STR_LIT>' : matches . group ( <NUM_LIT:4> ) <EOL> } <EOL> @ classmethod <EOL> def _json_to_obj ( cls , serialized_str ) : <EOL> json_dict = str_to_dict ( serialized_str ) <EOL> return cls . _dict_to_obj ( json_dict ) <EOL> @ classmethod <EOL> def _dict_to_obj ( cls , json_dict ) : <EOL> secrets , next_list , prev_list = [ ] , None , None <EOL> for secret_dict in json_dict . get ( '<STR_LIT>' ) : <EOL> secrets . append ( SecretMetadata . _dict_to_obj ( secret_dict ) ) <EOL> if '<STR_LIT>' in json_dict : <EOL> next_list = json_dict . get ( '<STR_LIT>' ) <EOL> if '<STR_LIT>' in json_dict : <EOL> prev_list = json_dict . get ( '<STR_LIT>' ) <EOL> return SecretGroup ( secrets , next_list , prev_list ) </s>
