Esempio n. 1
0
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
"""
import boto3

from syndicate.commons.log_helper import get_logger
from syndicate.connection.helper import apply_methods_decorator, retry

_LOG = get_logger('syndicate.connection.application_autoscaling_connection')


@apply_methods_decorator(retry)
class ApplicationAutoscaling(object):
    def __init__(self,
                 region=None,
                 aws_access_key_id=None,
                 aws_secret_access_key=None,
                 aws_session_token=None):
        self.region = region
        self.aws_access_key_id = aws_access_key_id
        self.aws_secret_access_key = aws_secret_access_key
        self.aws_session_token = aws_session_token
        self.client = boto3.client('application-autoscaling',
                                   region,
Esempio n. 2
0
import sys

import yaml

from syndicate.commons.log_helper import get_logger
from syndicate.core.conf.processor import (
    PROJECT_PATH_CFG, LEGACY_CONFIG_FILE_NAME, CONFIG_FILE_NAME,
    ALIASES_FILE_NAME, ACCOUNT_ID_CFG, REGION_CFG, DEPLOY_TARGET_BUCKET_CFG,
    AWS_ACCESS_KEY_ID_CFG, AWS_SECRET_ACCESS_KEY_CFG, PROJECTS_MAPPING_CFG,
    RESOURCES_PREFIX_CFG, RESOURCES_SUFFIX_CFG)
from syndicate.core.conf.validator import (PYTHON_BUILD_TOOL_NAME,
                                           MVN_BUILD_TOOL_NAME,
                                           NODE_BUILD_TOOL_NAME,
                                           LAMBDAS_ALIASES_NAME_CFG)

_LOG = get_logger('config_generator')


def generate_configuration_files(config_path,
                                 region,
                                 account_id,
                                 access_key,
                                 secret_key,
                                 bundle_bucket_name,
                                 python_build_mapping,
                                 java_build_mapping,
                                 nodejs_build_mapping,
                                 prefix,
                                 suffix,
                                 project_path=None):
    if not config_path:
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
"""
from botocore.exceptions import ClientError

from syndicate.commons.log_helper import get_logger
from syndicate.connection.helper import retry
from syndicate.core import CONFIG, CONN
from syndicate.core.helper import create_pool, prettify_json, unpack_kwargs
from syndicate.core.resources.helper import (build_description_obj,
                                             resolve_dynamic_identifier)

_IAM_CONN = CONN.iam()

_LOG = get_logger('syndicate.core.resources.iam_resource')


def remove_policies(args):
    create_pool(_remove_policy, args)


@unpack_kwargs
def _remove_policy(arn, config):
    policy_name = config['resource_name']
    try:
        _IAM_CONN.remove_policy(arn)
        _LOG.info('IAM policy %s was removed.', policy_name)
    except ClientError as e:
        error_code = e.response['Error']['Code']
        if error_code == 'NoSuchEntity':
Esempio n. 4
0
import sys
from concurrent.futures import ALL_COMPLETED, ThreadPoolExecutor
from functools import wraps
from threading import Thread
from time import time

from click import BadParameter
from tqdm import tqdm

from syndicate.commons.log_helper import get_logger
from syndicate.core import CONFIG, CONN
from syndicate.core.conf.config_holder import path_resolver
from syndicate.core.constants import (ARTIFACTS_FOLDER, BUILD_META_FILE_NAME,
                                      DEFAULT_SEP)

_LOG = get_logger('syndicate.core.helper')


def create_pool(func, args, workers=None, *kwargs):
    """ Create resources in pool in sub processes.

    :type args: iterable
    :type func: func
    """
    executor = ThreadPoolExecutor(workers) if workers else ThreadPoolExecutor()
    try:
        futures = [executor.submit(func, i, kwargs) for i in args]
        concurrent.futures.wait(futures, return_when=ALL_COMPLETED)
        responses = {}
        for future in futures:
            result = future.result()
Esempio n. 5
0
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
"""
import time

from botocore.exceptions import ClientError

from syndicate.commons.log_helper import get_logger
from syndicate.core.helper import unpack_kwargs
from syndicate.core.resources.base_resource import BaseResource
from syndicate.core.resources.helper import build_description_obj

_LOG = get_logger('core.resources.sqs_resource')

AVAILABLE_REGIONS = [
    'us-east-2', 'us-east-1', 'us-west-1', 'us-west-2', 'ap-south-1',
    'ap-northeast-2', 'ap-southeast-1', 'ap-southeast-2', 'ap-northeast-1',
    'ca-central-1', 'eu-central-1', 'eu-west-2', 'sa-east-1', 'eu-west-1'
]
FIFO_REGIONS = ['us-east-1', 'us-east-2', 'us-west-2', 'eu-west-1']


class SqsResource(BaseResource):
    def __init__(self, sqs_conn_builder, region, account_id) -> None:
        self.sqs_conn_builder = sqs_conn_builder
        self.region = region
        self.account_id = account_id
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
"""
import time

from botocore.exceptions import ClientError

from syndicate.commons.log_helper import get_logger
from syndicate.core.helper import unpack_kwargs
from syndicate.core.resources.base_resource import BaseResource
from syndicate.core.resources.helper import (build_description_obj,
                                             validate_params)

_LOG = get_logger('core.resources.step_function_resource')


class StepFunctionResource(BaseResource):
    def __init__(self, sf_conn, iam_conn, cw_events_conn, lambda_conn,
                 account_id, region) -> None:
        self.sf_conn = sf_conn
        self.iam_conn = iam_conn
        self.cw_events_conn = cw_events_conn
        self.lambda_conn = lambda_conn
        self.account_id = account_id
        self.region = region

    def create_state_machine(self, args):
        return self.create_pool(self._create_state_machine_from_meta, args)
Esempio n. 7
0
    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
"""
from boto3 import client
from botocore.exceptions import ClientError

from syndicate.commons.log_helper import get_logger
from syndicate.connection.helper import apply_methods_decorator, retry

_LOG = get_logger('syndicate.connection.api_gateway_connection')


@apply_methods_decorator(retry)
class ApiGatewayConnection(object):
    """ API Gateway connection class."""
    def __init__(self,
                 region=None,
                 aws_access_key_id=None,
                 aws_secret_access_key=None,
                 aws_session_token=None):
        self.region = region
        self.aws_access_key_id = aws_access_key_id
        self.aws_secret_access_key = aws_secret_access_key
        self.aws_session_token = aws_session_token
        self.client = client('apigateway',
Esempio n. 8
0
import time

from botocore.exceptions import ClientError

from syndicate.commons.log_helper import get_logger
from syndicate.connection.helper import retry
from syndicate.core.build.meta_processor import S3_PATH_NAME
from syndicate.core.helper import (unpack_kwargs, exit_on_exception)
from syndicate.core.resources.base_resource import BaseResource
from syndicate.core.resources.helper import (build_description_obj,
                                             validate_params,
                                             assert_required_params)

PROVISIONED_CONCURRENCY = 'provisioned_concurrency'

_LOG = get_logger('syndicate.core.resources.lambda_resource')

LAMBDA_MAX_CONCURRENCY = 'max_concurrency'
LAMBDA_CONCUR_QUALIFIER_ALIAS = 'ALIAS'
LAMBDA_CONCUR_QUALIFIER_VERSION = 'VERSION'
_LAMBDA_PROV_CONCURRENCY_QUALIFIERS = [
    LAMBDA_CONCUR_QUALIFIER_ALIAS, LAMBDA_CONCUR_QUALIFIER_VERSION
]


class LambdaResource(BaseResource):
    def __init__(self, lambda_conn, s3_conn, cw_logs_conn, sns_conn, iam_conn,
                 dynamodb_conn, sqs_conn, kinesis_conn, cw_events_conn, region,
                 account_id, deploy_target_bucket) -> None:
        self.lambda_conn = lambda_conn
        self.s3_conn = s3_conn
Esempio n. 9
0
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
"""
import time

from syndicate.commons.log_helper import get_logger
from syndicate.core import ClientError
from syndicate.core.helper import unpack_kwargs
from syndicate.core.resources.base_resource import BaseResource
from syndicate.core.resources.helper import build_description_obj

_LOG = get_logger('syndicate.core.resources.kinesis_resource')


class KinesisResource(BaseResource):
    def __init__(self, kin_conn) -> None:
        self.kin_conn = kin_conn

    def create_kinesis_stream(self, args):
        return self.create_pool(self._create_kinesis_stream_from_meta, args)

    def remove_kinesis_streams(self, args):
        self.create_pool(self._remove_kinesis_stream, args)

    @unpack_kwargs
    def _remove_kinesis_stream(self, arn, config):
        stream_name = config['resource_name']
Esempio n. 10
0
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
"""
import json
import uuid
from json import dumps

from boto3 import client
from botocore.exceptions import ClientError

from syndicate.commons.log_helper import get_logger
from syndicate.connection.helper import apply_methods_decorator, retry

_LOG = get_logger('syndicate.connection.cloud_watch_connection')


@apply_methods_decorator(retry)
class LogsConnection(object):
    """ CloudWatch Log connection class."""
    def __init__(self,
                 region=None,
                 aws_access_key_id=None,
                 aws_secret_access_key=None,
                 aws_session_token=None):
        self.client = client('logs',
                             region,
                             aws_access_key_id=aws_access_key_id,
                             aws_secret_access_key=aws_secret_access_key,
                             aws_session_token=aws_session_token)
Esempio n. 11
0
    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
"""
from boto3 import client

from syndicate.commons.log_helper import get_logger
from syndicate.connection.helper import apply_methods_decorator, retry
from syndicate.connection.iam_connection import IAMConnection

_LOG = get_logger('syndicate.connection.cognito_identity_connection')


@apply_methods_decorator(retry)
class CognitoIdentityConnection(object):
    """ Cognito identity connection class."""
    def __init__(self,
                 region=None,
                 aws_access_key_id=None,
                 aws_secret_access_key=None,
                 aws_session_token=None):
        self.region = region,
        self.aws_access_key_id = aws_access_key_id
        self.aws_secret_access_key = aws_secret_access_key
        self.aws_session_token = aws_session_token
        self.client = client('cognito-identity',
Esempio n. 12
0
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
"""
import os
import sys

from botocore.exceptions import ClientError
from botocore.vendored.requests.packages import urllib3

from syndicate.commons.log_helper import get_logger
from syndicate.connection import ConnectionProvider
from syndicate.connection.sts_connection import STSConnection
from syndicate.core.conf.config_holder import ConfigHolder

_LOG = get_logger('deployment.__init__')

S3_PATH_NAME = 's3_path'
SESSION_TOKEN = 'aws_session_token'
SECRET_KEY = 'aws_secret_access_key'
ACCESS_KEY = 'aws_access_key_id'


def exception_handler(exception_type, exception, traceback):
    print(exception)


sys.excepthook = exception_handler

# suppress botocore warnings
urllib3.disable_warnings()
Esempio n. 13
0
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
"""

from boto3 import client
from botocore.waiter import WaiterModel, create_waiter_with_client

from syndicate.commons.log_helper import get_logger
from syndicate.connection.helper import apply_methods_decorator, retry
from syndicate.core.helper import dict_keys_to_camel_case

_LOG = get_logger('syndicate.connection.batch_connection')


@apply_methods_decorator(retry)
class BatchConnection(object):
    """ AWS Batch connection class. """

    def __init__(self, region=None, aws_access_key_id=None,
                 aws_secret_access_key=None, aws_session_token=None):
        self.client = client('batch', region,
                             aws_access_key_id=aws_access_key_id,
                             aws_secret_access_key=aws_secret_access_key,
                             aws_session_token=aws_session_token)
        _LOG.debug('Opened new Batch connection.')

    def create_compute_environment(self, compute_environment_name,
Esempio n. 14
0
from syndicate.commons.log_helper import get_logger
from syndicate.core.generators import (_touch, _mkdir, _write_content_to_file,
                                       FILE_LAMBDA_HANDLER_PYTHON,
                                       FILE_LAMBDA_HANDLER_NODEJS,
                                       _read_content_from_file)
from syndicate.core.generators.contents import (
    NODEJS_LAMBDA_HANDLER_TEMPLATE, PYTHON_LAMBDA_HANDLER_TEMPLATE,
    _generate_python_node_lambda_config, _generate_lambda_role_config,
    _generate_nodejs_node_lambda_config, CANCEL_MESSAGE,
    _generate_package_nodejs_lambda, _generate_package_lock_nodejs_lambda,
    JAVA_LAMBDA_HANDLER_CLASS, SRC_MAIN_JAVA, FILE_POM)
from syndicate.core.groups import (PROJECT_JAVA, PROJECT_NODEJS,
                                   PROJECT_PYTHON)

_LOG = get_logger('syndicate.core.generators.lambda_function')

SLASH_SYMBOL = '/'

FOLDER_LAMBDAS = '/lambdas'
FOLDER_COMMONS = '/commons'

FILE_README = '/README.md'
FILE_DEPLOYMENT_RESOURCES = '/deployment_resources.json'
FILE_INIT_PYTHON = '/__init__.py'
FILE_LAMBDA_CONFIG = '/lambda_config.json'
FILE_PACKAGE_LOCK = '/package-lock.json'
FILE_PACKAGE = '/package.json'

FILE_REQUIREMENTS = '/requirements.txt'
FILE_LOCAL_REQUIREMENTS = '/local_requirements.txt'
Esempio n. 15
0
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
"""
import traceback
from functools import wraps
from time import sleep

from botocore.exceptions import ClientError

from syndicate.commons.log_helper import get_logger

_LOG = get_logger('syndicate.connection.helper')


def apply_methods_decorator(decorator):
    def decorate(cls):
        for attr in cls.__dict__:
            if callable(getattr(cls, attr)):
                setattr(cls, attr, decorator(getattr(cls, attr)))
        return cls

    return decorate


def retry(handler_func):
    """ Decorator for retry on specified exceptions.
Esempio n. 16
0
from concurrent.futures import ThreadPoolExecutor

from botocore.exceptions import ClientError

from syndicate.commons.log_helper import get_logger
from syndicate.connection import S3Connection
from syndicate.core import CONFIG, CONN, sts
from syndicate.core.build.helper import _json_serial
from syndicate.core.build.meta_processor import validate_deployment_packages
from syndicate.core.constants import (ARTIFACTS_FOLDER, BUILD_META_FILE_NAME,
                                      DEFAULT_SEP)
from syndicate.core.helper import build_path, unpack_kwargs

_S3_CONN = CONN.s3()

_LOG = get_logger('syndicate.core.build.bundle_processor')


def _build_output_key(bundle_name, deploy_name, is_regular_output):
    return '{0}/outputs/{1}{2}.json'.format(
        bundle_name, deploy_name, '' if is_regular_output else '_failed')


def _backup_deploy_output(filename, output):
    _LOG.info('Wrote file to {0}'.format(filename))
    with open(filename, 'a+') as backup_file:
        backup_file.write(output)
        backup_file.close()


def create_deploy_output(bundle_name,
Esempio n. 17
0
from syndicate.core.build.validator.mapping import (VALIDATOR_BY_TYPE_MAPPING,
                                                    ALL_TYPES)
from syndicate.core.conf.config_holder import GLOBAL_AWS_SERVICES
from syndicate.core.constants import (API_GATEWAY_TYPE, ARTIFACTS_FOLDER,
                                      BUILD_META_FILE_NAME, EBS_TYPE,
                                      LAMBDA_CONFIG_FILE_NAME, LAMBDA_TYPE,
                                      RESOURCES_FILE_NAME, RESOURCE_LIST,
                                      IAM_ROLE, LAMBDA_LAYER_TYPE)
from syndicate.core.helper import (build_path, prettify_json,
                                   resolve_aliases_for_string,
                                   write_content_to_file)
from syndicate.core.resources.helper import resolve_dynamic_identifier

DEFAULT_IAM_SUFFIX_LENGTH = 5

_LOG = get_logger('syndicate.core.build.meta_processor')


def validate_deployment_packages(meta_resources):
    package_paths = artifact_paths(meta_resources)
    bundles_path = build_path(CONFIG.project_path, ARTIFACTS_FOLDER)
    nonexistent_packages = []
    for package in package_paths:
        package_path = build_path(bundles_path, package)
        if not os.path.exists(package_path):
            nonexistent_packages.append(package_path)

    if nonexistent_packages:
        raise AssertionError('Bundle is not properly configured.'
                             ' Nonexistent deployment packages: '
                             '{0}'.format(prettify_json(nonexistent_packages)))
Esempio n. 18
0
    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
"""
from botocore.waiter import WaiterError

from syndicate.commons.log_helper import get_logger
from syndicate.core.helper import unpack_kwargs
from syndicate.core.resources.base_resource import BaseResource
from syndicate.core.resources.helper import build_description_obj

_LOG = get_logger('syndicate.core.resources.batch_compenv')

DEFAULT_STATE = 'ENABLED'
DEFAULT_SERVICE_ROLE = 'AWSBatchServiceRole'


class BatchComputeEnvironmentResource(BaseResource):

    def __init__(self, batch_conn, iam_conn):
        self.batch_conn = batch_conn
        self.iam_conn = iam_conn

    def create_compute_environment(self, args):
        return self.create_pool(self._create_compute_environment_from_meta, args)

    def describe_compute_environment(self, name, meta):
Esempio n. 19
0
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
"""

import os

from syndicate.commons.log_helper import get_logger
from syndicate.core.generators import (_touch, _mkdir, _write_content_to_file)
from syndicate.core.generators.contents import (_get_lambda_default_policy,
                                                JAVA_ROOT_POM_TEMPLATE,
                                                SRC_MAIN_JAVA, FILE_POM)
from syndicate.core.groups import (PROJECT_JAVA, PROJECT_NODEJS,
                                   PROJECT_PYTHON)

_LOG = get_logger('syndicate.core.generators.project')

SLASH_SYMBOL = '/'
FOLDER_LAMBDAS = '/lambdas'
FOLDER_COMMONS = '/commons'
FILE_README = '/README.md'
FILE_DEPLOYMENT_RESOURCES = '/deployment_resources.json'


def generate_project_structure(project_name, project_path, project_language):
    try:
        if not os.path.exists(project_path):
            raise AssertionError(
                'Path "{}" you have provided does not exist'.format(
                    project_path))
Esempio n. 20
0
from syndicate.core.build.runtime.java import assemble_java_mvn_lambdas
from syndicate.core.build.runtime.nodejs import assemble_node_lambdas
from syndicate.core.build.runtime.python import assemble_python_lambdas

RUNTIME_JAVA_8 = 'java8'
RUNTIME_NODEJS = 'nodejs10.x'
RUNTIME_PYTHON = 'pythonX'

SUPPORTED_RUNTIMES = [RUNTIME_JAVA_8, RUNTIME_NODEJS, RUNTIME_PYTHON]

RUNTIME_TO_BUILDER_MAPPING = {
    RUNTIME_JAVA_8: assemble_java_mvn_lambdas,
    RUNTIME_NODEJS: assemble_node_lambdas,
    RUNTIME_PYTHON: assemble_python_lambdas
}

_LOG = get_logger('syndicate.core.build.artifact_processor')


def assemble_artifacts(bundle_name, project_path, runtime):
    if runtime not in SUPPORTED_RUNTIMES:
        raise AssertionError('Runtime {} is not supported. '
                             'Currently available runtimes:{}'.format(
                                 runtime, SUPPORTED_RUNTIMES))

    assemble_func = RUNTIME_TO_BUILDER_MAPPING.get(runtime)
    if not assemble_func:
        raise AssertionError(
            'There is no assembler for the runtime {}'.format(runtime))
    assemble_func(bundle_name=bundle_name, project_path=project_path)
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
"""
from boto3 import client

from syndicate.commons.log_helper import get_logger
from syndicate.connection.helper import apply_methods_decorator, retry

_LOG = get_logger('syndicate.connection.secrets_manager_connection')


@apply_methods_decorator(retry)
class SecretsManagerConnection(object):
    def __init__(self, region=None, aws_access_key_id=None,
                 aws_secret_access_key=None, aws_session_token=None):
        self.client = client('secretsmanager', region,
                             aws_access_key_id=aws_access_key_id,
                             aws_secret_access_key=aws_secret_access_key,
                             aws_session_token=aws_session_token)
        _LOG.debug('Opened new Secrets Manager connection.')

    def describe_secret(self, secret_id):
        response = self.client.describe_secret(SecretId=secret_id)
        return response
Esempio n. 22
0
    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
"""
from botocore.exceptions import ClientError

from syndicate.commons.log_helper import get_logger
from syndicate.core.helper import unpack_kwargs
from syndicate.core.resources.base_resource import BaseResource
from syndicate.core.resources.helper import build_description_obj

_LOG = get_logger('syndicate.core.resources.cognito_identity_resource')


class CognitoResource(BaseResource):

    def __init__(self, cognito_conn, account_id, region) -> None:
        self.connection = cognito_conn
        self.account_id = account_id
        self.region = region

    def cognito_resource_identifier(self, name, output=None):
        if output:
            # cognito currently is not located in different regions
            # process only first object
            pool_output = list(output.items())[0][1]
            # find id from the output
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
"""
import os

from configobj import ConfigObj
from validate import Validator, VdtTypeError

from syndicate.commons.log_helper import get_logger
from syndicate.core.constants import (DEFAULT_SEP, IAM_POLICY, IAM_ROLE,
                                      S3_BUCKET_TYPE)

CONFIG_FILE_NAME = 'sdct.conf'

_LOG = get_logger('core.conf.config_holder')

ALL_REGIONS = [
    'us-east-1', 'us-east-2', 'us-west-1', 'us-west-2', 'sa-east-1',
    'ca-central-1', 'eu-west-1', 'eu-central-1', 'eu-west-2', 'eu-west-3',
    'ap-northeast-1', 'ap-northeast-2', 'ap-southeast-1', 'ap-southeast-2',
    'ap-south-1'
]

GLOBAL_AWS_SERVICES = {IAM_ROLE, IAM_POLICY, S3_BUCKET_TYPE}

PYTHON_BUILD_TOOL_NAME = 'python'
MVN_BUILD_TOOL_NAME = 'mvn'

ALLOWED_BUILDS = [PYTHON_BUILD_TOOL_NAME, MVN_BUILD_TOOL_NAME]
Esempio n. 24
0
    See the License for the specific language governing permissions and
    limitations under the License.
"""
import time

from botocore.exceptions import ClientError

from syndicate.commons.log_helper import get_logger
from syndicate.core import CONFIG, CONN
from syndicate.core.conf.config_holder import ALL_REGIONS
from syndicate.core.helper import create_pool, unpack_kwargs
from syndicate.core.resources.helper import (build_description_obj,
                                             create_args_for_multi_region,
                                             validate_params)

_LOG = get_logger('syndicate.core.resources.cloud_watch_resource')


def describe_rule(name, meta, region, response=None):
    if not response:
        response = CONN.cw_events(region).get_rule(name)
    arn = response['Arn']
    del response['Arn']
    return {arn: build_description_obj(response, name, meta)}


def describe_rule_from_meta(name, meta):
    new_region_args = create_args_for_multi_region(
        [
            {'name': name,
             'meta': meta}
"""
import time

from botocore.exceptions import ClientError

from syndicate.commons.log_helper import get_logger
from syndicate.core import CONFIG, CONN
from syndicate.core.helper import create_pool, unpack_kwargs
from syndicate.core.resources.helper import (build_description_obj,
                                             validate_params)
from syndicate.core.resources.lambda_resource import (
    resolve_lambda_arn_by_version_and_alias)

SUPPORTED_METHODS = ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'HEAD']

_LOG = get_logger('syndicate.core.resources.api_gateway_resource')

_DEFAULT_RESPONSES = {
    "responses": [
        {
            "status_code": "200"
        },
        {
            "status_code": "400"
        },
        {
            "status_code": "401"
        },
        {
            "status_code": "403"
        },
from syndicate.commons.log_helper import get_logger
from syndicate.core.build.bundle_processor import (
    create_deploy_output, load_deploy_output, load_failed_deploy_output,
    load_meta_resources, remove_deploy_output, remove_failed_deploy_output)
from syndicate.core.build.meta_processor import resolve_meta
from syndicate.core.constants import (BUILD_META_FILE_NAME,
                                      CLEAN_RESOURCE_TYPE_PRIORITY,
                                      DEPLOY_RESOURCE_TYPE_PRIORITY,
                                      LAMBDA_TYPE)
from syndicate.core.helper import exit_on_exception, prettify_json
from syndicate.core.resources import (APPLY_MAPPING, CREATE_RESOURCE,
                                      DESCRIBE_RESOURCE, REMOVE_RESOURCE,
                                      RESOURCE_CONFIGURATION_PROCESSORS,
                                      RESOURCE_IDENTIFIER, UPDATE_RESOURCE)

_LOG = get_logger('syndicate.core.build.deployment_processor')


def get_dependencies(name, meta, resources_dict, resources):
    """ Get dependencies from resources that needed to create them too.

    :type name: str
    :type meta: dict
    :type resources_dict: dict
    :param resources:
    :param resources_dict: resources that will be created {name: meta}
    """
    resources_dict[name] = meta
    if meta.get('dependencies'):
        for dependency in meta.get('dependencies'):
            dep_name = dependency['resource_name']
Esempio n. 27
0
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
"""
from operator import itemgetter

from boto3 import client, resource
from boto3.dynamodb.conditions import Attr, Key
from botocore.exceptions import ClientError

from syndicate.commons.log_helper import get_logger
from syndicate.connection.helper import apply_methods_decorator, retry

_LOG = get_logger('syndicate.connection.dynamo_connection')


def _append_attr_definition(definition, attr_name, attr_type):
    """ Adds an attribute definition if it is not already present.
    Dynamodb table creation requires to define attributes that are keys
    for the table or indexes. There must be no duplicated attribute
    definitions - aws throws ValidationException in such case.

    :type definition: []
    :type attr_name: str
    :type attr_type: str
    """
    for each in definition:
        if each['AttributeName'] == attr_name:
            return  # attribute is already defined, must not duplicate
Esempio n. 28
0
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
"""
from botocore.exceptions import ClientError

from syndicate.commons.log_helper import get_logger
from syndicate.core import CONN
from syndicate.core.resources.alarm_resource import remove_alarms
from syndicate.core.resources.helper import (build_description_obj,
                                             validate_params)

_LOG = get_logger('syndicate.core.resources.dynamo_db_resource')
_DYNAMO_DB_CONN = CONN.dynamodb()
_CW_METRIC = CONN.cw_metric()
_APP_AS_CONN = CONN.application_autoscaling()


def create_tables_by_10(args):
    """ Only 10 tables can be created, updated or deleted simultaneously.

    :type args: list
    """
    response = dict()
    waiters = {}
    start = 0
    end = 8
    while start < len(args):
Esempio n. 29
0
    You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
"""
from boto3 import client

from syndicate.commons.log_helper import get_logger
from syndicate.connection.helper import apply_methods_decorator, retry

_LOG = get_logger('syndicate.connection.ses_connection')


@apply_methods_decorator(retry)
class SESConnection(object):
    """SES connection class."""

    def __init__(self, region=None, aws_access_key_id=None,
                 aws_secret_access_key=None, source_arn=None,
                 aws_session_token=None):
        self.client = client('ses', region,
                             aws_access_key_id=aws_access_key_id,
                             aws_secret_access_key=aws_secret_access_key,
                             aws_session_token=aws_session_token)
        self.charset = 'utf-8'
        self.arn = source_arn
Esempio n. 30
0
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
"""
from json import dumps

from boto3 import client
from botocore.exceptions import ClientError

from syndicate.commons.log_helper import get_logger
from syndicate.connection.helper import apply_methods_decorator, retry

_LOG = get_logger('syndicate.connection.step_functions_connection')


@apply_methods_decorator(retry)
class SFConnection(object):
    """ STS connection class."""
    def __init__(self,
                 region=None,
                 aws_access_key_id=None,
                 aws_secret_access_key=None,
                 aws_session_token=None):
        self.client = client('stepfunctions',
                             region,
                             aws_access_key_id=aws_access_key_id,
                             aws_secret_access_key=aws_secret_access_key,
                             aws_session_token=aws_session_token)