<s> """<STR_LIT>""" <EOL> import re <EOL> from backend . decorators import required_roles , load , return_object , return_list , return_task , log <EOL> from rest_framework import viewsets <EOL> from rest_framework . permissions import IsAuthenticated <EOL> from ovs . lib . license import LicenseController <EOL> from ovs . dal . hybrids . license import License <EOL> from ovs . dal . lists . licenselist import LicenseList <EOL> class LicenseSet ( viewsets . ViewSet ) : <EOL> """<STR_LIT>""" <EOL> permission_classes = ( IsAuthenticated , ) <EOL> prefix = r'<STR_LIT>' <EOL> base_name = '<STR_LIT>' <EOL> @ log ( ) <EOL> @ required_roles ( [ '<STR_LIT>' ] ) <EOL> @ return_list ( License ) <EOL> @ load ( ) <EOL> def list ( self , component = None ) : <EOL> """<STR_LIT>""" <EOL> if component is None : <EOL> return LicenseList . get_licenses ( ) <EOL> return LicenseList . get_by_component ( component , return_as_list = True ) <EOL> @ log ( ) <EOL> @ required_roles ( [ '<STR_LIT>' ] ) <EOL> @ return_object ( License ) <EOL> @ load ( License ) <EOL> def retrieve ( self , license ) : <EOL> """<STR_LIT>""" <EOL> return license <EOL> @ log ( ) <EOL> @ required_roles ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> @ return_task ( ) <EOL> @ load ( ) <EOL> def create ( self , license_string , validate_only , registration_parameters = None ) : <EOL> """<STR_LIT>""" <EOL> if registration_parameters is None : <EOL> if validate_only is True : <EOL> return LicenseController . validate . delay ( license_string ) <EOL> if validate_only is False : <EOL> return LicenseController . apply . delay ( license_string ) <EOL> else : <EOL> invalid = [ ] <EOL> validation = { '<STR_LIT:name>' : '<STR_LIT>' , <EOL> '<STR_LIT:email>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : None , <EOL> '<STR_LIT>' : None } <EOL> for key in validation : <EOL> if key not in registration_parameters or ( validation [ key ] is not None and re . match ( validation [ key ] , registration_parameters [ key ] ) is None ) : <EOL> invalid . append ( key ) <EOL> if '<STR_LIT>' not in registration_parameters or not isinstance ( registration_parameters [ '<STR_LIT>' ] , bool ) : <EOL> invalid . append ( '<STR_LIT>' ) <EOL> if len ( invalid ) != <NUM_LIT:0> : <EOL> raise RuntimeError ( '<STR_LIT>' . format ( '<STR_LIT:U+002CU+0020>' . format ( invalid ) ) ) <EOL> return LicenseController . get_free_license . delay ( registration_parameters ) </s>
