import logging
import os
import boto3
from botocore.exceptions import ClientError


def create_presigned_url(object_name):
    """Generate a presigned URL to share an S3 object with a capped expiration of 60 seconds

    :param object_name: string
    :return: Presigned URL as string. If error, returns None.
    """
    s3_client = boto3.client('s3',
                             region_name=os.environ.get('S3_PERSISTENCE_REGION'),
                             config=boto3.session.Config(signature_version='s3v4',s3={'addressing_style': 'path'}))
    try:
        bucket_name = os.environ.get('S3_PERSISTENCE_BUCKET')
        response = s3_client.generate_presigned_url('get_object',
                                                    Params={'Bucket': bucket_name,
                                                            'Key': object_name},
                                                    ExpiresIn=60*1)
    except ClientError as e:
        logging.error(e)
        return None

    # The response contains the presigned URL
    return response
    


import ask_sdk_core.utils as ask_utils

from ask_sdk_core.dispatch_components import AbstractRequestHandler


class BootcampIntentBuilder:
    def __init__(self):
        self.classes={}
        return

    def addIntent(self,intent_name):
        class IntentClass(AbstractRequestHandler):
            """Handler for Hello World Intent."""
            def can_handle(self, handler_input):
                # type: (HandlerInput) -> bool
                return ask_utils.is_intent_name(intent_name)(handler_input)

        self.classes[intent_name]=IntentClass
        return
    
    def linkHandlerFunction(self,intent_name,function):
        def handle(self, handler_input):
            return function(handler_input)
        self.classes[intent_name].handle=handle
        return

bootcamp_builder=BootcampIntentBuilder()