idx int64 0 252k | question stringlengths 48 5.28k | target stringlengths 5 1.23k |
|---|---|---|
239,000 | def main ( ) : logging . basicConfig ( format = LOGGING_FORMAT ) parser = argparse . ArgumentParser ( description = main . __doc__ ) add_debug ( parser ) add_app ( parser ) add_env ( parser ) add_region ( parser ) args = parser . parse_args ( ) logging . getLogger ( __package__ . split ( '.' ) [ 0 ] ) . setLevel ( args... | Destroy any ELB related Resources . |
239,001 | def get_security_group_id ( name = '' , env = '' , region = '' ) : vpc_id = get_vpc_id ( env , region ) LOG . info ( 'Find %s sg in %s [%s] in %s' , name , env , region , vpc_id ) url = '{0}/securityGroups/{1}/{2}/{3}?vpcId={4}' . format ( API_URL , env , region , name , vpc_id ) response = requests . get ( url , verif... | Get a security group ID . |
239,002 | def remove_duplicate_sg ( security_groups ) : for each_sg , duplicate_sg_name in SECURITYGROUP_REPLACEMENTS . items ( ) : if each_sg in security_groups and duplicate_sg_name in security_groups : LOG . info ( 'Duplicate SG found. Removing %s in favor of %s.' , duplicate_sg_name , each_sg ) security_groups . remove ( dup... | Removes duplicate Security Groups that share a same name alias |
239,003 | def generate_encoded_user_data ( env = 'dev' , region = 'us-east-1' , generated = None , group_name = '' , pipeline_type = '' , canary = False , ) : r if env in [ "prod" , "prodp" , "prods" ] : env_c , env_p , env_s = "prod" , "prodp" , "prods" else : env_c , env_p , env_s = env , env , env user_data = get_template ( t... | r Generate base64 encoded User Data . |
239,004 | def prepare_infrastructure ( ) : runner = ForemastRunner ( ) runner . write_configs ( ) runner . create_app ( ) archaius = runner . configs [ runner . env ] [ 'app' ] [ 'archaius_enabled' ] eureka = runner . configs [ runner . env ] [ 'app' ] [ 'eureka_enabled' ] deploy_type = runner . configs [ 'pipeline' ] [ 'type' ]... | Entry point for preparing the infrastructure in a specific env . |
239,005 | def prepare_app_pipeline ( ) : runner = ForemastRunner ( ) runner . write_configs ( ) runner . create_app ( ) runner . create_pipeline ( ) runner . cleanup ( ) | Entry point for application setup and initial pipeline in Spinnaker . |
239,006 | def prepare_onetime_pipeline ( ) : runner = ForemastRunner ( ) runner . write_configs ( ) runner . create_pipeline ( onetime = os . getenv ( 'ENV' ) ) runner . cleanup ( ) | Entry point for single use pipeline setup in the defined app . |
239,007 | def write_configs ( self ) : utils . banner ( "Generating Configs" ) if not self . runway_dir : app_configs = configs . process_git_configs ( git_short = self . git_short ) else : app_configs = configs . process_runway_configs ( runway_dir = self . runway_dir ) self . configs = configs . write_variables ( app_configs =... | Generate the configurations needed for pipes . |
239,008 | def create_app ( self ) : utils . banner ( "Creating Spinnaker App" ) spinnakerapp = app . SpinnakerApp ( app = self . app , email = self . email , project = self . group , repo = self . repo , pipeline_config = self . configs [ 'pipeline' ] ) spinnakerapp . create_app ( ) | Create the spinnaker application . |
239,009 | def create_iam ( self ) : utils . banner ( "Creating IAM" ) iam . create_iam_resources ( env = self . env , app = self . app ) | Create IAM resources . |
239,010 | def create_archaius ( self ) : utils . banner ( "Creating S3" ) s3 . init_properties ( env = self . env , app = self . app ) | Create S3 bucket for Archaius . |
239,011 | def create_s3app ( self ) : utils . banner ( "Creating S3 App Infrastructure" ) primary_region = self . configs [ 'pipeline' ] [ 'primary_region' ] s3obj = s3 . S3Apps ( app = self . app , env = self . env , region = self . region , prop_path = self . json_path , primary_region = primary_region ) s3obj . create_bucket ... | Create S3 infra for s3 applications |
239,012 | def deploy_s3app ( self ) : utils . banner ( "Deploying S3 App" ) primary_region = self . configs [ 'pipeline' ] [ 'primary_region' ] s3obj = s3 . S3Deployment ( app = self . app , env = self . env , region = self . region , prop_path = self . json_path , artifact_path = self . artifact_path , artifact_version = self .... | Deploys artifacts contents to S3 bucket |
239,013 | def promote_s3app ( self ) : utils . banner ( "Promoting S3 App" ) primary_region = self . configs [ 'pipeline' ] [ 'primary_region' ] s3obj = s3 . S3Deployment ( app = self . app , env = self . env , region = self . region , prop_path = self . json_path , artifact_path = self . artifact_path , artifact_version = self ... | promotes S3 deployment to LATEST |
239,014 | def create_elb ( self ) : utils . banner ( "Creating ELB" ) elbobj = elb . SpinnakerELB ( app = self . app , env = self . env , region = self . region , prop_path = self . json_path ) elbobj . create_elb ( ) | Create the ELB for the defined environment . |
239,015 | def create_dns ( self ) : utils . banner ( "Creating DNS" ) elb_subnet = self . configs [ self . env ] [ 'elb' ] [ 'subnet_purpose' ] regions = self . configs [ self . env ] [ 'regions' ] failover = self . configs [ self . env ] [ 'dns' ] [ 'failover_dns' ] primary_region = self . configs [ 'pipeline' ] [ 'primary_regi... | Create DNS for the defined app and environment . |
239,016 | def create_autoscaling_policy ( self ) : utils . banner ( "Creating Scaling Policy" ) policyobj = autoscaling_policy . AutoScalingPolicy ( app = self . app , env = self . env , region = self . region , prop_path = self . json_path ) policyobj . create_policy ( ) | Create Scaling Policy for app in environment |
239,017 | def create_datapipeline ( self ) : utils . banner ( "Creating Data Pipeline" ) dpobj = datapipeline . AWSDataPipeline ( app = self . app , env = self . env , region = self . region , prop_path = self . json_path ) dpobj . create_datapipeline ( ) dpobj . set_pipeline_definition ( ) if self . configs [ self . env ] . get... | Creates data pipeline and adds definition |
239,018 | def slack_notify ( self ) : utils . banner ( "Sending slack notification" ) if self . env . startswith ( "prod" ) : notify = slacknotify . SlackNotification ( app = self . app , env = self . env , prop_path = self . json_path ) notify . post_message ( ) else : LOG . info ( "No slack message sent, not production environ... | Send out a slack notification . |
239,019 | def add_debug ( parser ) : parser . add_argument ( '-d' , '--debug' , action = 'store_const' , const = logging . DEBUG , default = logging . INFO , help = 'Set DEBUG output' ) | Add a debug flag to the _parser_ . |
239,020 | def add_env ( parser ) : parser . add_argument ( '-e' , '--env' , choices = ENVS , default = os . getenv ( 'ENV' , default = 'dev' ) , help = 'Deploy environment, overrides $ENV' ) | Add an env flag to the _parser_ . |
239,021 | def main ( ) : logging . basicConfig ( format = LOGGING_FORMAT ) log = logging . getLogger ( __name__ ) parser = argparse . ArgumentParser ( ) add_debug ( parser ) add_app ( parser ) add_properties ( parser ) add_env ( parser ) add_region ( parser ) args = parser . parse_args ( ) logging . getLogger ( __package__ . spl... | CLI entrypoint for scaling policy creation |
239,022 | def main ( ) : logging . basicConfig ( format = LOGGING_FORMAT ) log = logging . getLogger ( __name__ ) parser = argparse . ArgumentParser ( description = main . __doc__ ) add_debug ( parser ) add_app ( parser ) add_env ( parser ) add_properties ( parser ) add_region ( parser ) args = parser . parse_args ( ) logging . ... | Create Lambda events . |
239,023 | def post_slack_message ( message = None , channel = None , username = None , icon_emoji = None ) : LOG . debug ( 'Slack Channel: %s\nSlack Message: %s' , channel , message ) slack = slacker . Slacker ( SLACK_TOKEN ) try : slack . chat . post_message ( channel = channel , text = message , username = username , icon_emoj... | Format the message and post to the appropriate slack channel . |
239,024 | def destroy_dns ( app = '' , env = 'dev' , ** _ ) : client = boto3 . Session ( profile_name = env ) . client ( 'route53' ) generated = get_details ( app = app , env = env ) record = generated . dns_elb ( ) zone_ids = get_dns_zone_ids ( env = env , facing = 'external' ) for zone_id in zone_ids : record_sets = client . l... | Destroy DNS records . |
239,025 | def destroy_record ( client = None , found_record = None , record = '' , zone_id = '' ) : LOG . debug ( 'Found DNS record: %s' , found_record ) if found_record [ 'Name' ] . strip ( '.' ) == record : dns_json = get_template ( template_file = 'destroy/destroy_dns.json.j2' , record = json . dumps ( found_record ) ) dns_di... | Destroy an individual DNS record . |
239,026 | def create_sns_event ( app_name , env , region , rules ) : session = boto3 . Session ( profile_name = env , region_name = region ) sns_client = session . client ( 'sns' ) topic_name = rules . get ( 'topic' ) lambda_alias_arn = get_lambda_alias_arn ( app = app_name , account = env , region = region ) topic_arn = get_sns... | Create SNS lambda event from rules . |
239,027 | def destroy_sns_event ( app_name , env , region ) : session = boto3 . Session ( profile_name = env , region_name = region ) sns_client = session . client ( 'sns' ) lambda_subscriptions = get_sns_subscriptions ( app_name = app_name , env = env , region = region ) for subscription_arn in lambda_subscriptions : sns_client... | Destroy all Lambda SNS subscriptions . |
239,028 | def destroy_elb ( app = '' , env = 'dev' , region = 'us-east-1' , ** _ ) : task_json = get_template ( template_file = 'destroy/destroy_elb.json.j2' , app = app , env = env , region = region , vpc = get_vpc_id ( account = env , region = region ) ) wait_for_task ( task_json ) return True | Destroy ELB Resources . |
239,029 | def delete_pipeline ( app = '' , pipeline_name = '' ) : safe_pipeline_name = normalize_pipeline_name ( name = pipeline_name ) LOG . warning ( 'Deleting Pipeline: %s' , safe_pipeline_name ) url = '{host}/pipelines/{app}/{pipeline}' . format ( host = API_URL , app = app , pipeline = safe_pipeline_name ) response = reques... | Delete _pipeline_name_ from _app_ . |
239,030 | def clean_pipelines ( app = '' , settings = None ) : pipelines = get_all_pipelines ( app = app ) envs = settings [ 'pipeline' ] [ 'env' ] LOG . debug ( 'Find Regions in: %s' , envs ) regions = set ( ) for env in envs : try : regions . update ( settings [ env ] [ 'regions' ] ) except KeyError : error_msg = 'Missing "{}/... | Delete Pipelines for regions not defined in application . json files . |
239,031 | def extract_formats ( config_handle ) : configurations = dict ( config_handle ) formats = dict ( configurations . get ( 'formats' , { } ) ) return formats | Get application formats . |
239,032 | def load_dynamic_config ( config_file = DEFAULT_DYNAMIC_CONFIG_FILE ) : dynamic_configurations = { } sys . path . insert ( 0 , path . dirname ( path . abspath ( config_file ) ) ) try : config_module = __import__ ( 'config' ) dynamic_configurations = config_module . CONFIG except ImportError : LOG . error ( 'ImportError... | Load and parse dynamic config |
239,033 | def _remove_empty_entries ( entries ) : valid_entries = [ ] for entry in set ( entries ) : if entry : valid_entries . append ( entry ) return sorted ( valid_entries ) | Remove empty entries in a list |
239,034 | def _convert_string_to_native ( value ) : result = None try : result = ast . literal_eval ( str ( value ) ) except ( SyntaxError , ValueError ) : result = value . split ( ',' ) return result | Convert a string to its native python type |
239,035 | def _generate_security_groups ( config_key ) : raw_default_groups = validate_key_values ( CONFIG , 'base' , config_key , default = '' ) default_groups = _convert_string_to_native ( raw_default_groups ) LOG . debug ( 'Default security group for %s is %s' , config_key , default_groups ) entries = { } for env in ENVS : en... | Read config file and generate security group dict by environment . |
239,036 | def create_datapipeline ( self ) : tags = [ { "key" : "app_group" , "value" : self . group } , { "key" : "app_name" , "value" : self . app_name } ] response = self . client . create_pipeline ( name = self . datapipeline_data . get ( 'name' , self . app_name ) , uniqueId = self . app_name , description = self . datapipe... | Creates the data pipeline if it does not already exist |
239,037 | def set_pipeline_definition ( self ) : if not self . pipeline_id : self . get_pipeline_id ( ) json_def = self . datapipeline_data [ 'json_definition' ] try : pipelineobjects = translator . definition_to_api_objects ( json_def ) parameterobjects = translator . definition_to_api_parameters ( json_def ) parametervalues = ... | Translates the json definition and puts it on created pipeline |
239,038 | def get_pipeline_id ( self ) : all_pipelines = [ ] paginiator = self . client . get_paginator ( 'list_pipelines' ) for page in paginiator . paginate ( ) : all_pipelines . extend ( page [ 'pipelineIdList' ] ) for pipeline in all_pipelines : if pipeline [ 'name' ] == self . datapipeline_data . get ( 'name' , self . app_n... | Finds the pipeline ID for configured pipeline |
239,039 | def activate_pipeline ( self ) : self . client . activate_pipeline ( pipelineId = self . pipeline_id ) LOG . info ( "Activated Pipeline %s" , self . pipeline_id ) | Activates a deployed pipeline useful for OnDemand pipelines |
239,040 | def get_dns_zone_ids ( env = 'dev' , facing = 'internal' ) : client = boto3 . Session ( profile_name = env ) . client ( 'route53' ) zones = client . list_hosted_zones_by_name ( DNSName = '.' . join ( [ env , DOMAIN ] ) ) zone_ids = [ ] for zone in zones [ 'HostedZones' ] : LOG . debug ( 'Found Hosted Zone: %s' , zone )... | Get Route 53 Hosted Zone IDs for _env_ . |
239,041 | def update_dns_zone_record ( env , zone_id , ** kwargs ) : client = boto3 . Session ( profile_name = env ) . client ( 'route53' ) response = { } hosted_zone_info = client . get_hosted_zone ( Id = zone_id ) zone_name = hosted_zone_info [ 'HostedZone' ] [ 'Name' ] . rstrip ( '.' ) dns_name = kwargs . get ( 'dns_name' ) i... | Create a Route53 CNAME record in _env_ zone . |
239,042 | def find_existing_record ( env , zone_id , dns_name , check_key = None , check_value = None ) : client = boto3 . Session ( profile_name = env ) . client ( 'route53' ) pager = client . get_paginator ( 'list_resource_record_sets' ) existingrecord = None for rset in pager . paginate ( HostedZoneId = zone_id ) : for record... | Check if a specific DNS record exists . |
239,043 | def delete_existing_cname ( env , zone_id , dns_name ) : client = boto3 . Session ( profile_name = env ) . client ( 'route53' ) startrecord = None newrecord_name = dns_name startrecord = find_existing_record ( env , zone_id , newrecord_name , check_key = 'Type' , check_value = 'CNAME' ) if startrecord : LOG . info ( "D... | Delete an existing CNAME record . |
239,044 | def update_failover_dns_record ( env , zone_id , ** kwargs ) : client = boto3 . Session ( profile_name = env ) . client ( 'route53' ) response = { } hosted_zone_info = client . get_hosted_zone ( Id = zone_id ) zone_name = hosted_zone_info [ 'HostedZone' ] [ 'Name' ] . rstrip ( '.' ) dns_name = kwargs . get ( 'dns_name'... | Create a Failover Route53 alias record in _env_ zone . |
239,045 | def create_cloudwatch_log_event ( app_name , env , region , rules ) : session = boto3 . Session ( profile_name = env , region_name = region ) cloudwatch_client = session . client ( 'logs' ) log_group = rules . get ( 'log_group' ) filter_name = rules . get ( 'filter_name' ) filter_pattern = rules . get ( 'filter_pattern... | Create cloudwatch log event for lambda from rules . |
239,046 | def prepare_policy_template ( self , scaling_type , period_sec , server_group ) : template_kwargs = { 'app' : self . app , 'env' : self . env , 'region' : self . region , 'server_group' : server_group , 'period_sec' : period_sec , 'scaling_policy' : self . settings [ 'asg' ] [ 'scaling_policy' ] , } if scaling_type == ... | Renders scaling policy templates based on configs and variables . After rendering POSTs the json to Spinnaker for creation . |
239,047 | def create_policy ( self ) : if not self . settings [ 'asg' ] [ 'scaling_policy' ] : self . log . info ( "No scaling policy found, skipping..." ) return server_group = self . get_server_group ( ) scaling_policies = self . get_all_existing ( server_group ) for policy in scaling_policies : for subpolicy in policy : self ... | Wrapper function . Gets the server group sets sane defaults deletes existing policies and then runs self . prepare_policy_template for scaling up and scaling down policies . This function acts as the main driver for the scaling policy creationprocess |
239,048 | def get_server_group ( self ) : api_url = "{0}/applications/{1}" . format ( API_URL , self . app ) response = requests . get ( api_url , verify = GATE_CA_BUNDLE , cert = GATE_CLIENT_CERT ) for server_group in response . json ( ) [ 'clusters' ] [ self . env ] : return server_group [ 'serverGroups' ] [ - 1 ] | Finds the most recently deployed server group for the application . This is the server group that the scaling policy will be applied to . |
239,049 | def delete_existing_policy ( self , scaling_policy , server_group ) : self . log . info ( "Deleting policy %s on %s" , scaling_policy [ 'policyName' ] , server_group ) delete_dict = { "application" : self . app , "description" : "Delete scaling policy" , "job" : [ { "policyName" : scaling_policy [ 'policyName' ] , "ser... | Given a scaling_policy and server_group deletes the existing scaling_policy . Scaling policies need to be deleted instead of upserted for consistency . |
239,050 | def get_all_existing ( self , server_group ) : self . log . info ( "Checking for existing scaling policy" ) url = "{0}/applications/{1}/clusters/{2}/{1}/serverGroups" . format ( API_URL , self . app , self . env ) response = requests . get ( url , verify = GATE_CA_BUNDLE , cert = GATE_CLIENT_CERT ) assert response . ok... | Finds all existing scaling policies for an application |
239,051 | def destroy_cloudwatch_event ( app = '' , env = 'dev' , region = '' ) : session = boto3 . Session ( profile_name = env , region_name = region ) cloudwatch_client = session . client ( 'events' ) event_rules = get_cloudwatch_event_rule ( app_name = app , account = env , region = region ) for rule in event_rules : cloudwa... | Destroy Cloudwatch event subscription . |
239,052 | def create_bucket ( self ) : bucket_exists = self . _bucket_exists ( ) if self . s3props . get ( 'shared_bucket_target' ) : if bucket_exists : LOG . info ( 'App uses shared bucket - %s ' , self . bucket ) else : LOG . error ( "Shared bucket %s does not exist" , self . bucket ) raise S3SharedBucketNotFound else : if sel... | Create or update bucket based on app name . |
239,053 | def _bucket_exists ( self ) : try : self . s3client . get_bucket_location ( Bucket = self . bucket ) return True except ClientError as error : LOG . error ( error ) return False | Check if the bucket exists . |
239,054 | def _put_bucket_policy ( self ) : if self . s3props [ 'bucket_policy' ] : policy_str = json . dumps ( self . s3props [ 'bucket_policy' ] ) _response = self . s3client . put_bucket_policy ( Bucket = self . bucket , Policy = policy_str ) else : _response = self . s3client . delete_bucket_policy ( Bucket = self . bucket )... | Attach a bucket policy to app bucket . |
239,055 | def _put_bucket_website ( self ) : if self . s3props [ 'website' ] [ 'enabled' ] : website_config = { 'ErrorDocument' : { 'Key' : self . s3props [ 'website' ] [ 'error_document' ] } , 'IndexDocument' : { 'Suffix' : self . s3props [ 'website' ] [ 'index_suffix' ] } } _response = self . s3client . put_bucket_website ( Bu... | Configure static website on S3 bucket . |
239,056 | def _set_bucket_dns ( self ) : dotformat_regions = [ "eu-west-2" , "eu-central-1" , "ap-northeast-2" , "ap-south-1" , "ca-central-1" , "us-east-2" ] if self . region in dotformat_regions : s3_endpoint = "{0}.s3-website.{1}.amazonaws.com" . format ( self . bucket , self . region ) else : s3_endpoint = "{0}.s3-website-{1... | Create CNAME for S3 endpoint . |
239,057 | def _put_bucket_cors ( self ) : if self . s3props [ 'cors' ] [ 'enabled' ] and self . s3props [ 'website' ] [ 'enabled' ] : cors_config = { } cors_rules = [ ] for each_rule in self . s3props [ 'cors' ] [ 'cors_rules' ] : cors_rules . append ( { 'AllowedHeaders' : each_rule [ 'cors_headers' ] , 'AllowedMethods' : each_r... | Adds bucket cors configuration . |
239,058 | def _put_bucket_encryption ( self ) : if self . s3props [ 'encryption' ] [ 'enabled' ] : encryption_config = { 'Rules' : [ { } ] } encryption_config = { 'Rules' : self . s3props [ 'encryption' ] [ 'encryption_rules' ] } LOG . debug ( encryption_config ) _response = self . s3client . put_bucket_encryption ( Bucket = sel... | Adds bucket encryption configuration . |
239,059 | def _put_bucket_lifecycle ( self ) : status = 'deleted' if self . s3props [ 'lifecycle' ] [ 'enabled' ] : lifecycle_config = { 'Rules' : self . s3props [ 'lifecycle' ] [ 'lifecycle_rules' ] } LOG . debug ( 'Lifecycle Config: %s' , lifecycle_config ) _response = self . s3client . put_bucket_lifecycle_configuration ( Buc... | Adds bucket lifecycle configuration . |
239,060 | def _put_bucket_logging ( self ) : logging_config = { } if self . s3props [ 'logging' ] [ 'enabled' ] : logging_config = { 'LoggingEnabled' : { 'TargetBucket' : self . s3props [ 'logging' ] [ 'logging_bucket' ] , 'TargetGrants' : self . s3props [ 'logging' ] [ 'logging_grants' ] , 'TargetPrefix' : self . s3props [ 'log... | Adds bucket logging policy to bucket for s3 access requests |
239,061 | def _put_bucket_tagging ( self ) : all_tags = self . s3props [ 'tagging' ] [ 'tags' ] all_tags . update ( { 'app_group' : self . group , 'app_name' : self . app_name } ) tag_set = generate_s3_tags . generated_tag_data ( all_tags ) tagging_config = { 'TagSet' : tag_set } self . s3client . put_bucket_tagging ( Bucket = s... | Add bucket tags to bucket . |
239,062 | def _put_bucket_versioning ( self ) : status = 'Suspended' if self . s3props [ 'versioning' ] [ 'enabled' ] : status = 'Enabled' versioning_config = { 'MFADelete' : self . s3props [ 'versioning' ] [ 'mfa_delete' ] , 'Status' : status } _response = self . s3client . put_bucket_versioning ( Bucket = self . bucket , Versi... | Adds bucket versioning policy to bucket |
239,063 | def process_git_configs ( git_short = '' ) : LOG . info ( 'Processing application.json files from GitLab "%s".' , git_short ) file_lookup = FileLookup ( git_short = git_short ) app_configs = process_configs ( file_lookup , RUNWAY_BASE_PATH + '/application-master-{env}.json' , RUNWAY_BASE_PATH + '/pipeline.json' ) commi... | Retrieve _application . json_ files from GitLab . |
239,064 | def process_runway_configs ( runway_dir = '' ) : LOG . info ( 'Processing application.json files from local directory "%s".' , runway_dir ) file_lookup = FileLookup ( runway_dir = runway_dir ) app_configs = process_configs ( file_lookup , 'application-master-{env}.json' , 'pipeline.json' ) return app_configs | Read the _application . json_ files . |
239,065 | def process_configs ( file_lookup , app_config_format , pipeline_config ) : app_configs = collections . defaultdict ( dict ) for env in ENVS : file_json = app_config_format . format ( env = env ) try : env_config = file_lookup . json ( filename = file_json ) app_configs [ env ] = apply_region_configs ( env_config ) exc... | Processes the configs from lookup sources . |
239,066 | def apply_region_configs ( env_config ) : new_config = env_config . copy ( ) for region in env_config . get ( 'regions' , REGIONS ) : if isinstance ( env_config . get ( 'regions' ) , dict ) : region_specific_config = env_config [ 'regions' ] [ region ] new_config [ region ] = dict ( DeepChainMap ( region_specific_confi... | Override default env configs with region specific configs and nest all values under a region |
239,067 | def create_iam_resources ( env = 'dev' , app = '' , ** _ ) : session = boto3 . session . Session ( profile_name = env ) client = session . client ( 'iam' ) app_properties = get_properties ( env = 'pipeline' ) generated = get_details ( env = env , app = app ) generated_iam = generated . iam ( ) app_details = collections... | Create the IAM Resources for the application . |
239,068 | def attach_profile_to_role ( client , role_name = 'forrest_unicorn_role' , profile_name = 'forrest_unicorn_profile' ) : current_instance_profiles = resource_action ( client , action = 'list_instance_profiles_for_role' , log_format = 'Found Instance Profiles for %(RoleName)s.' , RoleName = role_name ) [ 'InstanceProfile... | Attach an IAM Instance Profile _profile_name_ to Role _role_name_ . |
239,069 | def find_elb ( name = '' , env = '' , region = '' ) : LOG . info ( 'Find %s ELB in %s [%s].' , name , env , region ) url = '{0}/applications/{1}/loadBalancers' . format ( API_URL , name ) response = requests . get ( url , verify = GATE_CA_BUNDLE , cert = GATE_CLIENT_CERT ) assert response . ok elb_dns = None accounts =... | Get an application s AWS elb dns name . |
239,070 | def find_elb_dns_zone_id ( name = '' , env = 'dev' , region = 'us-east-1' ) : LOG . info ( 'Find %s ELB DNS Zone ID in %s [%s].' , name , env , region ) client = boto3 . Session ( profile_name = env ) . client ( 'elb' , region_name = region ) elbs = client . describe_load_balancers ( LoadBalancerNames = [ name ] ) retu... | Get an application s AWS elb dns zone id . |
239,071 | def get_version ( ) : version = 'Not installed.' try : version = pkg_resources . get_distribution ( __package__ ) . version except pkg_resources . DistributionNotFound : pass return version | Retrieve package version . |
239,072 | async def loop ( self ) : self . _running = True while self . _running : updates = await self . api_call ( "getUpdates" , offset = self . _offset + 1 , timeout = self . api_timeout ) self . _process_updates ( updates ) | Return bot s main loop as coroutine . Use with asyncio . |
239,073 | def run ( self , debug = False , reload = None ) : loop = asyncio . get_event_loop ( ) logging . basicConfig ( level = logging . DEBUG if debug else logging . INFO ) if reload is None : reload = debug bot_loop = asyncio . ensure_future ( self . loop ( ) ) try : if reload : loop . run_until_complete ( run_with_reloader ... | Convenience method for running bots in getUpdates mode |
239,074 | def run_webhook ( self , webhook_url , ** options ) : loop = asyncio . get_event_loop ( ) loop . run_until_complete ( self . set_webhook ( webhook_url , ** options ) ) if webhook_url : url = urlparse ( webhook_url ) app = self . create_webhook_app ( url . path , loop ) host = os . environ . get ( "HOST" , "0.0.0.0" ) p... | Convenience method for running bots in webhook mode |
239,075 | def command ( self , regexp ) : def decorator ( fn ) : self . add_command ( regexp , fn ) return fn return decorator | Register a new command |
239,076 | def inline ( self , callback ) : if callable ( callback ) : self . _default_inline = callback return callback elif isinstance ( callback , str ) : def decorator ( fn ) : self . add_inline ( callback , fn ) return fn return decorator else : raise TypeError ( "str expected {} given" . format ( type ( callback ) ) ) | Set callback for inline queries |
239,077 | def callback ( self , callback ) : if callable ( callback ) : self . _default_callback = callback return callback elif isinstance ( callback , str ) : def decorator ( fn ) : self . add_callback ( callback , fn ) return fn return decorator else : raise TypeError ( "str expected {} given" . format ( type ( callback ) ) ) | Set callback for callback queries |
239,078 | def handle ( self , msg_type ) : def wrap ( callback ) : self . _handlers [ msg_type ] = callback return callback return wrap | Set handler for specific message type |
239,079 | def api_call ( self , method , ** params ) : coro = self . _api_call ( method , ** params ) return asyncio . ensure_future ( coro ) | Call Telegram API . |
239,080 | def send_message ( self , chat_id , text , ** options ) : return self . api_call ( "sendMessage" , chat_id = chat_id , text = text , ** options ) | Send a text message to chat |
239,081 | def edit_message_text ( self , chat_id , message_id , text , ** options ) : return self . api_call ( "editMessageText" , chat_id = chat_id , message_id = message_id , text = text , ** options ) | Edit a text message in a chat |
239,082 | def edit_message_reply_markup ( self , chat_id , message_id , reply_markup , ** options ) : return self . api_call ( "editMessageReplyMarkup" , chat_id = chat_id , message_id = message_id , reply_markup = reply_markup , ** options ) | Edit a reply markup of message in a chat |
239,083 | def download_file ( self , file_path , range = None ) : headers = { "range" : range } if range else None url = "{0}/file/bot{1}/{2}" . format ( API_URL , self . api_token , file_path ) return self . session . get ( url , headers = headers , proxy = self . proxy , proxy_auth = self . proxy_auth ) | Download a file from Telegram servers |
239,084 | def get_user_profile_photos ( self , user_id , ** options ) : return self . api_call ( "getUserProfilePhotos" , user_id = str ( user_id ) , ** options ) | Get a list of profile pictures for a user |
239,085 | async def webhook_handle ( self , request ) : update = await request . json ( loads = self . json_deserialize ) self . _process_update ( update ) return web . Response ( ) | aiohttp . web handle for processing web hooks |
239,086 | def create_webhook_app ( self , path , loop = None ) : app = web . Application ( loop = loop ) app . router . add_route ( "POST" , path , self . webhook_handle ) return app | Shorthand for creating aiohttp . web . Application with registered webhook hanlde |
239,087 | def send_text ( self , text , ** options ) : return self . bot . send_message ( self . id , text , ** options ) | Send a text message to the chat . |
239,088 | def reply ( self , text , markup = None , parse_mode = None ) : if markup is None : markup = { } return self . send_text ( text , reply_to_message_id = self . message [ "message_id" ] , disable_web_page_preview = "true" , reply_markup = self . bot . json_serialize ( markup ) , parse_mode = parse_mode , ) | Reply to the message this Chat object is based on . |
239,089 | def edit_text ( self , message_id , text , markup = None , parse_mode = None ) : if markup is None : markup = { } return self . bot . edit_message_text ( self . id , message_id , text , reply_markup = self . bot . json_serialize ( markup ) , parse_mode = parse_mode , ) | Edit the message in this chat . |
239,090 | def edit_reply_markup ( self , message_id , markup ) : return self . bot . edit_message_reply_markup ( self . id , message_id , reply_markup = self . bot . json_serialize ( markup ) ) | Edit only reply markup of the message in this chat . |
239,091 | def get_chat_member ( self , user_id ) : return self . bot . api_call ( "getChatMember" , chat_id = str ( self . id ) , user_id = str ( user_id ) ) | Get information about a member of a chat . |
239,092 | def send_sticker ( self , sticker , ** options ) : return self . bot . api_call ( "sendSticker" , chat_id = str ( self . id ) , sticker = sticker , ** options ) | Send a sticker to the chat . |
239,093 | def send_audio ( self , audio , ** options ) : return self . bot . api_call ( "sendAudio" , chat_id = str ( self . id ) , audio = audio , ** options ) | Send an mp3 audio file to the chat . |
239,094 | def send_photo ( self , photo , caption = "" , ** options ) : return self . bot . api_call ( "sendPhoto" , chat_id = str ( self . id ) , photo = photo , caption = caption , ** options ) | Send a photo to the chat . |
239,095 | def send_video ( self , video , caption = "" , ** options ) : return self . bot . api_call ( "sendVideo" , chat_id = str ( self . id ) , video = video , caption = caption , ** options ) | Send an mp4 video file to the chat . |
239,096 | def send_document ( self , document , caption = "" , ** options ) : return self . bot . api_call ( "sendDocument" , chat_id = str ( self . id ) , document = document , caption = caption , ** options ) | Send a general file . |
239,097 | def send_voice ( self , voice , ** options ) : return self . bot . api_call ( "sendVoice" , chat_id = str ( self . id ) , voice = voice , ** options ) | Send an OPUS - encoded . ogg audio file . |
239,098 | def send_location ( self , latitude , longitude , ** options ) : return self . bot . api_call ( "sendLocation" , chat_id = self . id , latitude = latitude , longitude = longitude , ** options ) | Send a point on the map . |
239,099 | def send_venue ( self , latitude , longitude , title , address , ** options ) : return self . bot . api_call ( "sendVenue" , chat_id = self . id , latitude = latitude , longitude = longitude , title = title , address = address , ** options ) | Send information about a venue . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.