<s> """<STR_LIT>""" <EOL> import atexit <EOL> from tempfile import mkdtemp <EOL> from shutil import rmtree <EOL> from OpenSSL . crypto import X509Extension <EOL> from twisted . python . filepath import FilePath <EOL> from pyrsistent import PClass , field <EOL> from . . ca import ( <EOL> RootCredential , ControlCredential , NodeCredential , UserCredential , <EOL> ) <EOL> def assert_has_extension ( test , credential , name , value ) : <EOL> """<STR_LIT>""" <EOL> expected = X509Extension ( name , False , value ) <EOL> x509 = credential . certificate . original <EOL> values = [ ] <EOL> for i in range ( x509 . get_extension_count ( ) ) : <EOL> extension = x509 . get_extension ( i ) <EOL> if extension . get_short_name ( ) == name : <EOL> values . append ( extension . get_data ( ) ) <EOL> test . assertIn ( expected . get_data ( ) , values ) <EOL> class CredentialSet ( PClass ) : <EOL> """<STR_LIT>""" <EOL> path = field ( ) <EOL> root = field ( ) <EOL> control = field ( ) <EOL> control_dns = field ( ) <EOL> user = field ( ) <EOL> node = field ( ) <EOL> @ staticmethod <EOL> def create ( ) : <EOL> """<STR_LIT>""" <EOL> directory = FilePath ( mkdtemp ( ) ) <EOL> atexit . register ( rmtree , directory . path ) <EOL> root = RootCredential . initialize ( directory , b"<STR_LIT>" ) <EOL> user = UserCredential . initialize ( directory , root , u"<STR_LIT>" ) <EOL> node = NodeCredential . initialize ( directory , root ) <EOL> control = ControlCredential . initialize ( directory , root , b"<STR_LIT:127.0.0.1>" ) <EOL> control_dns = ControlCredential . initialize ( <EOL> directory , root , b"<STR_LIT:localhost>" ) <EOL> return CredentialSet ( path = directory , <EOL> root = root , user = user , node = node , control = control , <EOL> control_dns = control_dns ) <EOL> def copy_to ( self , directory , control = False , user = False , node = False ) : <EOL> """<STR_LIT>""" <EOL> self . path . child ( b"<STR_LIT>" ) . copyTo ( directory . child ( b"<STR_LIT>" ) ) <EOL> if control : <EOL> self . path . child ( b"<STR_LIT>" ) . copyTo ( <EOL> directory . child ( b"<STR_LIT>" ) ) <EOL> self . path . child ( b"<STR_LIT>" ) . copyTo ( <EOL> directory . child ( b"<STR_LIT>" ) ) <EOL> if user : <EOL> self . path . child ( b"<STR_LIT>" ) . copyTo ( <EOL> directory . child ( b"<STR_LIT>" ) ) <EOL> self . path . child ( b"<STR_LIT>" ) . copyTo ( <EOL> directory . child ( b"<STR_LIT>" ) ) <EOL> if node : <EOL> uuid = self . node . uuid <EOL> self . path . child ( b"<STR_LIT>" . format ( uuid ) ) . copyTo ( <EOL> directory . child ( b"<STR_LIT>" ) ) <EOL> self . path . child ( b"<STR_LIT>" . format ( uuid ) ) . copyTo ( <EOL> directory . child ( b"<STR_LIT>" ) ) <EOL> _credential_set1 = None <EOL> _credential_set2 = None <EOL> def get_credential_sets ( ) : <EOL> """<STR_LIT>""" <EOL> global _credential_set2 <EOL> global _credential_set1 <EOL> if _credential_set1 is None : <EOL> _credential_set1 = CredentialSet . create ( ) <EOL> _credential_set2 = CredentialSet . create ( ) <EOL> return _credential_set1 , _credential_set2 </s>
