<s> from __future__ import print_function <EOL> import logging <EOL> from boto import s3 <EOL> from boto . exception import S3ResponseError , S3CreateError <EOL> from boto . route53 . exception import DNSServerError <EOL> from cactus . deployment . engine import BaseDeploymentEngine <EOL> from cactus . deployment . s3 . auth import AWSCredentialsManager <EOL> from cactus . deployment . s3 . file import S3File <EOL> from cactus . deployment . s3 . domain import AWSBucket , AWSDomain <EOL> from cactus . exceptions import InvalidCredentials <EOL> from cactus . utils import ipc <EOL> logger = logging . getLogger ( __name__ ) <EOL> class S3DeploymentEngine ( BaseDeploymentEngine ) : <EOL> FileClass = S3File <EOL> CredentialsManagerClass = AWSCredentialsManager <EOL> config_bucket_name = "<STR_LIT>" <EOL> config_bucket_website = "<STR_LIT>" <EOL> config_bucket_region = "<STR_LIT>" <EOL> _s3_default_region = "<STR_LIT>" <EOL> _s3_port = <NUM_LIT> <EOL> _s3_is_secure = True <EOL> _s3_https_connection_factory = None <EOL> def _get_buckets ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return self . get_connection ( ) . get_all_buckets ( ) <EOL> except S3ResponseError as e : <EOL> if e . error_code == u'<STR_LIT>' : <EOL> logger . info ( "<STR_LIT>" , e . body ) <EOL> raise InvalidCredentials ( ) <EOL> raise <EOL> def _get_bucket_region ( self ) : <EOL> return self . site . config . get ( self . config_bucket_region , self . _s3_default_region ) <EOL> def _create_connection ( self ) : <EOL> """<STR_LIT>""" <EOL> aws_access_key , aws_secret_key = self . credentials_manager . get_credentials ( ) <EOL> return s3 . connect_to_region ( self . _get_bucket_region ( ) , <EOL> aws_access_key_id = aws_access_key . strip ( ) , <EOL> aws_secret_access_key = aws_secret_key . strip ( ) , <EOL> is_secure = self . _s3_is_secure , port = self . _s3_port , <EOL> https_connection_factory = self . _s3_https_connection_factory , <EOL> calling_format = '<STR_LIT>' <EOL> ) <EOL> def get_bucket ( self ) : <EOL> """<STR_LIT>""" <EOL> buckets = self . _get_buckets ( ) <EOL> buckets = dict ( ( bucket . name , bucket ) for bucket in buckets ) <EOL> return buckets . get ( self . bucket_name ) <EOL> def create_bucket ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> if self . _get_bucket_region ( ) == "<STR_LIT>" : <EOL> region = "<STR_LIT>" <EOL> else : <EOL> region = self . _get_bucket_region ( ) <EOL> bucket = self . get_connection ( ) . create_bucket ( self . bucket_name , <EOL> policy = '<STR_LIT>' , location = region <EOL> ) <EOL> except S3CreateError : <EOL> logger . info ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , self . bucket_name ) <EOL> return <EOL> bucket . configure_website ( self . _index_page , self . _error_page ) <EOL> return bucket <EOL> def get_website_endpoint ( self ) : <EOL> return self . bucket . get_website_endpoint ( ) <EOL> def domain_setup ( self ) : <EOL> bucket_name = self . site . config . get ( self . config_bucket_name ) <EOL> bucket_name = self . site . config . get ( self . config_bucket_name ) <EOL> if not bucket_name : <EOL> logger . warning ( "<STR_LIT>" ) <EOL> return <EOL> aws_access_key , aws_secret_key = self . credentials_manager . get_credentials ( ) <EOL> domain = AWSDomain ( aws_access_key , aws_secret_key , bucket_name ) <EOL> try : <EOL> domain . setup ( ) <EOL> except DNSServerError as e : <EOL> logger . debug ( e ) <EOL> ipc . signal ( "<STR_LIT>" , { "<STR_LIT>" : "<STR_LIT>" } ) <EOL> logger . error ( "<STR_LIT>" ) <EOL> logger . error ( e ) <EOL> def domain_list ( self ) : <EOL> bucket_name = self . site . config . get ( self . config_bucket_name ) <EOL> if not bucket_name : <EOL> logger . warning ( "<STR_LIT>" ) <EOL> return <EOL> aws_access_key , aws_secret_key = self . credentials_manager . get_credentials ( ) <EOL> domain = AWSDomain ( aws_access_key , aws_secret_key , bucket_name ) <EOL> try : <EOL> domain_list = domain . nameServers ( ) <EOL> except DNSServerError as e : <EOL> print ( e ) <EOL> ipc . signal ( "<STR_LIT>" , { "<STR_LIT>" : "<STR_LIT>" } ) <EOL> logger . error ( "<STR_LIT>" ) <EOL> logger . error ( e ) <EOL> return <EOL> if domain_list : <EOL> ipc . signal ( "<STR_LIT>" , { "<STR_LIT>" : domain_list } ) <EOL> for domain in domain_list : <EOL> logger . info ( domain ) <EOL> else : <EOL> logger . error ( "<STR_LIT>" ) <EOL> def domain_remove ( self ) : <EOL> pass </s>
